Skip to content
Open
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
25 changes: 25 additions & 0 deletions cmd/application_external_secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"os"

"github.com/qovery/qovery-cli/utils"
"github.com/spf13/cobra"
)
Comment thread
Copilot marked this conversation as resolved.

var applicationExternalSecretCmd = &cobra.Command{
Use: "external-secret",
Short: "Manage application external secrets",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

if len(args) == 0 {
_ = cmd.Help()
os.Exit(0)
}
},
}

func init() {
applicationCmd.AddCommand(applicationExternalSecretCmd)
}
81 changes: 81 additions & 0 deletions cmd/application_external_secret_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/qovery/qovery-cli/utils"
)

var applicationExternalSecretCreateCmd = &cobra.Command{
Use: "create",
Short: "Create application external secret",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

client := utils.GetQoveryClient(tokenType, token)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

applications, _, err := client.ApplicationsAPI.ListApplication(context.Background(), envId).Execute()

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

application := utils.FindByApplicationName(applications.GetResults(), applicationName)

if application == nil {
utils.PrintlnError(fmt.Errorf("application %s not found", applicationName))
utils.PrintlnInfo("You can list all applications with: qovery application list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateServiceExternalSecret(client, projectId, envId, application.Id, utils.ApplicationScope, utils.Key, utils.Reference, utils.SecretManagerAccessId, utils.MountPath)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

utils.Println(fmt.Sprintf("External secret %s has been created", pterm.FgBlue.Sprintf("%s", utils.Key)))
},
}

func init() {
applicationExternalSecretCmd.AddCommand(applicationExternalSecretCreateCmd)
applicationExternalSecretCreateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
applicationExternalSecretCreateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
applicationExternalSecretCreateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
applicationExternalSecretCreateCmd.Flags().StringVarP(&applicationName, "application", "n", "", "Application Name")
applicationExternalSecretCreateCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "External secret key")
applicationExternalSecretCreateCmd.Flags().StringVarP(&utils.Reference, "reference", "r", "", "Reference to the secret in the secrets provider")
applicationExternalSecretCreateCmd.Flags().StringVarP(&utils.SecretManagerAccessId, "secret-manager-access-id", "", "", "Secret manager access ID")
applicationExternalSecretCreateCmd.Flags().StringVarP(&utils.ApplicationScope, "scope", "", "APPLICATION", "Scope of this external secret <PROJECT|ENVIRONMENT|APPLICATION>")
applicationExternalSecretCreateCmd.Flags().StringVarP(&utils.MountPath, "mount-path", "", "", "Path where the secret will be mounted as a file")

_ = applicationExternalSecretCreateCmd.MarkFlagRequired("key")
_ = applicationExternalSecretCreateCmd.MarkFlagRequired("reference")
_ = applicationExternalSecretCreateCmd.MarkFlagRequired("secret-manager-access-id")
_ = applicationExternalSecretCreateCmd.MarkFlagRequired("application")
}
75 changes: 75 additions & 0 deletions cmd/application_external_secret_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/qovery/qovery-cli/utils"
)

var applicationExternalSecretDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete application external secret",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

applications, _, err := client.ApplicationsAPI.ListApplication(context.Background(), envId).Execute()

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

application := utils.FindByApplicationName(applications.GetResults(), applicationName)

if application == nil {
utils.PrintlnError(fmt.Errorf("application %s not found", applicationName))
utils.PrintlnInfo("You can list all applications with: qovery application list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.DeleteServiceVariable(client, application.Id, utils.ApplicationType, utils.Key)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

utils.Println(fmt.Sprintf("External secret %s has been deleted", pterm.FgBlue.Sprintf("%s", utils.Key)))
},
}

func init() {
applicationExternalSecretCmd.AddCommand(applicationExternalSecretDeleteCmd)
applicationExternalSecretDeleteCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
applicationExternalSecretDeleteCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
applicationExternalSecretDeleteCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
applicationExternalSecretDeleteCmd.Flags().StringVarP(&applicationName, "application", "n", "", "Application Name")
applicationExternalSecretDeleteCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "External secret key")

_ = applicationExternalSecretDeleteCmd.MarkFlagRequired("key")
_ = applicationExternalSecretDeleteCmd.MarkFlagRequired("application")
}
77 changes: 77 additions & 0 deletions cmd/application_external_secret_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/qovery/qovery-cli/utils"
)

var applicationExternalSecretUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update application external secret",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

