Skip to content

Commit

Permalink
add CLI support
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad committed Aug 8, 2024
1 parent 585b2a9 commit 6d2d08f
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions src/cmd/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ type IntegrationType string
const (
IntegrationTypeAWS IntegrationType = "aws"
IntegrationTypeAzure IntegrationType = "azure"
IntegrationTypeGCP IntegrationType = "googleCloud"
)

var AllIntegrationType = []IntegrationType{IntegrationTypeAWS, IntegrationTypeAzure, IntegrationTypeGCP}

var IntegrationConfigCurrentVersion = "1"

type IntegrationInputType struct {
Expand All @@ -27,7 +30,7 @@ type IntegrationInputType struct {
}

type IntegrationInput interface {
opslevel.AWSIntegrationInput | opslevel.AzureResourcesIntegrationInput
opslevel.AWSIntegrationInput | opslevel.AzureResourcesIntegrationInput | opslevel.GoogleCloudIntegrationInput
}

func validateIntegrationInput() (*IntegrationInputType, error) {
Expand All @@ -40,11 +43,11 @@ func validateIntegrationInput() (*IntegrationInputType, error) {
IntegrationConfigCurrentVersion, input.Version)
}
switch input.Kind {
case IntegrationTypeAWS, IntegrationTypeAzure:
case IntegrationTypeAWS, IntegrationTypeAzure, IntegrationTypeGCP:
return input, nil
default:
return nil, fmt.Errorf("unsupported integration kind: '%s' (must be one of: '%s', '%s')",
input.Kind, IntegrationTypeAWS, IntegrationTypeAzure)
return nil, fmt.Errorf("unsupported integration kind: '%s' (must be one of: %+v)",
input.Kind, AllIntegrationType)
}
}

Expand Down Expand Up @@ -82,6 +85,19 @@ spec:
clientId: "XXX_CLIENT_ID_XXX"
clientSecret: "XXX_CLIENT_SECRET_XXX"
EOF
cat << EOF | opslevel create integration -f -
version: 1
kind: googleCloud
spec:
name: "GCP New"
ownershipTagKeys:
- owner
- team
privateKey: "XXX_PRIVATE_KEY_XXX"
clientEmail: "[email protected]"
tagsOverrideOwnership: false
EOF
`,
Run: func(cmd *cobra.Command, args []string) {
input, validateErr := validateIntegrationInput()
Expand All @@ -99,6 +115,11 @@ EOF
cobra.CheckErr(err)
result, err = getClientGQL().CreateIntegrationAzureResources(azureInput)
cobra.CheckErr(err)
case IntegrationTypeGCP:
gcpInput, err := readIntegrationInput[opslevel.GoogleCloudIntegrationInput](input)
cobra.CheckErr(err)
result, err = getClientGQL().CreateIntegrationGCP(gcpInput)
cobra.CheckErr(err)
default:
cobra.CheckErr(fmt.Errorf("cannot use unexpected input kind: '%s'", input.Kind))
}
Expand Down Expand Up @@ -160,10 +181,22 @@ cat << EOF | opslevel update integration Z2lkOi8vb123456789 -f -
version: 1
kind: azure
spec:
name: "dev"
name: "Azure Dev"
clientId: "XXX_CLIENT_ID_XXX"
clientSecret: "XXX_CLIENT_SECRET_XXX"
EOF
cat << EOF | opslevel update integration Z2lkOi8vb123456789 -f -
version: 1
kind: googleCloud
spec:
name: "GCP Dev"
ownershipTagKeys:
- opslevel_team
- team
privateKey: "XXX_NEW_PRIVATE_KEY_XXX"
tagsOverrideOwnership: true
EOF
`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"ID"},
Expand All @@ -183,6 +216,11 @@ EOF
cobra.CheckErr(err)
result, err = getClientGQL().UpdateIntegrationAzureResources(args[0], azureInput)
cobra.CheckErr(err)
case IntegrationTypeGCP:
gcpInput, err := readIntegrationInput[opslevel.GoogleCloudIntegrationInput](input)
cobra.CheckErr(err)
result, err = getClientGQL().UpdateIntegrationGCP(args[0], gcpInput)
cobra.CheckErr(err)
default:
cobra.CheckErr(fmt.Errorf("cannot use unexpected input kind: '%s'", input.Kind))
}
Expand Down

0 comments on commit 6d2d08f

Please sign in to comment.