github.com/xgoffin/jenkins-library@v1.154.0/cmd/integrationArtifactResource_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 integrationArtifactResourceOptions struct { 19 APIServiceKey string `json:"apiServiceKey,omitempty"` 20 IntegrationFlowID string `json:"integrationFlowId,omitempty"` 21 Operation string `json:"operation,omitempty" validate:"possible-values=create update delete"` 22 ResourcePath string `json:"resourcePath,omitempty"` 23 } 24 25 // IntegrationArtifactResourceCommand Add, Delete or Update an resource file of integration flow designtime artifact 26 func IntegrationArtifactResourceCommand() *cobra.Command { 27 const STEP_NAME = "integrationArtifactResource" 28 29 metadata := integrationArtifactResourceMetadata() 30 var stepConfig integrationArtifactResourceOptions 31 var startTime time.Time 32 var logCollector *log.CollectorHook 33 var splunkClient *splunk.Splunk 34 telemetryClient := &telemetry.Telemetry{} 35 36 var createIntegrationArtifactResourceCmd = &cobra.Command{ 37 Use: STEP_NAME, 38 Short: "Add, Delete or Update an resource file of integration flow designtime artifact", 39 Long: `With this step you can either add, delete or update a resource of integration flow designtime artifact using the OData API. Learn more about the SAP Cloud Integration remote API for managing an resource of integration flow artifact [here](https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/d1679a80543f46509a7329243b595bdb.html).`, 40 PreRunE: func(cmd *cobra.Command, _ []string) error { 41 startTime = time.Now() 42 log.SetStepName(STEP_NAME) 43 log.SetVerbose(GeneralConfig.Verbose) 44 45 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 46 47 path, _ := os.Getwd() 48 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 49 log.RegisterHook(fatalHook) 50 51 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 52 if err != nil { 53 log.SetErrorCategory(log.ErrorConfiguration) 54 return err 55 } 56 log.RegisterSecret(stepConfig.APIServiceKey) 57 58 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 59 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 60 log.RegisterHook(&sentryHook) 61 } 62 63 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 64 splunkClient = &splunk.Splunk{} 65 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 66 log.RegisterHook(logCollector) 67 } 68 69 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 70 if err != nil { 71 return err 72 } 73 if err = validation.ValidateStruct(stepConfig); err != nil { 74 log.SetErrorCategory(log.ErrorConfiguration) 75 return err 76 } 77 78 return nil 79 }, 80 Run: func(_ *cobra.Command, _ []string) { 81 stepTelemetryData := telemetry.CustomData{} 82 stepTelemetryData.ErrorCode = "1" 83 handler := func() { 84 config.RemoveVaultSecretFiles() 85 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 86 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 87 stepTelemetryData.PiperCommitHash = GitCommit 88 telemetryClient.SetData(&stepTelemetryData) 89 telemetryClient.Send() 90 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 91 splunkClient.Send(telemetryClient.GetData(), logCollector) 92 } 93 } 94 log.DeferExitHandler(handler) 95 defer handler() 96 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 97 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 98 splunkClient.Initialize(GeneralConfig.CorrelationID, 99 GeneralConfig.HookConfig.SplunkConfig.Dsn, 100 GeneralConfig.HookConfig.SplunkConfig.Token, 101 GeneralConfig.HookConfig.SplunkConfig.Index, 102 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 103 } 104 integrationArtifactResource(stepConfig, &stepTelemetryData) 105 stepTelemetryData.ErrorCode = "0" 106 log.Entry().Info("SUCCESS") 107 }, 108 } 109 110 addIntegrationArtifactResourceFlags(createIntegrationArtifactResourceCmd, &stepConfig) 111 return createIntegrationArtifactResourceCmd 112 } 113 114 func addIntegrationArtifactResourceFlags(cmd *cobra.Command, stepConfig *integrationArtifactResourceOptions) { 115 cmd.Flags().StringVar(&stepConfig.APIServiceKey, "apiServiceKey", os.Getenv("PIPER_apiServiceKey"), "Service key JSON string to access the Process Integration Runtime service instance of plan 'api'") 116 cmd.Flags().StringVar(&stepConfig.IntegrationFlowID, "integrationFlowId", os.Getenv("PIPER_integrationFlowId"), "Specifies the ID of the Integration Flow artifact") 117 cmd.Flags().StringVar(&stepConfig.Operation, "operation", os.Getenv("PIPER_operation"), "Specifies the operation(create/update/delete) for resource file of the Integration Flow artifact") 118 cmd.Flags().StringVar(&stepConfig.ResourcePath, "resourcePath", os.Getenv("PIPER_resourcePath"), "Specifies integration artifact resource file relative path.") 119 120 cmd.MarkFlagRequired("apiServiceKey") 121 cmd.MarkFlagRequired("integrationFlowId") 122 cmd.MarkFlagRequired("operation") 123 cmd.MarkFlagRequired("resourcePath") 124 } 125 126 // retrieve step metadata 127 func integrationArtifactResourceMetadata() config.StepData { 128 var theMetaData = config.StepData{ 129 Metadata: config.StepMetadata{ 130 Name: "integrationArtifactResource", 131 Aliases: []config.Alias{}, 132 Description: "Add, Delete or Update an resource file of integration flow designtime artifact", 133 }, 134 Spec: config.StepSpec{ 135 Inputs: config.StepInputs{ 136 Secrets: []config.StepSecrets{ 137 {Name: "cpiApiServiceKeyCredentialsId", Description: "Jenkins secret text credential ID containing the service key to the Process Integration Runtime service instance of plan 'api'", Type: "jenkins"}, 138 }, 139 Parameters: []config.StepParameters{ 140 { 141 Name: "apiServiceKey", 142 ResourceRef: []config.ResourceReference{ 143 { 144 Name: "cpiApiServiceKeyCredentialsId", 145 Param: "apiServiceKey", 146 Type: "secret", 147 }, 148 }, 149 Scope: []string{"PARAMETERS"}, 150 Type: "string", 151 Mandatory: true, 152 Aliases: []config.Alias{}, 153 Default: os.Getenv("PIPER_apiServiceKey"), 154 }, 155 { 156 Name: "integrationFlowId", 157 ResourceRef: []config.ResourceReference{}, 158 Scope: []string{"PARAMETERS", "GENERAL", "STAGES", "STEPS"}, 159 Type: "string", 160 Mandatory: true, 161 Aliases: []config.Alias{}, 162 Default: os.Getenv("PIPER_integrationFlowId"), 163 }, 164 { 165 Name: "operation", 166 ResourceRef: []config.ResourceReference{}, 167 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 168 Type: "string", 169 Mandatory: true, 170 Aliases: []config.Alias{}, 171 Default: os.Getenv("PIPER_operation"), 172 }, 173 { 174 Name: "resourcePath", 175 ResourceRef: []config.ResourceReference{}, 176 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 177 Type: "string", 178 Mandatory: true, 179 Aliases: []config.Alias{}, 180 Default: os.Getenv("PIPER_resourcePath"), 181 }, 182 }, 183 }, 184 }, 185 } 186 return theMetaData 187 }