Skip to content

Commit

Permalink
Revert "Create koyeb orga list and koyeb orga switch"
Browse files Browse the repository at this point in the history
This reverts commit ab6d584.
  • Loading branch information
brmzkw committed Aug 18, 2023
1 parent 8de0c69 commit 05fc33c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 358 deletions.
35 changes: 11 additions & 24 deletions pkg/koyeb/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const (
)

// SetupCLIContext is called by the root command to setup the context for all subcommands.
// When `organization` is not empty, it should contain the ID of the organization to switch the context to.
func SetupCLIContext(cmd *cobra.Command, organization string) error {
func SetupCLIContext(cmd *cobra.Command) error {
apiClient, err := getApiClient()
if err != nil {
return err
Expand All @@ -38,15 +37,6 @@ func SetupCLIContext(cmd *cobra.Command, organization string) error {
ctx = context.WithValue(ctx, ctx_mapper, idmapper.NewMapper(ctx, apiClient))
ctx = context.WithValue(ctx, ctx_renderer, renderer.NewRenderer(outputFormat))
cmd.SetContext(ctx)

if organization != "" {
token, err := GetOrganizationToken(apiClient.OrganizationApi, ctx, organization)
if err != nil {
return err
}
ctx = context.WithValue(ctx, koyeb.ContextAccessToken, token)
cmd.SetContext(ctx)
}
return nil
}

Expand All @@ -59,21 +49,18 @@ type CLIContext struct {
Renderer renderer.Renderer
}

// GetCLIContext transforms the untyped context passed to cobra commands into a CLIContext.
func GetCLIContext(ctx context.Context) *CLIContext {
return &CLIContext{
Context: ctx,
Client: ctx.Value(ctx_client).(*koyeb.APIClient),
LogsClient: ctx.Value(ctx_logs_client).(*LogsAPIClient),
Mapper: ctx.Value(ctx_mapper).(*idmapper.Mapper),
Token: ctx.Value(koyeb.ContextAccessToken).(string),
Renderer: ctx.Value(ctx_renderer).(renderer.Renderer),
}
}

// WithCLIContext is a decorator that provides a CLIContext to cobra commands.
func WithCLIContext(fn func(ctx *CLIContext, cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
return fn(GetCLIContext(cmd.Context()), cmd, args)
ctx := cmd.Context()
cliContext := CLIContext{
Context: ctx,
Client: ctx.Value(ctx_client).(*koyeb.APIClient),
LogsClient: ctx.Value(ctx_logs_client).(*LogsAPIClient),
Mapper: ctx.Value(ctx_mapper).(*idmapper.Mapper),
Token: ctx.Value(koyeb.ContextAccessToken).(string),
Renderer: ctx.Value(ctx_renderer).(renderer.Renderer),
}
return fn(&cliContext, cmd, args)
}
}
35 changes: 14 additions & 21 deletions pkg/koyeb/idmapper/idmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
)

type Mapper struct {
app *AppMapper
domain *DomainMapper
service *ServiceMapper
deployment *DeploymentMapper
regional *RegionalDeploymentMapper
instance *InstanceMapper
secret *SecretMapper
organization *OrganizationMapper
app *AppMapper
domain *DomainMapper
service *ServiceMapper
deployment *DeploymentMapper
regional *RegionalDeploymentMapper
instance *InstanceMapper
secret *SecretMapper
}

func NewMapper(ctx context.Context, client *koyeb.APIClient) *Mapper {
Expand All @@ -25,17 +24,15 @@ func NewMapper(ctx context.Context, client *koyeb.APIClient) *Mapper {
regionalMapper := NewRegionalDeploymentMapper(ctx, client)
instanceMapper := NewInstanceMapper(ctx, client)
secretMapper := NewSecretMapper(ctx, client)
organizationMapper := NewOrganizationMapper(ctx, client)

return &Mapper{
app: appMapper,
domain: domainMapper,
service: serviceMapper,
deployment: deploymentMapper,
regional: regionalMapper,
instance: instanceMapper,
secret: secretMapper,
organization: organizationMapper,
app: appMapper,
domain: domainMapper,
service: serviceMapper,
deployment: deploymentMapper,
regional: regionalMapper,
instance: instanceMapper,
secret: secretMapper,
}
}

Expand Down Expand Up @@ -66,7 +63,3 @@ func (mapper *Mapper) Instance() *InstanceMapper {
func (mapper *Mapper) Secret() *SecretMapper {
return mapper.secret
}

func (mapper *Mapper) Organization() *OrganizationMapper {
return mapper.organization
}
124 changes: 0 additions & 124 deletions pkg/koyeb/idmapper/organization.go

This file was deleted.

4 changes: 1 addition & 3 deletions pkg/koyeb/koyeb.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func GetRootCommand() *cobra.Command {
return err
}
DetectUpdates()
organization := viper.GetString("organization")
return SetupCLIContext(cmd, organization)
return SetupCLIContext(cmd)
},
}

Expand All @@ -100,7 +99,6 @@ func GetRootCommand() *cobra.Command {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(completionCmd)

rootCmd.AddCommand(NewOrganizationCmd())
rootCmd.AddCommand(NewSecretCmd())
rootCmd.AddCommand(NewAppCmd())
rootCmd.AddCommand(NewDomainCmd())
Expand Down
59 changes: 0 additions & 59 deletions pkg/koyeb/organizations.go

This file was deleted.

Loading

0 comments on commit 05fc33c

Please sign in to comment.