Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions cmd/ctrlc/root/api/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package create

import (
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/deploymentversion"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/deploymentversionchannel"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/environment"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/relationship"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/release"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/releasechannel"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/system"
"github.com/spf13/cobra"
)
Expand All @@ -21,8 +19,6 @@ func NewCreateCmd() *cobra.Command {
},
}

cmd.AddCommand(releasechannel.NewCreateReleaseChannelCmd())
cmd.AddCommand(deploymentversionchannel.NewCreateDeploymentVersionChannelCmd())
cmd.AddCommand(deploymentversion.NewCreateDeploymentVersionCmd())
cmd.AddCommand(environment.NewCreateEnvironmentCmd())
cmd.AddCommand(relationship.NewRelationshipCmd())
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions cmd/ctrlc/root/api/create/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

func NewCreateEnvironmentCmd() *cobra.Command {
var nameFlag string
var releaseChannels []string
var deploymentVersionChannels []string
var system string
var resourceSelector string
var metadata map[string]string
Expand Down Expand Up @@ -42,8 +40,6 @@ func NewCreateEnvironmentCmd() *cobra.Command {

body := api.CreateEnvironmentJSONRequestBody{}
body.Name = nameFlag
body.ReleaseChannels = &releaseChannels
body.DeploymentVersionChannels = &deploymentVersionChannels
body.SystemId = system
body.Metadata = cliutil.StringMapPtr(metadata)

Expand All @@ -66,8 +62,6 @@ func NewCreateEnvironmentCmd() *cobra.Command {

cmd.Flags().StringVarP(&nameFlag, "name", "n", "", "Name of the environment (required)")
cmd.Flags().StringVarP(&system, "system", "s", "", "ID of the system (required)")
cmd.Flags().StringSliceVarP(&releaseChannels, "release-channel", "r", []string{}, "Release channel in format <channelid>")
cmd.Flags().StringSliceVarP(&deploymentVersionChannels, "deployment-version-channel", "d", []string{}, "Deployment version channel in format <channelid>")
cmd.Flags().StringVarP(&resourceSelector, "resource-selector", "f", "", "Resource selector as JSON string")
cmd.Flags().StringToStringVarP(&metadata, "metadata", "m", make(map[string]string), "Metadata key-value pairs (e.g. --metadata key=value)")

Expand Down
69 changes: 0 additions & 69 deletions cmd/ctrlc/root/api/create/releasechannel/release-channel.go

This file was deleted.

4 changes: 0 additions & 4 deletions cmd/ctrlc/root/api/delete/delete.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package delete

import (
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/delete/deploymentversionchannel"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/delete/environment"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/delete/policy"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/delete/releasechannel"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/delete/resource"
"github.com/spf13/cobra"
)
Expand All @@ -21,8 +19,6 @@ func NewDeleteCmd() *cobra.Command {

cmd.AddCommand(resource.NewDeleteResourceCmd())
cmd.AddCommand(environment.NewDeleteEnvironmentCmd())
cmd.AddCommand(releasechannel.NewDeleteReleaseChannelCmd())
cmd.AddCommand(deploymentversionchannel.NewDeleteDeploymentVersionChannelCmd())
cmd.AddCommand(policy.NewDeletePolicyCmd())
return cmd
}

This file was deleted.

48 changes: 0 additions & 48 deletions cmd/ctrlc/root/api/delete/releasechannel/release-channel.go

This file was deleted.

55 changes: 50 additions & 5 deletions cmd/ctrlc/root/apply/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,42 @@ func processResourceRelationships(
}
}

func createMetadataKeysMatch(match MetadataKeysMatch) (*struct {
SourceKey string `json:"sourceKey"`
TargetKey string `json:"targetKey"`
}, error) {
if match.Key != nil {
return &struct {
SourceKey string `json:"sourceKey"`
TargetKey string `json:"targetKey"`
}{
SourceKey: *match.Key,
TargetKey: *match.Key,
}, nil
}

if match.SourceKey == nil || match.TargetKey == nil {
return nil, fmt.Errorf("sourceKey and targetKey must be provided")
}

return &struct {
SourceKey string `json:"sourceKey"`
TargetKey string `json:"targetKey"`
}{
SourceKey: *match.SourceKey,
TargetKey: *match.TargetKey,
}, nil
}

func createRelationshipRequestBody(workspaceId string, relationship ResourceRelationship) api.CreateResourceRelationshipRule {
config := api.CreateResourceRelationshipRule{
WorkspaceId: workspaceId,
Reference: relationship.Reference,
DependencyType: api.ResourceRelationshipRuleDependencyType(relationship.DependencyType),
MetadataKeysMatches: &[]string{},
WorkspaceId: workspaceId,
Reference: relationship.Reference,
DependencyType: api.ResourceRelationshipRuleDependencyType(relationship.DependencyType),
MetadataKeysMatches: &[]struct {
SourceKey string `json:"sourceKey"`
TargetKey string `json:"targetKey"`
}{},
TargetMetadataEquals: &[]struct {
Key string `json:"key"`
Value string `json:"value"`
Expand Down Expand Up @@ -82,7 +112,22 @@ func createRelationshipRequestBody(workspaceId string, relationship ResourceRela
}

if relationship.MetadataKeysMatch != nil {
config.MetadataKeysMatches = &relationship.MetadataKeysMatch
metadataKeysMatches := []struct {
SourceKey string `json:"sourceKey"`
TargetKey string `json:"targetKey"`
}{}

for _, match := range relationship.MetadataKeysMatch {
metadataKeysMatch, err := createMetadataKeysMatch(match)
if err != nil {
log.Error("Failed to create metadata keys match", "error", err, "match", match)
continue
}

metadataKeysMatches = append(metadataKeysMatches, *metadataKeysMatch)
}

config.MetadataKeysMatches = &metadataKeysMatches
}

// Log the MetadataTargetKeysEquals for debugging
Expand Down
Loading