applications, _, err := client.ApplicationsAPI.ListApplication(context.Background(), envId).Execute()

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

application := utils.FindByApplicationName(applications.GetResults(), applicationName)

if application == nil {
utils.PrintlnError(fmt.Errorf("application %s not found", applicationName))
utils.PrintlnInfo("You can list all applications with: qovery application list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.UpdateServiceExternalSecret(client, utils.Key, utils.Reference, utils.SecretManagerAccessId, application.Id, utils.ApplicationType)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

utils.Println(fmt.Sprintf("External secret %s has been updated", pterm.FgBlue.Sprintf("%s", utils.Key)))
},
}

func init() {
applicationExternalSecretCmd.AddCommand(applicationExternalSecretUpdateCmd)
applicationExternalSecretUpdateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
applicationExternalSecretUpdateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
applicationExternalSecretUpdateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
applicationExternalSecretUpdateCmd.Flags().StringVarP(&applicationName, "application", "n", "", "Application Name")
applicationExternalSecretUpdateCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "External secret key")
applicationExternalSecretUpdateCmd.Flags().StringVarP(&utils.Reference, "reference", "r", "", "New reference to the secret in the secrets provider")
applicationExternalSecretUpdateCmd.Flags().StringVarP(&utils.SecretManagerAccessId, "secret-manager-access-id", "", "", "New secret manager access ID")

_ = applicationExternalSecretUpdateCmd.MarkFlagRequired("key")
_ = applicationExternalSecretUpdateCmd.MarkFlagRequired("application")
}
25 changes: 25 additions & 0 deletions cmd/container_external_secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"os"

"github.com/qovery/qovery-cli/utils"
"github.com/spf13/cobra"
)
Comment thread
Copilot marked this conversation as resolved.

var containerExternalSecretCmd = &cobra.Command{
Use: "external-secret",
Short: "Manage container external secrets",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

if len(args) == 0 {
_ = cmd.Help()
os.Exit(0)
}
},
}

func init() {
containerCmd.AddCommand(containerExternalSecretCmd)
}
81 changes: 81 additions & 0 deletions cmd/container_external_secret_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/qovery/qovery-cli/utils"
)

var containerExternalSecretCreateCmd = &cobra.Command{
Use: "create",
Short: "Create container external secret",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

client := utils.GetQoveryClient(tokenType, token)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

containers, _, err := client.ContainersAPI.ListContainer(context.Background(), envId).Execute()

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

container := utils.FindByContainerName(containers.GetResults(), containerName)

if container == nil {
utils.PrintlnError(fmt.Errorf("container %s not found", containerName))
utils.PrintlnInfo("You can list all containers with: qovery container list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateServiceExternalSecret(client, projectId, envId, container.Id, utils.ContainerScope, utils.Key, utils.Reference, utils.SecretManagerAccessId, utils.MountPath)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

utils.Println(fmt.Sprintf("External secret %s has been created", pterm.FgBlue.Sprintf("%s", utils.Key)))
},
}

func init() {
containerExternalSecretCmd.AddCommand(containerExternalSecretCreateCmd)
containerExternalSecretCreateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
containerExternalSecretCreateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
containerExternalSecretCreateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
containerExternalSecretCreateCmd.Flags().StringVarP(&containerName, "container", "n", "", "Container Name")
containerExternalSecretCreateCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "External secret key")
containerExternalSecretCreateCmd.Flags().StringVarP(&utils.Reference, "reference", "r", "", "Reference to the secret in the secrets provider")
containerExternalSecretCreateCmd.Flags().StringVarP(&utils.SecretManagerAccessId, "secret-manager-access-id", "", "", "Secret manager access ID")
containerExternalSecretCreateCmd.Flags().StringVarP(&utils.ContainerScope, "scope", "", "CONTAINER", "Scope of this external secret <PROJECT|ENVIRONMENT|CONTAINER>")
containerExternalSecretCreateCmd.Flags().StringVarP(&utils.MountPath, "mount-path", "", "", "Path where the secret will be mounted as a file")

_ = containerExternalSecretCreateCmd.MarkFlagRequired("key")
_ = containerExternalSecretCreateCmd.MarkFlagRequired("reference")
_ = containerExternalSecretCreateCmd.MarkFlagRequired("secret-manager-access-id")
_ = containerExternalSecretCreateCmd.MarkFlagRequired("container")
}
Loading
Loading