You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	IntegrationArtifactUpdateConfiguration Command (#2542)
* IntegrationArtifactUpdateConfiguration Command Co-authored-by: Marcus Holl <marcus.holl@sap.com>
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							1c140e7cb4
						
					
				
				
					commit
					0ed5cce53a
				
			
							
								
								
									
										113
									
								
								cmd/integrationArtifactUpdateConfiguration.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								cmd/integrationArtifactUpdateConfiguration.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,113 @@ | |||||||
|  | package cmd | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"bytes" | ||||||
|  | 	"encoding/json" | ||||||
|  | 	"fmt" | ||||||
|  | 	"io/ioutil" | ||||||
|  | 	"net/http" | ||||||
|  |  | ||||||
|  | 	"github.com/Jeffail/gabs/v2" | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/command" | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/cpi" | ||||||
|  | 	piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/log" | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||||
|  | 	"github.com/pkg/errors" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | type integrationArtifactUpdateConfigurationUtils interface { | ||||||
|  | 	command.ExecRunner | ||||||
|  |  | ||||||
|  | 	// Add more methods here, or embed additional interfaces, or remove/replace as required. | ||||||
|  | 	// The integrationArtifactUpdateConfigurationUtils interface should be descriptive of your runtime dependencies, | ||||||
|  | 	// i.e. include everything you need to be able to mock in tests. | ||||||
|  | 	// Unit tests shall be executable in parallel (not depend on global state), and don't (re-)test dependencies. | ||||||
|  | } | ||||||
|  |  | ||||||
|  | type integrationArtifactUpdateConfigurationUtilsBundle struct { | ||||||
|  | 	*command.Command | ||||||
|  |  | ||||||
|  | 	// Embed more structs as necessary to implement methods or interfaces you add to integrationArtifactUpdateConfigurationUtils. | ||||||
|  | 	// Structs embedded in this way must each have a unique set of methods attached. | ||||||
|  | 	// If there is no struct which implements the method you need, attach the method to | ||||||
|  | 	// integrationArtifactUpdateConfigurationUtilsBundle and forward to the implementation of the dependency. | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func newIntegrationArtifactUpdateConfigurationUtils() integrationArtifactUpdateConfigurationUtils { | ||||||
|  | 	utils := integrationArtifactUpdateConfigurationUtilsBundle{ | ||||||
|  | 		Command: &command.Command{}, | ||||||
|  | 	} | ||||||
|  | 	// Reroute command output to logging framework | ||||||
|  | 	utils.Stdout(log.Writer()) | ||||||
|  | 	utils.Stderr(log.Writer()) | ||||||
|  | 	return &utils | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func integrationArtifactUpdateConfiguration(config integrationArtifactUpdateConfigurationOptions, telemetryData *telemetry.CustomData) { | ||||||
|  | 	// Utils can be used wherever the command.ExecRunner interface is expected. | ||||||
|  | 	// It can also be used for example as a mavenExecRunner. | ||||||
|  | 	httpClient := &piperhttp.Client{} | ||||||
|  |  | ||||||
|  | 	// For HTTP calls import  piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||||
|  | 	// and use a  &piperhttp.Client{} in a custom system | ||||||
|  | 	// Example: step checkmarxExecuteScan.go | ||||||
|  |  | ||||||
|  | 	// Error situations should be bubbled up until they reach the line below which will then stop execution | ||||||
|  | 	// through the log.Entry().Fatal() call leading to an os.Exit(1) in the end. | ||||||
|  | 	err := runIntegrationArtifactUpdateConfiguration(&config, telemetryData, httpClient) | ||||||
|  | 	if err != nil { | ||||||
|  | 		log.Entry().WithError(err).Fatal("step execution failed") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func runIntegrationArtifactUpdateConfiguration(config *integrationArtifactUpdateConfigurationOptions, telemetryData *telemetry.CustomData, httpClient piperhttp.Sender) error { | ||||||
|  | 	clientOptions := piperhttp.ClientOptions{} | ||||||
|  |  | ||||||
|  | 	configUpdateURL := fmt.Sprintf("%s/api/v1/IntegrationDesigntimeArtifacts(Id='%s',Version='%s')/$links/Configurations('%s')", config.Host, config.IntegrationFlowID, config.IntegrationFlowVersion, config.ParameterKey) | ||||||
|  | 	tokenParameters := cpi.TokenParameters{TokenURL: config.OAuthTokenProviderURL, Username: config.Username, Password: config.Password, Client: httpClient} | ||||||
|  | 	token, err := cpi.CommonUtils.GetBearerToken(tokenParameters) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return errors.Wrap(err, "failed to fetch Bearer Token") | ||||||
|  | 	} | ||||||
|  | 	clientOptions.Token = fmt.Sprintf("Bearer %s", token) | ||||||
|  | 	httpClient.SetOptions(clientOptions) | ||||||
|  | 	httpMethod := "PUT" | ||||||
|  | 	header := make(http.Header) | ||||||
|  | 	header.Add("Content-Type", "application/json") | ||||||
|  | 	header.Add("Accept", "application/json") | ||||||
|  | 	jsonObj := gabs.New() | ||||||
|  | 	jsonObj.Set(config.ParameterValue, "ParameterValue") | ||||||
|  | 	jsonBody, jsonErr := json.Marshal(jsonObj) | ||||||
|  |  | ||||||
|  | 	if jsonErr != nil { | ||||||
|  | 		return errors.Wrapf(jsonErr, "input json body is invalid for parameterValue %q", config.ParameterValue) | ||||||
|  | 	} | ||||||
|  | 	configUpdateResp, httpErr := httpClient.SendRequest(httpMethod, configUpdateURL, bytes.NewBuffer(jsonBody), header, nil) | ||||||
|  | 	if httpErr != nil { | ||||||
|  | 		return errors.Wrapf(httpErr, "HTTP %q request to %q failed with error", httpMethod, configUpdateURL) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if configUpdateResp != nil && configUpdateResp.Body != nil { | ||||||
|  | 		defer configUpdateResp.Body.Close() | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if configUpdateResp == nil { | ||||||
|  | 		return errors.Errorf("did not retrieve a HTTP response") | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if configUpdateResp.StatusCode == http.StatusAccepted { | ||||||
|  | 		log.Entry(). | ||||||
|  | 			WithField("IntegrationFlowID", config.IntegrationFlowID). | ||||||
|  | 			Info("successfully updated the integration flow configuration parameter") | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 	response, readErr := ioutil.ReadAll(configUpdateResp.Body) | ||||||
|  |  | ||||||
|  | 	if readErr != nil { | ||||||
|  | 		return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code: %v", configUpdateResp.StatusCode) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	log.Entry().Errorf("a HTTP error occurred! Response body: %v, Response status code: %v", response, configUpdateResp.StatusCode) | ||||||
|  | 	return errors.Errorf("Failed to update the integration flow configuration parameter, Response Status code: %v", configUpdateResp.StatusCode) | ||||||
|  | } | ||||||
							
								
								
									
										207
									
								
								cmd/integrationArtifactUpdateConfiguration_generated.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										207
									
								
								cmd/integrationArtifactUpdateConfiguration_generated.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,207 @@ | |||||||
|  | // Code generated by piper's step-generator. DO NOT EDIT. | ||||||
|  |  | ||||||
|  | package cmd | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"os" | ||||||
|  | 	"time" | ||||||
|  |  | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/config" | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/log" | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||||
|  | 	"github.com/spf13/cobra" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | type integrationArtifactUpdateConfigurationOptions struct { | ||||||
|  | 	Username               string `json:"username,omitempty"` | ||||||
|  | 	Password               string `json:"password,omitempty"` | ||||||
|  | 	IntegrationFlowID      string `json:"integrationFlowId,omitempty"` | ||||||
|  | 	IntegrationFlowVersion string `json:"integrationFlowVersion,omitempty"` | ||||||
|  | 	Platform               string `json:"platform,omitempty"` | ||||||
|  | 	Host                   string `json:"host,omitempty"` | ||||||
|  | 	OAuthTokenProviderURL  string `json:"oAuthTokenProviderUrl,omitempty"` | ||||||
|  | 	ParameterKey           string `json:"parameterKey,omitempty"` | ||||||
|  | 	ParameterValue         string `json:"parameterValue,omitempty"` | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // IntegrationArtifactUpdateConfigurationCommand Update integration flow Configuration parameter | ||||||
|  | func IntegrationArtifactUpdateConfigurationCommand() *cobra.Command { | ||||||
|  | 	const STEP_NAME = "integrationArtifactUpdateConfiguration" | ||||||
|  |  | ||||||
|  | 	metadata := integrationArtifactUpdateConfigurationMetadata() | ||||||
|  | 	var stepConfig integrationArtifactUpdateConfigurationOptions | ||||||
|  | 	var startTime time.Time | ||||||
|  |  | ||||||
|  | 	var createIntegrationArtifactUpdateConfigurationCmd = &cobra.Command{ | ||||||
|  | 		Use:   STEP_NAME, | ||||||
|  | 		Short: "Update integration flow Configuration parameter", | ||||||
|  | 		Long:  `With this step you can update the value for a configuration parameters of a designtime integration flow using the OData API. Learn more about the SAP Cloud Integration remote API for configuration update of the integration flow parameter [here](https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/83733a65c0214aa6acba035e8640bb5a.html).`, | ||||||
|  | 		PreRunE: func(cmd *cobra.Command, _ []string) error { | ||||||
|  | 			startTime = time.Now() | ||||||
|  | 			log.SetStepName(STEP_NAME) | ||||||
|  | 			log.SetVerbose(GeneralConfig.Verbose) | ||||||
|  |  | ||||||
|  | 			path, _ := os.Getwd() | ||||||
|  | 			fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} | ||||||
|  | 			log.RegisterHook(fatalHook) | ||||||
|  |  | ||||||
|  | 			err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) | ||||||
|  | 			if err != nil { | ||||||
|  | 				log.SetErrorCategory(log.ErrorConfiguration) | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 			log.RegisterSecret(stepConfig.Username) | ||||||
|  | 			log.RegisterSecret(stepConfig.Password) | ||||||
|  |  | ||||||
|  | 			if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { | ||||||
|  | 				sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) | ||||||
|  | 				log.RegisterHook(&sentryHook) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			return nil | ||||||
|  | 		}, | ||||||
|  | 		Run: func(_ *cobra.Command, _ []string) { | ||||||
|  | 			telemetryData := telemetry.CustomData{} | ||||||
|  | 			telemetryData.ErrorCode = "1" | ||||||
|  | 			handler := func() { | ||||||
|  | 				config.RemoveVaultSecretFiles() | ||||||
|  | 				telemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) | ||||||
|  | 				telemetryData.ErrorCategory = log.GetErrorCategory().String() | ||||||
|  | 				telemetry.Send(&telemetryData) | ||||||
|  | 			} | ||||||
|  | 			log.DeferExitHandler(handler) | ||||||
|  | 			defer handler() | ||||||
|  | 			telemetry.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) | ||||||
|  | 			integrationArtifactUpdateConfiguration(stepConfig, &telemetryData) | ||||||
|  | 			telemetryData.ErrorCode = "0" | ||||||
|  | 			log.Entry().Info("SUCCESS") | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	addIntegrationArtifactUpdateConfigurationFlags(createIntegrationArtifactUpdateConfigurationCmd, &stepConfig) | ||||||
|  | 	return createIntegrationArtifactUpdateConfigurationCmd | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func addIntegrationArtifactUpdateConfigurationFlags(cmd *cobra.Command, stepConfig *integrationArtifactUpdateConfigurationOptions) { | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User to authenticate to the SAP Cloud Platform Integration Service") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password to authenticate to the SAP Cloud Platform Integration Service") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.IntegrationFlowID, "integrationFlowId", os.Getenv("PIPER_integrationFlowId"), "Specifies the ID of the Integration Flow artifact") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.IntegrationFlowVersion, "integrationFlowVersion", os.Getenv("PIPER_integrationFlowVersion"), "Specifies the version of the Integration Flow artifact") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.Platform, "platform", os.Getenv("PIPER_platform"), "Specifies the running platform of the SAP Cloud platform integraion service") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`.") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.OAuthTokenProviderURL, "oAuthTokenProviderUrl", os.Getenv("PIPER_oAuthTokenProviderUrl"), "Specifies the oAuth Provider protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`.") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.ParameterKey, "parameterKey", os.Getenv("PIPER_parameterKey"), "Specifies the externalized parameter name.") | ||||||
|  | 	cmd.Flags().StringVar(&stepConfig.ParameterValue, "parameterValue", os.Getenv("PIPER_parameterValue"), "Specifies the externalized parameter value.") | ||||||
|  |  | ||||||
|  | 	cmd.MarkFlagRequired("username") | ||||||
|  | 	cmd.MarkFlagRequired("password") | ||||||
|  | 	cmd.MarkFlagRequired("integrationFlowId") | ||||||
|  | 	cmd.MarkFlagRequired("integrationFlowVersion") | ||||||
|  | 	cmd.MarkFlagRequired("host") | ||||||
|  | 	cmd.MarkFlagRequired("oAuthTokenProviderUrl") | ||||||
|  | 	cmd.MarkFlagRequired("parameterKey") | ||||||
|  | 	cmd.MarkFlagRequired("parameterValue") | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // retrieve step metadata | ||||||
|  | func integrationArtifactUpdateConfigurationMetadata() config.StepData { | ||||||
|  | 	var theMetaData = config.StepData{ | ||||||
|  | 		Metadata: config.StepMetadata{ | ||||||
|  | 			Name:        "integrationArtifactUpdateConfiguration", | ||||||
|  | 			Aliases:     []config.Alias{}, | ||||||
|  | 			Description: "Update integration flow Configuration parameter", | ||||||
|  | 		}, | ||||||
|  | 		Spec: config.StepSpec{ | ||||||
|  | 			Inputs: config.StepInputs{ | ||||||
|  | 				Parameters: []config.StepParameters{ | ||||||
|  | 					{ | ||||||
|  | 						Name: "username", | ||||||
|  | 						ResourceRef: []config.ResourceReference{ | ||||||
|  | 							{ | ||||||
|  | 								Name:  "cpiCredentialsId", | ||||||
|  | 								Param: "username", | ||||||
|  | 								Type:  "secret", | ||||||
|  | 							}, | ||||||
|  | 						}, | ||||||
|  | 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:      "string", | ||||||
|  | 						Mandatory: true, | ||||||
|  | 						Aliases:   []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name: "password", | ||||||
|  | 						ResourceRef: []config.ResourceReference{ | ||||||
|  | 							{ | ||||||
|  | 								Name:  "cpiCredentialsId", | ||||||
|  | 								Param: "password", | ||||||
|  | 								Type:  "secret", | ||||||
|  | 							}, | ||||||
|  | 						}, | ||||||
|  | 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:      "string", | ||||||
|  | 						Mandatory: true, | ||||||
|  | 						Aliases:   []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name:        "integrationFlowId", | ||||||
|  | 						ResourceRef: []config.ResourceReference{}, | ||||||
|  | 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:        "string", | ||||||
|  | 						Mandatory:   true, | ||||||
|  | 						Aliases:     []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name:        "integrationFlowVersion", | ||||||
|  | 						ResourceRef: []config.ResourceReference{}, | ||||||
|  | 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:        "string", | ||||||
|  | 						Mandatory:   true, | ||||||
|  | 						Aliases:     []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name:        "platform", | ||||||
|  | 						ResourceRef: []config.ResourceReference{}, | ||||||
|  | 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:        "string", | ||||||
|  | 						Mandatory:   false, | ||||||
|  | 						Aliases:     []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name:        "host", | ||||||
|  | 						ResourceRef: []config.ResourceReference{}, | ||||||
|  | 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:        "string", | ||||||
|  | 						Mandatory:   true, | ||||||
|  | 						Aliases:     []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name:        "oAuthTokenProviderUrl", | ||||||
|  | 						ResourceRef: []config.ResourceReference{}, | ||||||
|  | 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:        "string", | ||||||
|  | 						Mandatory:   true, | ||||||
|  | 						Aliases:     []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name:        "parameterKey", | ||||||
|  | 						ResourceRef: []config.ResourceReference{}, | ||||||
|  | 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:        "string", | ||||||
|  | 						Mandatory:   true, | ||||||
|  | 						Aliases:     []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 					{ | ||||||
|  | 						Name:        "parameterValue", | ||||||
|  | 						ResourceRef: []config.ResourceReference{}, | ||||||
|  | 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||||
|  | 						Type:        "string", | ||||||
|  | 						Mandatory:   true, | ||||||
|  | 						Aliases:     []config.Alias{}, | ||||||
|  | 					}, | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | 	return theMetaData | ||||||
|  | } | ||||||
							
								
								
									
										17
									
								
								cmd/integrationArtifactUpdateConfiguration_generated_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								cmd/integrationArtifactUpdateConfiguration_generated_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | package cmd | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"testing" | ||||||
|  |  | ||||||
|  | 	"github.com/stretchr/testify/assert" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func TestIntegrationArtifactUpdateConfigurationCommand(t *testing.T) { | ||||||
|  | 	t.Parallel() | ||||||
|  |  | ||||||
|  | 	testCmd := IntegrationArtifactUpdateConfigurationCommand() | ||||||
|  |  | ||||||
|  | 	// only high level testing performed - details are tested in step generation procedure | ||||||
|  | 	assert.Equal(t, "integrationArtifactUpdateConfiguration", testCmd.Use, "command name incorrect") | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										88
									
								
								cmd/integrationArtifactUpdateConfiguration_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								cmd/integrationArtifactUpdateConfiguration_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | |||||||
|  | package cmd | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"testing" | ||||||
|  |  | ||||||
|  | 	"github.com/SAP/jenkins-library/pkg/mock" | ||||||
|  | 	"github.com/stretchr/testify/assert" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | type integrationArtifactUpdateConfigurationMockUtils struct { | ||||||
|  | 	*mock.ExecMockRunner | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func newIntegrationArtifactUpdateConfigurationTestsUtils() integrationArtifactUpdateConfigurationMockUtils { | ||||||
|  | 	utils := integrationArtifactUpdateConfigurationMockUtils{ | ||||||
|  | 		ExecMockRunner: &mock.ExecMockRunner{}, | ||||||
|  | 	} | ||||||
|  | 	return utils | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func TestRunIntegrationArtifactUpdateConfiguration(t *testing.T) { | ||||||
|  | 	t.Parallel() | ||||||
|  |  | ||||||
|  | 	t.Run("Successfully update of Integration Flow configuration parameter test", func(t *testing.T) { | ||||||
|  | 		config := integrationArtifactUpdateConfigurationOptions{ | ||||||
|  | 			Host:                   "https://demo", | ||||||
|  | 			OAuthTokenProviderURL:  "https://demo/oauth/token", | ||||||
|  | 			Username:               "demouser", | ||||||
|  | 			Password:               "******", | ||||||
|  | 			IntegrationFlowID:      "flow1", | ||||||
|  | 			IntegrationFlowVersion: "1.0.1", | ||||||
|  | 			ParameterKey:           "myheader", | ||||||
|  | 			ParameterValue:         "def", | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Positive", Method: "PUT", URL: "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')"} | ||||||
|  |  | ||||||
|  | 		err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient) | ||||||
|  |  | ||||||
|  | 		if assert.NoError(t, err) { | ||||||
|  |  | ||||||
|  | 			t.Run("check url", func(t *testing.T) { | ||||||
|  | 				assert.Equal(t, "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')", httpClient.URL) | ||||||
|  | 			}) | ||||||
|  |  | ||||||
|  | 			t.Run("check method", func(t *testing.T) { | ||||||
|  | 				assert.Equal(t, "PUT", httpClient.Method) | ||||||
|  | 			}) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 	}) | ||||||
|  |  | ||||||
|  | 	t.Run("Failed case of Integration Flow configuration parameter Test", func(t *testing.T) { | ||||||
|  | 		config := integrationArtifactUpdateConfigurationOptions{ | ||||||
|  | 			Host:                   "https://demo", | ||||||
|  | 			OAuthTokenProviderURL:  "https://demo/oauth/token", | ||||||
|  | 			Username:               "demouser", | ||||||
|  | 			Password:               "******", | ||||||
|  | 			IntegrationFlowID:      "flow1", | ||||||
|  | 			IntegrationFlowVersion: "1.0.1", | ||||||
|  | 			ParameterKey:           "myheader", | ||||||
|  | 			ParameterValue:         "def", | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative"} | ||||||
|  |  | ||||||
|  | 		err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient) | ||||||
|  | 		assert.EqualError(t, err, "HTTP \"PUT\" request to \"https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')\" failed with error: Not found - either wrong version for the given Id or wrong parameter key") | ||||||
|  | 	}) | ||||||
|  |  | ||||||
|  | 	t.Run("Failed case of Integration Flow configuration parameter test with error body", func(t *testing.T) { | ||||||
|  | 		config := integrationArtifactUpdateConfigurationOptions{ | ||||||
|  | 			Host:                   "https://demo", | ||||||
|  | 			OAuthTokenProviderURL:  "https://demo/oauth/token", | ||||||
|  | 			Username:               "demouser", | ||||||
|  | 			Password:               "******", | ||||||
|  | 			IntegrationFlowID:      "flow1", | ||||||
|  | 			IntegrationFlowVersion: "1.0.1", | ||||||
|  | 			ParameterKey:           "myheader", | ||||||
|  | 			ParameterValue:         "def", | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative_With_ResponseBody"} | ||||||
|  |  | ||||||
|  | 		err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient) | ||||||
|  | 		assert.EqualError(t, err, "Failed to update the integration flow configuration parameter, Response Status code: 400") | ||||||
|  | 	}) | ||||||
|  | } | ||||||
| @@ -43,6 +43,7 @@ func GetAllStepMetadata() map[string]config.StepData { | |||||||
| 		"gitopsUpdateDeployment":                  gitopsUpdateDeploymentMetadata(), | 		"gitopsUpdateDeployment":                  gitopsUpdateDeploymentMetadata(), | ||||||
| 		"hadolintExecute":                         hadolintExecuteMetadata(), | 		"hadolintExecute":                         hadolintExecuteMetadata(), | ||||||
| 		"integrationArtifactDeploy":               integrationArtifactDeployMetadata(), | 		"integrationArtifactDeploy":               integrationArtifactDeployMetadata(), | ||||||
|  | 		"integrationArtifactUpdateConfiguration":  integrationArtifactUpdateConfigurationMetadata(), | ||||||
| 		"jsonApplyPatch":                          jsonApplyPatchMetadata(), | 		"jsonApplyPatch":                          jsonApplyPatchMetadata(), | ||||||
| 		"kanikoExecute":                           kanikoExecuteMetadata(), | 		"kanikoExecute":                           kanikoExecuteMetadata(), | ||||||
| 		"karmaExecuteTests":                       karmaExecuteTestsMetadata(), | 		"karmaExecuteTests":                       karmaExecuteTestsMetadata(), | ||||||
|   | |||||||
| @@ -123,6 +123,7 @@ func Execute() { | |||||||
| 	rootCmd.AddCommand(VaultRotateSecretIdCommand()) | 	rootCmd.AddCommand(VaultRotateSecretIdCommand()) | ||||||
| 	rootCmd.AddCommand(TransportRequestUploadCTSCommand()) | 	rootCmd.AddCommand(TransportRequestUploadCTSCommand()) | ||||||
| 	rootCmd.AddCommand(IntegrationArtifactDeployCommand()) | 	rootCmd.AddCommand(IntegrationArtifactDeployCommand()) | ||||||
|  | 	rootCmd.AddCommand(IntegrationArtifactUpdateConfigurationCommand()) | ||||||
|  |  | ||||||
| 	addRootFlags(rootCmd) | 	addRootFlags(rootCmd) | ||||||
| 	if err := rootCmd.Execute(); err != nil { | 	if err := rootCmd.Execute(); err != nil { | ||||||
|   | |||||||
| @@ -0,0 +1,35 @@ | |||||||
|  | # ${docGenStepName} | ||||||
|  |  | ||||||
|  | ## ${docGenDescription} | ||||||
|  |  | ||||||
|  | ## Prerequisites | ||||||
|  |  | ||||||
|  | ## ${docGenParameters} | ||||||
|  |  | ||||||
|  | ## ${docGenConfiguration} | ||||||
|  |  | ||||||
|  | ## ${docJenkinsPluginDependencies} | ||||||
|  |  | ||||||
|  | ## Example | ||||||
|  |  | ||||||
|  | Example configuration for the use in a `Jenkinsfile`. | ||||||
|  |  | ||||||
|  | ```groovy | ||||||
|  | integrationArtifactUpdateConfiguration script: this | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | Example of a YAML configuration file (such as `.pipeline/config.yaml`). | ||||||
|  |  | ||||||
|  | ```yaml | ||||||
|  | steps: | ||||||
|  |   <...> | ||||||
|  |   integrationArtifactUpdateConfiguration: | ||||||
|  |     cpiCredentialsId: 'MY_CPI_OAUTH_CREDENTIALSID_IN_JENKINS' | ||||||
|  |     integrationFlowId: 'MY_INTEGRATION_FLOW_NAME' | ||||||
|  |     integrationFlowVersion: 'MY_INTEGRATION_FLOW_VERSION' | ||||||
|  |     platform: 'cf' | ||||||
|  |     host: 'https://CPI_HOST_ITSPACES_URL' | ||||||
|  |     oAuthTokenProviderUrl: 'https://CPI_HOST_OAUTH_URL' | ||||||
|  |     parameterKey: 'MY_INTEGRATION_FLOW_CONFIG_PARAMETER_NAME' | ||||||
|  |     parameterValue: 'MY_INTEGRATION_FLOW_CONFIG_PARAMETER_VALUE' | ||||||
|  | ``` | ||||||
| @@ -101,6 +101,7 @@ nav: | |||||||
|         - healthExecuteCheck: steps/healthExecuteCheck.md |         - healthExecuteCheck: steps/healthExecuteCheck.md | ||||||
|         - influxWriteData: steps/influxWriteData.md |         - influxWriteData: steps/influxWriteData.md | ||||||
|         - integrationArtifactDeploy: steps/integrationArtifactDeploy.md |         - integrationArtifactDeploy: steps/integrationArtifactDeploy.md | ||||||
|  |         - integrationArtifactUpdateConfiguration: steps/integrationArtifactUpdateConfiguration.md | ||||||
|         - jenkinsMaterializeLog: steps/jenkinsMaterializeLog.md |         - jenkinsMaterializeLog: steps/jenkinsMaterializeLog.md | ||||||
|         - kanikoExecute: steps/kanikoExecute.md |         - kanikoExecute: steps/kanikoExecute.md | ||||||
|         - karmaExecuteTests: steps/karmaExecuteTests.md |         - karmaExecuteTests: steps/karmaExecuteTests.md | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response, | |||||||
| 	switch functionName { | 	switch functionName { | ||||||
| 	case "IntegrationArtifactDeploy": | 	case "IntegrationArtifactDeploy": | ||||||
| 		if testType == "Positive" { | 		if testType == "Positive" { | ||||||
| 			return GetEmptyHTTPResponseBody() | 			return GetEmptyHTTPResponseBodyAndErrorNil() | ||||||
| 		} | 		} | ||||||
| 		res := http.Response{ | 		res := http.Response{ | ||||||
| 			StatusCode: 500, | 			StatusCode: 500, | ||||||
| @@ -28,6 +28,24 @@ func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response, | |||||||
| 					}`))), | 					}`))), | ||||||
| 		} | 		} | ||||||
| 		return &res, errors.New("Internal Server Error") | 		return &res, errors.New("Internal Server Error") | ||||||
|  | 	case "IntegrationArtifactUpdateConfiguration": | ||||||
|  | 		if testType == "Positive" { | ||||||
|  | 			return GetEmptyHTTPResponseBodyAndErrorNil() | ||||||
|  | 		} | ||||||
|  | 		if testType == "Negative_With_ResponseBody" { | ||||||
|  | 			return GetNegativeCaseHTTPResponseBodyAndErrorNil() | ||||||
|  | 		} | ||||||
|  | 		res := http.Response{ | ||||||
|  | 			StatusCode: 404, | ||||||
|  | 			Body: ioutil.NopCloser(bytes.NewReader([]byte(`{ | ||||||
|  | 						"code": "Not Found", | ||||||
|  | 						"message": { | ||||||
|  | 						"@lang": "en", | ||||||
|  | 						"#text": "Parameter key 'Parameter1' not found." | ||||||
|  | 						} | ||||||
|  | 					}`))), | ||||||
|  | 		} | ||||||
|  | 		return &res, errors.New("Not found - either wrong version for the given Id or wrong parameter key") | ||||||
| 	default: | 	default: | ||||||
| 		res := http.Response{ | 		res := http.Response{ | ||||||
| 			StatusCode: 404, | 			StatusCode: 404, | ||||||
| @@ -37,11 +55,26 @@ func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response, | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| //GetEmptyHTTPResponseBody -Empty http respose body | //GetEmptyHTTPResponseBodyAndErrorNil -Empty http respose body | ||||||
| func GetEmptyHTTPResponseBody() (*http.Response, error) { | func GetEmptyHTTPResponseBodyAndErrorNil() (*http.Response, error) { | ||||||
| 	res := http.Response{ | 	res := http.Response{ | ||||||
| 		StatusCode: 202, | 		StatusCode: 202, | ||||||
| 		Body:       ioutil.NopCloser(bytes.NewReader([]byte(``))), | 		Body:       ioutil.NopCloser(bytes.NewReader([]byte(``))), | ||||||
| 	} | 	} | ||||||
| 	return &res, nil | 	return &res, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | //GetNegativeCaseHTTPResponseBodyAndErrorNil -Negative case http respose body | ||||||
|  | func GetNegativeCaseHTTPResponseBodyAndErrorNil() (*http.Response, error) { | ||||||
|  | 	res := http.Response{ | ||||||
|  | 		StatusCode: 400, | ||||||
|  | 		Body: ioutil.NopCloser(bytes.NewReader([]byte(`{ | ||||||
|  | 					"code": "Bad Request", | ||||||
|  | 					"message": { | ||||||
|  | 					"@lang": "en", | ||||||
|  | 					"#text": "Wrong body format for the expected parameter value" | ||||||
|  | 					} | ||||||
|  | 				}`))), | ||||||
|  | 	} | ||||||
|  | 	return &res, nil | ||||||
|  | } | ||||||
|   | |||||||
| @@ -0,0 +1,95 @@ | |||||||
|  | metadata: | ||||||
|  |   name: integrationArtifactUpdateConfiguration | ||||||
|  |   description: Update integration flow Configuration parameter | ||||||
|  |   longDescription: | | ||||||
|  |     With this step you can update the value for a configuration parameters of a designtime integration flow using the OData API. Learn more about the SAP Cloud Integration remote API for configuration update of the integration flow parameter [here](https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/83733a65c0214aa6acba035e8640bb5a.html). | ||||||
|  |  | ||||||
|  | spec: | ||||||
|  |   inputs: | ||||||
|  |     secrets: | ||||||
|  |       - name: cpiCredentialsId | ||||||
|  |         description: Jenkins credentials ID containing username and password for authentication to the SAP Cloud Platform Integration API's | ||||||
|  |         type: jenkins | ||||||
|  |     params: | ||||||
|  |       - name: username | ||||||
|  |         type: string | ||||||
|  |         description: User to authenticate to the SAP Cloud Platform Integration Service | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
|  |         secret: true | ||||||
|  |         resourceRef: | ||||||
|  |           - name: cpiCredentialsId | ||||||
|  |             type: secret | ||||||
|  |             param: username | ||||||
|  |       - name: password | ||||||
|  |         type: string | ||||||
|  |         description: Password to authenticate to the SAP Cloud Platform Integration Service | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
|  |         secret: true | ||||||
|  |         resourceRef: | ||||||
|  |           - name: cpiCredentialsId | ||||||
|  |             type: secret | ||||||
|  |             param: password | ||||||
|  |       - name: integrationFlowId | ||||||
|  |         type: string | ||||||
|  |         description: Specifies the ID of the Integration Flow artifact | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
|  |       - name: integrationFlowVersion | ||||||
|  |         type: string | ||||||
|  |         description: Specifies the version of the Integration Flow artifact | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
|  |       - name: platform | ||||||
|  |         type: string | ||||||
|  |         description: Specifies the running platform of the SAP Cloud platform integraion service | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: false | ||||||
|  |       - name: host | ||||||
|  |         type: string | ||||||
|  |         description: Specifies the protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`. | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
|  |       - name: oAuthTokenProviderUrl | ||||||
|  |         type: string | ||||||
|  |         description: Specifies the oAuth Provider protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`. | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
|  |       - name: parameterKey | ||||||
|  |         type: string | ||||||
|  |         description: Specifies the externalized parameter name. | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
|  |       - name: parameterValue | ||||||
|  |         type: string | ||||||
|  |         description: Specifies the externalized parameter value. | ||||||
|  |         scope: | ||||||
|  |           - PARAMETERS | ||||||
|  |           - STAGES | ||||||
|  |           - STEPS | ||||||
|  |         mandatory: true | ||||||
| @@ -170,9 +170,9 @@ public class CommonStepsTest extends BasePiperTest{ | |||||||
|         'kanikoExecute', //implementing new golang pattern without fields |         'kanikoExecute', //implementing new golang pattern without fields | ||||||
|         'gitopsUpdateDeployment', //implementing new golang pattern without fields |         'gitopsUpdateDeployment', //implementing new golang pattern without fields | ||||||
|         'vaultRotateSecretId', //implementing new golang pattern without fields |         'vaultRotateSecretId', //implementing new golang pattern without fields | ||||||
|         'deployIntegrationArtifact', //implementing new golang pattern without fields |  | ||||||
|         'uiVeri5ExecuteTests', //implementing new golang pattern without fields |         'uiVeri5ExecuteTests', //implementing new golang pattern without fields | ||||||
|         'integrationArtifactDeploy' //implementing new golang pattern without fields |         'integrationArtifactDeploy', //implementing new golang pattern without fields | ||||||
|  |         'integrationArtifactUpdateConfiguration', //implementing new golang pattern without fields | ||||||
|     ] |     ] | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								vars/integrationArtifactUpdateConfiguration.groovy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vars/integrationArtifactUpdateConfiguration.groovy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | import groovy.transform.Field | ||||||
|  |  | ||||||
|  | @Field String STEP_NAME = getClass().getName() | ||||||
|  | @Field String METADATA_FILE = 'metadata/integrationArtifactUpdateConfiguration.yaml' | ||||||
|  |  | ||||||
|  | void call(Map parameters = [:]) { | ||||||
|  |     List credentials = [ | ||||||
|  |         [type: 'usernamePassword', id: 'cpiCredentialsId', env: ['PIPER_username', 'PIPER_password']] | ||||||
|  |     ] | ||||||
|  |     piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials) | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user