Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/accounts #262

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cmd/create/environment.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package create

import (
"fmt"
"strings"

"github.com/dream11/odin/internal/service"
"github.com/dream11/odin/pkg/util"
environmentProto "github.com/dream11/odin/proto/gen/go/dream11/od/environment/v1"
Expand All @@ -26,6 +29,19 @@ var environmentCmd = &cobra.Command{
},
}

func validateAccounts(accounts string) error {
if accounts == "" {
return fmt.Errorf("accounts parameter cannot be an empty string")
}
accountList := strings.Split(accounts, ",")
for _, account := range accountList {
if account == "" {
return fmt.Errorf("accounts parameter contains an empty account")
}
}
return nil
}

func init() {
environmentCmd.Flags().StringVar(&envName, "name", "", "name of the environment to be created")
environmentCmd.Flags().StringVar(&accounts, "accounts", "", "list of comma separated cloud provider accounts")
Expand All @@ -37,12 +53,19 @@ func init() {
if err := environmentCmd.MarkFlagRequired("provisioning-type"); err != nil {
log.Fatal("Error marking 'provisioning-type' flag as required:", err)
}
err = environmentCmd.MarkFlagRequired("accounts")
if err != nil {
log.Fatal("Error marking 'accounts' flag as required:", err)
}
createCmd.AddCommand(environmentCmd)
}

func execute(cmd *cobra.Command) {
ctx := cmd.Context()

// Validate accounts parameter
if err := validateAccounts(accounts); err != nil {
log.Fatal("Invalid accounts parameter: ", err)
}
err := environmentClient.CreateEnvironment(&ctx, &environmentProto.CreateEnvironmentRequest{
EnvName: envName,
Accounts: util.SplitProviderAccount(accounts),
Expand Down
8 changes: 4 additions & 4 deletions cmd/describe/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package describe
import (
"encoding/json"
"fmt"
"strconv"

serviceBackend "github.com/dream11/odin/internal/service"
service "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
"github.com/iancoleman/orderedmap"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"strconv"
)

var serviceName string
Expand Down Expand Up @@ -58,8 +59,8 @@ func execute(cmd *cobra.Command) {
ctx := cmd.Context()
response, err := serviceClient.DescribeService(&ctx, &service.DescribeServiceRequest{
ServiceName: serviceName,
Version: serviceVersion,
Params: params,
Version: serviceVersion,
Params: params,
})

if err != nil {
Expand Down Expand Up @@ -90,4 +91,3 @@ func writeAsJSON(response *service.DescribeServiceResponse) {
}
fmt.Println(string(output))
}

6 changes: 3 additions & 3 deletions cmd/list/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func writeListServiceAsJSON(response *serviceProto.ListServiceResponse) {
var services []map[string]interface{}
for _, serviceEntity := range response.Services {
services = append(services, map[string]interface{}{
"name": serviceEntity.Name,
"version": serviceEntity.Version,
"Tags": serviceEntity.Tags,
"name": serviceEntity.Name,
"version": serviceEntity.Version,
"Tags": serviceEntity.Tags,
})
}
output, _ := json.MarshalIndent(services, "", " ")
Expand Down
13 changes: 10 additions & 3 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"errors"
"fmt"
"github.com/dream11/odin/pkg/util"
"io"
"strings"

"github.com/briandowns/spinner"
"github.com/dream11/odin/pkg/constant"
"github.com/dream11/odin/pkg/util"
serviceDto "github.com/dream11/odin/proto/gen/go/dream11/od/dto/v1"
serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -276,14 +277,20 @@ func (e *Service) ReleaseService(ctx *context.Context, request *serviceProto.Rel
message = response.Message
message += fmt.Sprintf("\n Service %s %s", response.ServiceStatus.ServiceAction, response.ServiceStatus)
for _, compMessage := range response.ComponentsStatus {
message += fmt.Sprintf("\n Component %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus)
message += fmt.Sprintf("\n Component %s %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus, compMessage.Error)
if compMessage.ComponentStatus == "FAILED" {
return errors.New(compMessage.Error)
}
}

spinnerInstance.Prefix = fmt.Sprintf(" %s ", message)
spinnerInstance.Start()
}
}
if strings.Contains(strings.ToLower(message), "fail") {
return errors.New(message)
}
log.Info("Service released successfully !")

return err
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package util

import (
"fmt"
v1 "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
"net"
"strings"

v1 "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
)

// SplitProviderAccount splits string into list of cloud provider accounts
Expand Down
Loading