Skip to content

Commit

Permalink
add command to set tls certificate and private key (#83)
Browse files Browse the repository at this point in the history
* add command to set tls certificate and private key

* add command for setting external dns tls secrets

* update module versions

* fix example

* add flag to get certificate and private key from file

* remove unneccessary else-if block
  • Loading branch information
nilsgstrabo authored Jan 17, 2024
1 parent 81396e9 commit b2042d3
Show file tree
Hide file tree
Showing 46 changed files with 1,949 additions and 429 deletions.
48 changes: 23 additions & 25 deletions cmd/createApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,28 @@ import (
"github.com/equinor/radix-cli/generated-client/client/platform"
"github.com/equinor/radix-cli/generated-client/models"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)

// createApplicationCmd represents the create application command
var createApplicationCmd = &cobra.Command{
Use: "application",
Short: "Create application",
Long: `Creates a Radix application in the cluster
Example:
rx create application --application your-application-name --repository https://github.com/your-repository --config-branch main --ad-groups abcdef-1234-5678-9aaa-abcdefgf --reader-ad-groups=23456789--9123-4567-8901-23456701 --shared-secret someSecretPhrase12345 --acknowledge-warnings --configuration-item "YOUR PROJECT CONFIG ITEM" --context playground
`,
Use: "application",
Short: "Create application",
Long: "Creates a Radix application in the cluster",
Example: `rx create application --application your-application-name --repository https://github.com/your-repository --config-branch main --ad-groups abcdef-1234-5678-9aaa-abcdefgf --reader-ad-groups=23456789--9123-4567-8901-23456701 --shared-secret someSecretPhrase12345 --acknowledge-warnings --configuration-item "YOUR PROJECT CONFIG ITEM" --context playground`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}

repository, _ := cmd.Flags().GetString("repository")
sharedSecret, _ := cmd.Flags().GetString("shared-secret")
configBranch, _ := cmd.Flags().GetString("config-branch")
configFile, _ := cmd.Flags().GetString("config-file")
configurationItem, _ := cmd.Flags().GetString("configuration-item")
acknowledgeWarnings, err := cmd.Flags().GetBool("acknowledge-warnings")
repository, _ := cmd.Flags().GetString(flagnames.Repository)
sharedSecret, _ := cmd.Flags().GetString(flagnames.SharedSecret)
configBranch, _ := cmd.Flags().GetString(flagnames.ConfigBranch)
configFile, _ := cmd.Flags().GetString(flagnames.ConfigFile)
configurationItem, _ := cmd.Flags().GetString(flagnames.ConfigurationItem)
acknowledgeWarnings, err := cmd.Flags().GetBool(flagnames.AcknowledgeWarnings)
if err != nil {
println(fmt.Sprintf("invalid argument %s: %v", "acknowledge-warnings", err))
return err
Expand All @@ -57,8 +55,8 @@ rx create application --application your-application-name --repository https://g
return errors.New("application name, repository, configuration item and config branch are required fields")
}

adGroups, _ := cmd.Flags().GetStringSlice("ad-groups")
readerAdGroups, _ := cmd.Flags().GetStringSlice("reader-ad-groups")
adGroups, _ := cmd.Flags().GetStringSlice(flagnames.AdminADGroups)
readerAdGroups, _ := cmd.Flags().GetStringSlice(flagnames.ReaderADGroups)

cmd.SilenceUsage = true

Expand Down Expand Up @@ -125,14 +123,14 @@ rx create application --application your-application-name --repository https://g

func init() {
createCmd.AddCommand(createApplicationCmd)
createApplicationCmd.Flags().StringP("application", "a", "", "Name of the application to create")
createApplicationCmd.Flags().StringP("repository", "", "", "Repository path")
createApplicationCmd.Flags().StringP("shared-secret", "", "", "Shared secret for the webhook")
createApplicationCmd.Flags().StringP("config-branch", "", "", "Name of the branch where Radix will read your radixconfig.yaml from")
createApplicationCmd.Flags().StringP("config-file", "", "", "Name of the radix config file. Optional, defaults to radixconfig.yaml")
createApplicationCmd.Flags().StringSliceP("ad-groups", "", []string{}, "Admin groups")
createApplicationCmd.Flags().StringSliceP("reader-ad-groups", "", []string{}, "Reader groups")
createApplicationCmd.Flags().StringP("configuration-item", "", "", "Configuration item")
createApplicationCmd.Flags().Bool("acknowledge-warnings", false, "Acknowledge warnings and proceed")
createApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to create")
createApplicationCmd.Flags().StringP(flagnames.Repository, "", "", "Repository path")
createApplicationCmd.Flags().StringP(flagnames.SharedSecret, "", "", "Shared secret for the webhook")
createApplicationCmd.Flags().StringP(flagnames.ConfigBranch, "", "", "Name of the branch where Radix will read your radixconfig.yaml from")
createApplicationCmd.Flags().StringP(flagnames.ConfigFile, "", "", "Name of the radix config file. Optional, defaults to radixconfig.yaml")
createApplicationCmd.Flags().StringSliceP(flagnames.AdminADGroups, "", []string{}, "Admin groups")
createApplicationCmd.Flags().StringSliceP(flagnames.ReaderADGroups, "", []string{}, "Reader groups")
createApplicationCmd.Flags().StringP(flagnames.ConfigurationItem, "", "", "Configuration item")
createApplicationCmd.Flags().Bool(flagnames.AcknowledgeWarnings, false, "Acknowledge warnings and proceed")
setContextSpecificPersistentFlags(createApplicationCmd)
}
18 changes: 10 additions & 8 deletions cmd/createBuildDeployPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package cmd

import (
"errors"

log "github.com/sirupsen/logrus"

"github.com/equinor/radix-cli/generated-client/client/application"
"github.com/equinor/radix-cli/generated-client/models"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)

Expand All @@ -30,14 +32,14 @@ var createBuildDeployApplicationCmd = &cobra.Command{
Short: "Will trigger build-deploy of a Radix application",
Long: `Triggers build-deploy of Radix application, if branch to environment map exists for the branch in the Radix config`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}

branch, _ := cmd.Flags().GetString("branch")
commitID, _ := cmd.Flags().GetString("commitID")
follow, _ := cmd.Flags().GetBool("follow")
branch, _ := cmd.Flags().GetString(flagnames.Branch)
commitID, _ := cmd.Flags().GetString(flagnames.CommitID)
follow, _ := cmd.Flags().GetBool(flagnames.Follow)

if appName == nil || *appName == "" || branch == "" {
return errors.New("application name and branch are required")
Expand Down Expand Up @@ -73,9 +75,9 @@ var createBuildDeployApplicationCmd = &cobra.Command{

func init() {
createJobCmd.AddCommand(createBuildDeployApplicationCmd)
createBuildDeployApplicationCmd.Flags().StringP("application", "a", "", "Name of the application to build-deploy")
createBuildDeployApplicationCmd.Flags().StringP("branch", "b", "master", "Branch to build-deploy from")
createBuildDeployApplicationCmd.Flags().StringP("commitID", "i", "", "Commit id")
createBuildDeployApplicationCmd.Flags().BoolP("follow", "f", false, "Follow build-deploy")
createBuildDeployApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to build-deploy")
createBuildDeployApplicationCmd.Flags().StringP(flagnames.Branch, "b", "master", "Branch to build-deploy from")
createBuildDeployApplicationCmd.Flags().StringP(flagnames.CommitID, "i", "", "Commit id")
createBuildDeployApplicationCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow build-deploy")
setContextSpecificPersistentFlags(createBuildDeployApplicationCmd)
}
24 changes: 12 additions & 12 deletions cmd/createDeployPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/equinor/radix-cli/generated-client/client/application"
"github.com/equinor/radix-cli/generated-client/models"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)

Expand All @@ -47,23 +48,23 @@ Examples:
`,
RunE: func(cmd *cobra.Command, args []string) error {
var errs []error
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
errs = append(errs, err)
}
targetEnvironment, err := cmd.Flags().GetString("environment")
targetEnvironment, err := cmd.Flags().GetString(flagnames.Environment)
if err != nil {
errs = append(errs, err)
}
triggeredByUser, err := cmd.Flags().GetString("user")
triggeredByUser, err := cmd.Flags().GetString(flagnames.User)
if err != nil {
errs = append(errs, err)
}
follow, err := cmd.Flags().GetBool("follow")
follow, err := cmd.Flags().GetBool(flagnames.Follow)
if err != nil {
errs = append(errs, err)
}
imageTagNames, err := cmd.Flags().GetStringToString("image-tag-name")
imageTagNames, err := cmd.Flags().GetStringToString(flagnames.ImageTagName)
if err != nil {
errs = append(errs, err)
}
Expand All @@ -73,7 +74,7 @@ Examples:
if appName == nil || *appName == "" || targetEnvironment == "" {
return errors.New("application name and target environment are required")
}
commitID, _ := cmd.Flags().GetString("commitID")
commitID, _ := cmd.Flags().GetString(flagnames.CommitID)
err2 := validateCommitID(commitID)
if err2 != nil {
return err2
Expand Down Expand Up @@ -125,11 +126,10 @@ func validateCommitID(commitID string) error {

func init() {
createJobCmd.AddCommand(createDeployPipelineJobCmd)
createDeployPipelineJobCmd.Flags().StringP("application", "a", "", "Name of the application to deploy")
createDeployPipelineJobCmd.Flags().StringP("environment", "e", "", "Target environment to deploy in ('prod', 'dev', 'playground')")
createDeployPipelineJobCmd.Flags().StringP("user", "u", "", "The user who triggered the deploy")
createDeployPipelineJobCmd.Flags().StringToStringP("image-tag-name", "t", map[string]string{}, "Image tag name for a component: component-name=tag-name. Multiple pairs can be specified.")
createDeployPipelineJobCmd.Flags().StringP("commitID", "i", "", "An optional 40 character commit id to tag the new pipeline job")
createDeployPipelineJobCmd.Flags().BoolP("follow", "f", false, "Follow deploy")
createDeployPipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to deploy")
createDeployPipelineJobCmd.Flags().StringP(flagnames.User, "u", "", "The user who triggered the deploy")
createDeployPipelineJobCmd.Flags().StringToStringP(flagnames.ImageTagName, "t", map[string]string{}, "Image tag name for a component: component-name=tag-name. Multiple pairs can be specified.")
createDeployPipelineJobCmd.Flags().StringP(flagnames.CommitID, "i", "", "An optional 40 character commit id to tag the new pipeline job")
createDeployPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow deploy")
setContextSpecificPersistentFlags(createDeployPipelineJobCmd)
}
10 changes: 6 additions & 4 deletions cmd/createEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package cmd

import (
"errors"

"github.com/equinor/radix-cli/generated-client/client/environment"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)

Expand All @@ -27,12 +29,12 @@ var createEnvironmentCmd = &cobra.Command{
Short: "Create environment",
Long: `Creates a Radix environment for the application`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}

envName, err := cmd.Flags().GetString("environment")
envName, err := cmd.Flags().GetString(flagnames.Environment)

if err != nil || appName == nil || *appName == "" {
return errors.New("environment name and application name are required fields")
Expand All @@ -56,7 +58,7 @@ var createEnvironmentCmd = &cobra.Command{

func init() {
createCmd.AddCommand(createEnvironmentCmd)
createEnvironmentCmd.Flags().StringP("application", "a", "", "Name of the application namespace")
createEnvironmentCmd.Flags().StringP("environment", "e", "", "Name of the environment to create")
createEnvironmentCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application namespace")
createEnvironmentCmd.Flags().StringP(flagnames.Environment, "e", "", "Name of the environment to create")
setContextSpecificPersistentFlags(createEnvironmentCmd)
}
29 changes: 15 additions & 14 deletions cmd/createPromotePipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/equinor/radix-cli/generated-client/client/application"
"github.com/equinor/radix-cli/generated-client/models"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)

Expand All @@ -32,17 +33,17 @@ var createPromotePipelineJobCmd = &cobra.Command{
Short: "Will trigger promote of a Radix application",
Long: `Triggers promote of a Radix application deployment`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}

useActiveDeployment, _ := cmd.Flags().GetBool("use-active-deployment")
deploymentName, _ := cmd.Flags().GetString("deployment")
fromEnvironment, _ := cmd.Flags().GetString("from-environment")
toEnvironment, _ := cmd.Flags().GetString("to-environment")
triggeredByUser, _ := cmd.Flags().GetString("user")
follow, _ := cmd.Flags().GetBool("follow")
useActiveDeployment, _ := cmd.Flags().GetBool(flagnames.UseActiveDeployment)
deploymentName, _ := cmd.Flags().GetString(flagnames.Deployment)
fromEnvironment, _ := cmd.Flags().GetString(flagnames.FromEnvironment)
toEnvironment, _ := cmd.Flags().GetString(flagnames.ToEnvironment)
triggeredByUser, _ := cmd.Flags().GetString(flagnames.User)
follow, _ := cmd.Flags().GetBool(flagnames.Follow)

if !useActiveDeployment && deploymentName == "" {
return errors.New("Specifying deployment name or setting use-active-deployment is required")
Expand Down Expand Up @@ -114,12 +115,12 @@ func getActiveDeploymentName(apiClient *apiclient.Radixapi, appName, envName str

func init() {
createJobCmd.AddCommand(createPromotePipelineJobCmd)
createPromotePipelineJobCmd.Flags().StringP("application", "a", "", "Name of the application to be promoted")
createPromotePipelineJobCmd.Flags().StringP("deployment", "d", "", "Name of a deployment to be promoted")
createPromotePipelineJobCmd.Flags().StringP("from-environment", "", "", "The deployment source environment")
createPromotePipelineJobCmd.Flags().StringP("to-environment", "", "", "The deployment target environment")
createPromotePipelineJobCmd.Flags().StringP("user", "u", "", "The user who triggered the promote pipeline job")
createPromotePipelineJobCmd.Flags().BoolP("follow", "f", false, "Follow the promote pipeline job log")
createPromotePipelineJobCmd.Flags().BoolP("use-active-deployment", "", false, "Promote the active deployment")
createPromotePipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to be promoted")
createPromotePipelineJobCmd.Flags().StringP(flagnames.Deployment, "d", "", "Name of a deployment to be promoted")
createPromotePipelineJobCmd.Flags().StringP(flagnames.FromEnvironment, "", "", "The deployment source environment")
createPromotePipelineJobCmd.Flags().StringP(flagnames.ToEnvironment, "", "", "The deployment target environment")
createPromotePipelineJobCmd.Flags().StringP(flagnames.User, "u", "", "The user who triggered the promote pipeline job")
createPromotePipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow the promote pipeline job log")
createPromotePipelineJobCmd.Flags().BoolP(flagnames.UseActiveDeployment, "", false, "Promote the active deployment")
setContextSpecificPersistentFlags(createPromotePipelineJobCmd)
}
6 changes: 4 additions & 2 deletions cmd/deleteApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package cmd

import (
"errors"

"github.com/equinor/radix-cli/generated-client/client/application"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)

Expand All @@ -27,7 +29,7 @@ var deleteApplicationCmd = &cobra.Command{
Short: "Delete application",
Long: `Will delete an application from the cluster`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}
Expand All @@ -53,6 +55,6 @@ var deleteApplicationCmd = &cobra.Command{

func init() {
deleteCmd.AddCommand(deleteApplicationCmd)
deleteApplicationCmd.Flags().StringP("application", "a", "", "Name of the application to create")
deleteApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to create")
setContextSpecificPersistentFlags(deleteApplicationCmd)
}
10 changes: 6 additions & 4 deletions cmd/deleteEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package cmd

import (
"errors"

"github.com/equinor/radix-cli/generated-client/client/environment"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/spf13/cobra"
)

Expand All @@ -27,12 +29,12 @@ var deleteEnvironmentCmd = &cobra.Command{
Short: "delete environment",
Long: `deletes an orphaned Radix environment`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}

envName, err := cmd.Flags().GetString("environment")
envName, err := cmd.Flags().GetString(flagnames.Environment)

if err != nil || appName == nil || *appName == "" {
return errors.New("environment name and application name are required fields")
Expand All @@ -56,7 +58,7 @@ var deleteEnvironmentCmd = &cobra.Command{

func init() {
deleteCmd.AddCommand(deleteEnvironmentCmd)
deleteEnvironmentCmd.Flags().StringP("application", "a", "", "Name of the application namespace")
deleteEnvironmentCmd.Flags().StringP("environment", "e", "", "Name of the environment to delete")
deleteEnvironmentCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application")
deleteEnvironmentCmd.Flags().StringP(flagnames.Environment, "e", "", "Name of the environment to delete")
setContextSpecificPersistentFlags(deleteEnvironmentCmd)
}
5 changes: 3 additions & 2 deletions cmd/getApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/equinor/radix-cli/generated-client/client/application"
"github.com/equinor/radix-cli/generated-client/client/platform"
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/equinor/radix-cli/pkg/utils/json"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -32,7 +33,7 @@ var getApplicationCmd = &cobra.Command{
Short: "Gets Radix application",
Long: `Gets a list of Radix applications or a single application if provided`,
RunE: func(cmd *cobra.Command, args []string) error {
appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")
appName, err := getAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
}
Expand Down Expand Up @@ -73,6 +74,6 @@ var getApplicationCmd = &cobra.Command{

func init() {
getCmd.AddCommand(getApplicationCmd)
getApplicationCmd.Flags().StringP("application", "a", "", "Name of the application")
getApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application")
setContextSpecificPersistentFlags(getApplicationCmd)
}
Loading

0 comments on commit b2042d3

Please sign in to comment.