github.com/jaylevin/jenkins-library@v1.230.4/cmd/abapEnvironmentPushATCSystemConfig_generated.go (about) 1 // Code generated by piper's step-generator. DO NOT EDIT. 2 3 package cmd 4 5 import ( 6 "fmt" 7 "os" 8 "time" 9 10 "github.com/SAP/jenkins-library/pkg/config" 11 "github.com/SAP/jenkins-library/pkg/log" 12 "github.com/SAP/jenkins-library/pkg/splunk" 13 "github.com/SAP/jenkins-library/pkg/telemetry" 14 "github.com/SAP/jenkins-library/pkg/validation" 15 "github.com/spf13/cobra" 16 ) 17 18 type abapEnvironmentPushATCSystemConfigOptions struct { 19 AtcSystemConfigFilePath string `json:"atcSystemConfigFilePath,omitempty"` 20 PatchIfExisting bool `json:"patchIfExisting,omitempty"` 21 CfAPIEndpoint string `json:"cfApiEndpoint,omitempty"` 22 CfOrg string `json:"cfOrg,omitempty"` 23 CfServiceInstance string `json:"cfServiceInstance,omitempty"` 24 CfServiceKeyName string `json:"cfServiceKeyName,omitempty"` 25 CfSpace string `json:"cfSpace,omitempty"` 26 Username string `json:"username,omitempty"` 27 Password string `json:"password,omitempty"` 28 Host string `json:"host,omitempty"` 29 } 30 31 // AbapEnvironmentPushATCSystemConfigCommand Create/Update ATC System Configuration 32 func AbapEnvironmentPushATCSystemConfigCommand() *cobra.Command { 33 const STEP_NAME = "abapEnvironmentPushATCSystemConfig" 34 35 metadata := abapEnvironmentPushATCSystemConfigMetadata() 36 var stepConfig abapEnvironmentPushATCSystemConfigOptions 37 var startTime time.Time 38 var logCollector *log.CollectorHook 39 var splunkClient *splunk.Splunk 40 telemetryClient := &telemetry.Telemetry{} 41 42 var createAbapEnvironmentPushATCSystemConfigCmd = &cobra.Command{ 43 Use: STEP_NAME, 44 Short: "Create/Update ATC System Configuration", 45 Long: `This step is for creating/updating an [ATC](https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/657285a09f7148d894c27bb8e17827cf.html?version=Cloud) system configurationon on an SAP BTP, ABAP Environment system. 46 Please provide either of the following options: 47 48 * The host and credentials the SAP BTP, ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0763](https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/657285a09f7148d894c27bb8e17827cf.html?version=Cloud). 49 * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0763. 50 * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority.`, 51 PreRunE: func(cmd *cobra.Command, _ []string) error { 52 startTime = time.Now() 53 log.SetStepName(STEP_NAME) 54 log.SetVerbose(GeneralConfig.Verbose) 55 56 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 57 58 path, _ := os.Getwd() 59 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 60 log.RegisterHook(fatalHook) 61 62 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 63 if err != nil { 64 log.SetErrorCategory(log.ErrorConfiguration) 65 return err 66 } 67 log.RegisterSecret(stepConfig.Username) 68 log.RegisterSecret(stepConfig.Password) 69 70 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 71 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 72 log.RegisterHook(&sentryHook) 73 } 74 75 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 76 splunkClient = &splunk.Splunk{} 77 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 78 log.RegisterHook(logCollector) 79 } 80 81 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 82 if err != nil { 83 return err 84 } 85 if err = validation.ValidateStruct(stepConfig); err != nil { 86 log.SetErrorCategory(log.ErrorConfiguration) 87 return err 88 } 89 90 return nil 91 }, 92 Run: func(_ *cobra.Command, _ []string) { 93 stepTelemetryData := telemetry.CustomData{} 94 stepTelemetryData.ErrorCode = "1" 95 handler := func() { 96 config.RemoveVaultSecretFiles() 97 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 98 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 99 stepTelemetryData.PiperCommitHash = GitCommit 100 telemetryClient.SetData(&stepTelemetryData) 101 telemetryClient.Send() 102 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 103 splunkClient.Send(telemetryClient.GetData(), logCollector) 104 } 105 } 106 log.DeferExitHandler(handler) 107 defer handler() 108 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 109 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 110 splunkClient.Initialize(GeneralConfig.CorrelationID, 111 GeneralConfig.HookConfig.SplunkConfig.Dsn, 112 GeneralConfig.HookConfig.SplunkConfig.Token, 113 GeneralConfig.HookConfig.SplunkConfig.Index, 114 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 115 } 116 abapEnvironmentPushATCSystemConfig(stepConfig, &stepTelemetryData) 117 stepTelemetryData.ErrorCode = "0" 118 log.Entry().Info("SUCCESS") 119 }, 120 } 121 122 addAbapEnvironmentPushATCSystemConfigFlags(createAbapEnvironmentPushATCSystemConfigCmd, &stepConfig) 123 return createAbapEnvironmentPushATCSystemConfigCmd 124 } 125 126 func addAbapEnvironmentPushATCSystemConfigFlags(cmd *cobra.Command, stepConfig *abapEnvironmentPushATCSystemConfigOptions) { 127 cmd.Flags().StringVar(&stepConfig.AtcSystemConfigFilePath, "atcSystemConfigFilePath", os.Getenv("PIPER_atcSystemConfigFilePath"), "Path to a JSON file with ATC System Configuration") 128 cmd.Flags().BoolVar(&stepConfig.PatchIfExisting, "patchIfExisting", true, "In case an configuration under the given name already exists in the system. Should the step update/patch the existing ATC Systm Configuration from the provided ATC System Configuration file?") 129 cmd.Flags().StringVar(&stepConfig.CfAPIEndpoint, "cfApiEndpoint", os.Getenv("PIPER_cfApiEndpoint"), "Cloud Foundry API endpoint") 130 cmd.Flags().StringVar(&stepConfig.CfOrg, "cfOrg", os.Getenv("PIPER_cfOrg"), "CF org") 131 cmd.Flags().StringVar(&stepConfig.CfServiceInstance, "cfServiceInstance", os.Getenv("PIPER_cfServiceInstance"), "Parameter of ServiceInstance Name to delete CloudFoundry Service") 132 cmd.Flags().StringVar(&stepConfig.CfServiceKeyName, "cfServiceKeyName", os.Getenv("PIPER_cfServiceKeyName"), "Parameter of CloudFoundry Service Key to be created") 133 cmd.Flags().StringVar(&stepConfig.CfSpace, "cfSpace", os.Getenv("PIPER_cfSpace"), "CF Space") 134 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0763") 135 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0763") 136 cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the host address of the SAP SAP BTP, ABAP Environment system") 137 138 cmd.MarkFlagRequired("atcSystemConfigFilePath") 139 cmd.MarkFlagRequired("username") 140 cmd.MarkFlagRequired("password") 141 } 142 143 // retrieve step metadata 144 func abapEnvironmentPushATCSystemConfigMetadata() config.StepData { 145 var theMetaData = config.StepData{ 146 Metadata: config.StepMetadata{ 147 Name: "abapEnvironmentPushATCSystemConfig", 148 Aliases: []config.Alias{}, 149 Description: "Create/Update ATC System Configuration", 150 }, 151 Spec: config.StepSpec{ 152 Inputs: config.StepInputs{ 153 Secrets: []config.StepSecrets{ 154 {Name: "abapCredentialsId", Description: "Jenkins credentials ID containing user and password to authenticate to the SAP BTP, ABAP Environment system or the Cloud Foundry API", Type: "jenkins", Aliases: []config.Alias{{Name: "cfCredentialsId", Deprecated: false}}}, 155 }, 156 Parameters: []config.StepParameters{ 157 { 158 Name: "atcSystemConfigFilePath", 159 ResourceRef: []config.ResourceReference{}, 160 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 161 Type: "string", 162 Mandatory: true, 163 Aliases: []config.Alias{}, 164 Default: os.Getenv("PIPER_atcSystemConfigFilePath"), 165 }, 166 { 167 Name: "patchIfExisting", 168 ResourceRef: []config.ResourceReference{}, 169 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 170 Type: "bool", 171 Mandatory: false, 172 Aliases: []config.Alias{}, 173 Default: true, 174 }, 175 { 176 Name: "cfApiEndpoint", 177 ResourceRef: []config.ResourceReference{}, 178 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 179 Type: "string", 180 Mandatory: false, 181 Aliases: []config.Alias{{Name: "cloudFoundry/apiEndpoint"}}, 182 Default: os.Getenv("PIPER_cfApiEndpoint"), 183 }, 184 { 185 Name: "cfOrg", 186 ResourceRef: []config.ResourceReference{}, 187 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 188 Type: "string", 189 Mandatory: false, 190 Aliases: []config.Alias{{Name: "cloudFoundry/org"}}, 191 Default: os.Getenv("PIPER_cfOrg"), 192 }, 193 { 194 Name: "cfServiceInstance", 195 ResourceRef: []config.ResourceReference{}, 196 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 197 Type: "string", 198 Mandatory: false, 199 Aliases: []config.Alias{{Name: "cloudFoundry/serviceInstance"}}, 200 Default: os.Getenv("PIPER_cfServiceInstance"), 201 }, 202 { 203 Name: "cfServiceKeyName", 204 ResourceRef: []config.ResourceReference{}, 205 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 206 Type: "string", 207 Mandatory: false, 208 Aliases: []config.Alias{{Name: "cloudFoundry/serviceKey"}, {Name: "cloudFoundry/serviceKeyName"}, {Name: "cfServiceKey"}}, 209 Default: os.Getenv("PIPER_cfServiceKeyName"), 210 }, 211 { 212 Name: "cfSpace", 213 ResourceRef: []config.ResourceReference{}, 214 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 215 Type: "string", 216 Mandatory: false, 217 Aliases: []config.Alias{{Name: "cloudFoundry/space"}}, 218 Default: os.Getenv("PIPER_cfSpace"), 219 }, 220 { 221 Name: "username", 222 ResourceRef: []config.ResourceReference{ 223 { 224 Name: "abapCredentialsId", 225 Param: "username", 226 Type: "secret", 227 }, 228 }, 229 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 230 Type: "string", 231 Mandatory: true, 232 Aliases: []config.Alias{}, 233 Default: os.Getenv("PIPER_username"), 234 }, 235 { 236 Name: "password", 237 ResourceRef: []config.ResourceReference{ 238 { 239 Name: "abapCredentialsId", 240 Param: "password", 241 Type: "secret", 242 }, 243 }, 244 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 245 Type: "string", 246 Mandatory: true, 247 Aliases: []config.Alias{}, 248 Default: os.Getenv("PIPER_password"), 249 }, 250 { 251 Name: "host", 252 ResourceRef: []config.ResourceReference{}, 253 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 254 Type: "string", 255 Mandatory: false, 256 Aliases: []config.Alias{}, 257 Default: os.Getenv("PIPER_host"), 258 }, 259 }, 260 }, 261 Containers: []config.Container{ 262 {Name: "cf", Image: "ppiper/cf-cli:7"}, 263 }, 264 }, 265 } 266 return theMetaData 267 }