2019-10-24 10:59:58 +02:00
package cmd
import (
2019-10-25 14:58:59 +02:00
"encoding/json"
2019-10-24 10:59:58 +02:00
"fmt"
"io"
"os"
2020-02-06 10:08:15 +02:00
"path/filepath"
2020-04-17 10:29:18 +02:00
"reflect"
2020-07-29 09:22:10 +02:00
"strconv"
2020-02-06 10:08:15 +02:00
"strings"
2019-10-24 10:59:58 +02:00
2019-10-25 14:58:59 +02:00
"github.com/SAP/jenkins-library/pkg/config"
2019-11-11 10:52:44 +02:00
"github.com/SAP/jenkins-library/pkg/log"
2021-09-29 08:31:45 +02:00
"github.com/SAP/jenkins-library/pkg/orchestrator"
2019-11-11 10:52:44 +02:00
"github.com/SAP/jenkins-library/pkg/piperutils"
2019-10-25 14:58:59 +02:00
"github.com/pkg/errors"
2019-10-24 10:59:58 +02:00
"github.com/spf13/cobra"
)
2019-11-06 17:22:50 +02:00
// GeneralConfigOptions contains all global configuration options for piper binary
type GeneralConfigOptions struct {
2021-07-08 15:26:07 +02:00
GitHubAccessTokens map [ string ] string // map of tokens with url as key in order to maintain url-specific tokens
2020-05-14 10:50:58 +02:00
CorrelationID string
CustomConfig string
2021-07-08 15:26:07 +02:00
GitHubTokens [ ] string // list of entries in form of <server>:<token> to allow token authentication for downloading config / defaults
2020-05-14 10:50:58 +02:00
DefaultConfig [ ] string //ordered list of Piper default configurations. Can be filePath or ENV containing JSON in format 'ENV:MY_ENV_VAR'
IgnoreCustomDefaults bool
ParametersJSON string
EnvRootPath string
NoTelemetry bool
StageName string
StepConfigJSON string
StepMetadata string //metadata to be considered, can be filePath or ENV containing JSON in format 'ENV:MY_ENV_VAR'
StepName string
Verbose bool
LogFormat string
2020-09-16 14:50:09 +02:00
VaultRoleID string
VaultRoleSecretID string
2021-02-15 10:48:51 +02:00
VaultToken string
VaultServerURL string
VaultNamespace string
VaultPath string
2020-05-14 10:50:58 +02:00
HookConfig HookConfiguration
2021-08-12 14:54:46 +02:00
MetaDataResolver func ( ) map [ string ] config . StepData
2021-12-15 16:07:47 +02:00
GCPJsonKeyFilePath string
GCSFolderPath string
GCSBucketId string
GCSSubFolder string
2020-05-05 08:36:24 +02:00
}
2021-05-17 12:14:04 +02:00
// HookConfiguration contains the configuration for supported hooks, so far Sentry and Splunk are supported.
2020-05-05 08:36:24 +02:00
type HookConfiguration struct {
SentryConfig SentryConfiguration ` json:"sentry,omitempty" `
2021-05-17 12:14:04 +02:00
SplunkConfig SplunkConfiguration ` json:"splunk,omitempty" `
2020-05-05 08:36:24 +02:00
}
// SentryConfiguration defines the configuration options for the Sentry logging system
type SentryConfiguration struct {
Dsn string ` json:"dsn,omitempty" `
2019-10-24 10:59:58 +02:00
}
2021-05-17 12:14:04 +02:00
// SplunkConfiguration defines the configuration options for the Splunk logging system
type SplunkConfiguration struct {
Dsn string ` json:"dsn,omitempty" `
Token string ` json:"token,omitempty" `
Index string ` json:"index,omitempty" `
SendLogs bool ` json:"sendLogs" `
}
2019-10-24 10:59:58 +02:00
var rootCmd = & cobra . Command {
Use : "piper" ,
Short : "Executes CI/CD steps from project 'Piper' " ,
Long : `
2020-04-24 18:29:30 +02:00
This project ' Piper ' binary provides a CI / CD step library .
2019-10-24 10:59:58 +02:00
It contains many steps which can be used within CI / CD systems as well as directly on e . g . a developer ' s machine .
` ,
}
2019-11-06 15:07:41 +02:00
// GeneralConfig contains global configuration flags for piper binary
2019-11-06 17:22:50 +02:00
var GeneralConfig GeneralConfigOptions
2019-10-24 10:59:58 +02:00
// Execute is the starting point of the piper command line tool
func Execute ( ) {
2020-04-03 16:34:40 +02:00
rootCmd . AddCommand ( ArtifactPrepareVersionCommand ( ) )
2019-10-24 10:59:58 +02:00
rootCmd . AddCommand ( ConfigCommand ( ) )
2020-05-18 08:55:25 +02:00
rootCmd . AddCommand ( ContainerSaveImageCommand ( ) )
2020-09-07 15:22:01 +02:00
rootCmd . AddCommand ( CommandLineCompletionCommand ( ) )
2019-10-31 14:57:29 +02:00
rootCmd . AddCommand ( VersionCommand ( ) )
2019-12-13 11:55:45 +02:00
rootCmd . AddCommand ( DetectExecuteScanCommand ( ) )
2020-11-16 16:14:54 +02:00
rootCmd . AddCommand ( HadolintExecuteCommand ( ) )
2019-10-30 10:20:25 +02:00
rootCmd . AddCommand ( KarmaExecuteTestsCommand ( ) )
2021-01-28 12:31:24 +02:00
rootCmd . AddCommand ( UiVeri5ExecuteTestsCommand ( ) )
2020-03-23 11:38:31 +02:00
rootCmd . AddCommand ( SonarExecuteScanCommand ( ) )
2020-01-24 15:30:27 +02:00
rootCmd . AddCommand ( KubernetesDeployCommand ( ) )
2019-12-05 15:22:38 +02:00
rootCmd . AddCommand ( XsDeployCommand ( ) )
2020-09-14 12:05:12 +02:00
rootCmd . AddCommand ( GithubCheckBranchProtectionCommand ( ) )
2020-12-21 17:21:07 +02:00
rootCmd . AddCommand ( GithubCommentIssueCommand ( ) )
2020-12-21 18:13:16 +02:00
rootCmd . AddCommand ( GithubCreateIssueCommand ( ) )
2020-09-11 18:56:51 +02:00
rootCmd . AddCommand ( GithubCreatePullRequestCommand ( ) )
2020-09-14 12:05:12 +02:00
rootCmd . AddCommand ( GithubPublishReleaseCommand ( ) )
2020-09-14 18:08:24 +02:00
rootCmd . AddCommand ( GithubSetCommitStatusCommand ( ) )
2020-10-20 09:05:17 +02:00
rootCmd . AddCommand ( GitopsUpdateDeploymentCommand ( ) )
2020-02-10 15:53:12 +02:00
rootCmd . AddCommand ( CloudFoundryDeleteServiceCommand ( ) )
2020-02-04 12:43:27 +02:00
rootCmd . AddCommand ( AbapEnvironmentPullGitRepoCommand ( ) )
2020-08-21 14:49:48 +02:00
rootCmd . AddCommand ( AbapEnvironmentCloneGitRepoCommand ( ) )
2020-08-04 17:52:28 +02:00
rootCmd . AddCommand ( AbapEnvironmentCheckoutBranchCommand ( ) )
2020-11-03 13:02:13 +02:00
rootCmd . AddCommand ( AbapEnvironmentCreateSystemCommand ( ) )
2020-01-28 00:40:53 +02:00
rootCmd . AddCommand ( CheckmarxExecuteScanCommand ( ) )
2020-05-25 19:48:59 +02:00
rootCmd . AddCommand ( FortifyExecuteScanCommand ( ) )
2020-02-25 15:33:34 +02:00
rootCmd . AddCommand ( MtaBuildCommand ( ) )
2020-02-06 17:16:34 +02:00
rootCmd . AddCommand ( ProtecodeExecuteScanCommand ( ) )
2020-02-28 14:09:46 +02:00
rootCmd . AddCommand ( MavenExecuteCommand ( ) )
2020-04-01 11:45:31 +02:00
rootCmd . AddCommand ( CloudFoundryCreateServiceKeyCommand ( ) )
2020-03-13 14:32:37 +02:00
rootCmd . AddCommand ( MavenBuildCommand ( ) )
2020-07-29 19:51:27 +02:00
rootCmd . AddCommand ( MavenExecuteIntegrationCommand ( ) )
2020-03-12 16:45:57 +02:00
rootCmd . AddCommand ( MavenExecuteStaticCodeChecksCommand ( ) )
2020-03-20 19:20:52 +02:00
rootCmd . AddCommand ( NexusUploadCommand ( ) )
2020-05-13 14:51:48 +02:00
rootCmd . AddCommand ( AbapEnvironmentRunATCCheckCommand ( ) )
2020-04-24 18:29:30 +02:00
rootCmd . AddCommand ( NpmExecuteScriptsCommand ( ) )
2020-06-22 10:12:28 +02:00
rootCmd . AddCommand ( NpmExecuteLintCommand ( ) )
2020-04-24 15:31:41 +02:00
rootCmd . AddCommand ( GctsCreateRepositoryCommand ( ) )
2020-07-14 10:58:57 +02:00
rootCmd . AddCommand ( GctsExecuteABAPUnitTestsCommand ( ) )
2020-05-18 21:39:35 +02:00
rootCmd . AddCommand ( GctsDeployCommand ( ) )
2020-07-27 08:30:02 +02:00
rootCmd . AddCommand ( MalwareExecuteScanCommand ( ) )
2020-08-19 10:17:27 +02:00
rootCmd . AddCommand ( CloudFoundryCreateServiceCommand ( ) )
2020-07-31 12:38:00 +02:00
rootCmd . AddCommand ( CloudFoundryDeployCommand ( ) )
2020-07-27 11:13:13 +02:00
rootCmd . AddCommand ( GctsRollbackCommand ( ) )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-07-01 07:54:13 +02:00
rootCmd . AddCommand ( WhitesourceExecuteScanCommand ( ) )
2020-06-18 07:45:22 +02:00
rootCmd . AddCommand ( GctsCloneRepositoryCommand ( ) )
2020-06-18 14:50:46 +02:00
rootCmd . AddCommand ( JsonApplyPatchCommand ( ) )
2020-07-10 08:07:59 +02:00
rootCmd . AddCommand ( KanikoExecuteCommand ( ) )
2021-08-18 12:10:55 +02:00
rootCmd . AddCommand ( CnbBuildCommand ( ) )
2021-12-06 15:43:37 +02:00
rootCmd . AddCommand ( AbapEnvironmentBuildCommand ( ) )
2020-08-27 07:54:03 +02:00
rootCmd . AddCommand ( AbapEnvironmentAssemblePackagesCommand ( ) )
2020-09-17 11:01:19 +02:00
rootCmd . AddCommand ( AbapAddonAssemblyKitCheckCVsCommand ( ) )
2020-09-17 15:56:14 +02:00
rootCmd . AddCommand ( AbapAddonAssemblyKitCheckPVCommand ( ) )
2020-09-18 11:18:51 +02:00
rootCmd . AddCommand ( AbapAddonAssemblyKitCreateTargetVectorCommand ( ) )
2020-09-18 10:24:46 +02:00
rootCmd . AddCommand ( AbapAddonAssemblyKitPublishTargetVectorCommand ( ) )
2020-09-18 14:07:42 +02:00
rootCmd . AddCommand ( AbapAddonAssemblyKitRegisterPackagesCommand ( ) )
2020-09-18 16:40:49 +02:00
rootCmd . AddCommand ( AbapAddonAssemblyKitReleasePackagesCommand ( ) )
2020-09-18 17:27:04 +02:00
rootCmd . AddCommand ( AbapAddonAssemblyKitReserveNextPackagesCommand ( ) )
2020-09-24 11:30:25 +02:00
rootCmd . AddCommand ( CloudFoundryCreateSpaceCommand ( ) )
rootCmd . AddCommand ( CloudFoundryDeleteSpaceCommand ( ) )
2020-11-17 14:49:31 +02:00
rootCmd . AddCommand ( VaultRotateSecretIdCommand ( ) )
2021-10-04 13:08:34 +02:00
rootCmd . AddCommand ( IsChangeInDevelopmentCommand ( ) )
2021-01-13 17:14:56 +02:00
rootCmd . AddCommand ( TransportRequestUploadCTSCommand ( ) )
2021-06-14 12:36:18 +02:00
rootCmd . AddCommand ( TransportRequestUploadRFCCommand ( ) )
2021-03-17 09:08:33 +02:00
rootCmd . AddCommand ( NewmanExecuteCommand ( ) )
2021-01-22 16:55:50 +02:00
rootCmd . AddCommand ( IntegrationArtifactDeployCommand ( ) )
2021-02-19 14:07:18 +02:00
rootCmd . AddCommand ( TransportRequestUploadSOLMANCommand ( ) )
2021-01-29 10:46:47 +02:00
rootCmd . AddCommand ( IntegrationArtifactUpdateConfigurationCommand ( ) )
2021-02-04 11:50:15 +02:00
rootCmd . AddCommand ( IntegrationArtifactGetMplStatusCommand ( ) )
2021-03-11 13:03:32 +02:00
rootCmd . AddCommand ( IntegrationArtifactGetServiceEndpointCommand ( ) )
2021-02-10 18:08:23 +02:00
rootCmd . AddCommand ( IntegrationArtifactDownloadCommand ( ) )
2021-02-10 12:33:10 +02:00
rootCmd . AddCommand ( AbapEnvironmentAssembleConfirmCommand ( ) )
2021-02-17 10:59:56 +02:00
rootCmd . AddCommand ( IntegrationArtifactUploadCommand ( ) )
2021-06-29 14:50:19 +02:00
rootCmd . AddCommand ( IntegrationArtifactTriggerIntegrationTestCommand ( ) )
2021-08-02 16:27:16 +02:00
rootCmd . AddCommand ( IntegrationArtifactUnDeployCommand ( ) )
2021-08-12 09:11:02 +02:00
rootCmd . AddCommand ( IntegrationArtifactResourceCommand ( ) )
2021-03-29 16:22:23 +02:00
rootCmd . AddCommand ( TerraformExecuteCommand ( ) )
2021-03-25 09:18:30 +02:00
rootCmd . AddCommand ( ContainerExecuteStructureTestsCommand ( ) )
2021-06-01 13:15:10 +02:00
rootCmd . AddCommand ( GaugeExecuteTestsCommand ( ) )
2021-04-29 16:50:23 +02:00
rootCmd . AddCommand ( BatsExecuteTestsCommand ( ) )
2021-04-15 07:45:06 +02:00
rootCmd . AddCommand ( PipelineCreateScanSummaryCommand ( ) )
2021-05-21 08:54:43 +02:00
rootCmd . AddCommand ( TransportRequestDocIDFromGitCommand ( ) )
rootCmd . AddCommand ( TransportRequestReqIDFromGitCommand ( ) )
2021-06-11 16:17:40 +02:00
rootCmd . AddCommand ( WritePipelineEnv ( ) )
rootCmd . AddCommand ( ReadPipelineEnv ( ) )
2021-06-30 11:18:49 +02:00
rootCmd . AddCommand ( InfluxWriteDataCommand ( ) )
2021-09-20 11:14:13 +02:00
rootCmd . AddCommand ( AbapEnvironmentRunAUnitTestCommand ( ) )
2021-07-26 07:47:43 +02:00
rootCmd . AddCommand ( CheckStepActiveCommand ( ) )
2021-12-06 17:17:59 +02:00
rootCmd . AddCommand ( GolangBuildCommand ( ) )
2021-11-19 11:05:39 +02:00
rootCmd . AddCommand ( ShellExecuteCommand ( ) )
2021-11-02 11:30:08 +02:00
rootCmd . AddCommand ( ApiProxyDownloadCommand ( ) )
2021-11-15 14:48:14 +02:00
rootCmd . AddCommand ( ApiKeyValueMapDownloadCommand ( ) )
2019-10-25 14:58:59 +02:00
addRootFlags ( rootCmd )
2021-07-08 15:26:07 +02:00
2019-10-25 14:58:59 +02:00
if err := rootCmd . Execute ( ) ; err != nil {
2020-09-22 07:49:34 +02:00
log . SetErrorCategory ( log . ErrorConfiguration )
2020-06-24 10:04:05 +02:00
log . Entry ( ) . WithError ( err ) . Fatal ( "configuration error" )
2019-10-25 14:58:59 +02:00
}
}
func addRootFlags ( rootCmd * cobra . Command ) {
Changes for Pipeline Reporting (#3213)
* Adds GetLog() function to orchestrator
* Fixes BUILD_NUMBER env variable
* Fixes correct env var for JENKINS_HOME
* Adds getEnv to read env variables with default value, adds test for jenkins GetLog() implementation
* Adds possibility to read errorJsons; updates splunk package for log files (WIP)
* Uncommenting dev code
* Adds GetLog() function to orchestrator
* Fixes BUILD_NUMBER env variable
* Fixes correct env var for JENKINS_HOME
* Adds getEnv to read env variables with default value, adds test for jenkins GetLog() implementation
* Adds possibility to read errorJsons; updates splunk package for log files (WIP)
* Uncommenting dev code
* Adds GetRequest function which holds the response in memory (not saved to disk)
* Implements GetLog() function for ADO, adds function to read PipelineRuntime
* PAT has been revoked
* Changes http package, s.t. if password only is required basic auth works too
* Adds env variable for azure token, error handling in case of unauthenticated/nil response
* Adds logging output in case env variable can not be read and fallback variable needs to be used
* Adds usage of environment variables for auth, uses jenkins api
* Adds init functionality for orchestrators, updates GetLog() and GetPipelineStartTime() function
* Adds initaliziation function for orchestrator authetnication
* Adds settings struct for orchestrator authentication
* Adds function to whole logfile to Splunk
* Struct for pipeline related telemetry information
* Increase messagebatch size to 10k
* Changes splunk package to a pointer based implementation, updates generated files and corresponding template and tests for splunk
* Changes telemetry package to pointer based implementation to have multiple telemetry objects, adjusted tests and splunk implementation
* Changes content type to txt
* Send telemetry independent of logfiles, increases amount of messages per file
* Adds JobURL for orchestrators and UnknownOrchestrator as fallback
* telemetry makes use of orchestrator specific information
* Adds orchestrator independent correlationID
* Adds custom fields for pipeline status
* go fmt
* Removes env var test - no env variables are read anymore
* Use UnknownOrchestratorConfigProvider in case the orchestrator can not be initalized
* Removes Custom fields from telemetry as these can not be reflected in SWA
* Adds custom telemetry information (piperHash,..) to each step telemetry information
* Removes falltrough in case no orchestrator has been found
* Updates tests for orchestrator package
* Adds orchestrator import in generated files
* Updates generator files for internal library
* Adds orchestrator telemetry information to steps
* Updates generated files, fatalHook writes to cpe
* Go generate from master, go fmt
* Adds Custom Data field LastErrorCode
* Removes GetLog() test
* Update init_unix.go
* Update docker_integration_test_executor.go
* Update integration_api_cli_test.go
* Reverts go1.17 fmt formatting
* Reverts go1.17 fmt formatting
* Reverts go1.17 fmt formatting
* Renames customTelemetryData to stepTelemetryData
* Adjustments to orchestrator-package, cleanup, adds JobName
* Adjusts commonPipelineEnvironment path
* Adds pipelineTelemetry struct to telemetry package, removes pipeline telemetry structs from splunk package
* Go fmt
* Changes path for errorDetails, adds debug information
* Removes custom fields from step, adds orchestrator, commithash to baseMetadata
* Adjusts tests for telemetry package
* Adds tests for orchestrator
* Updates generated files, initalization of splunk client only if its available in the config
* Fixes typo in helper go
* Update pkg/http/downloader.go
* Update pkg/http/downloader.go
* Update pkg/log/fatalHook.go
* Update fatalHook.go
* Update pkg/splunk/splunk.go
* Update pkg/telemetry/data.go
* Adds GetBuildStatus() and GetAPIInformation() to orchestrators
* error formatting
* Bugfix: dont send telemetry data if disabled, adjusts test
* go fmt
* Use correct error handling
* Update pkg/telemetry/telemetry.go
* Fixes telemetry disabled in the tests
* Fixes http tests
* Log fatal errors to logFile
* Adds CustomReportingConfig to hooks
* Cleanup comments in splunk package
* Adds possibility to send telemetry to custom endpoint
* Adds debug output for the payload
* Debug output for the payload as a string
* Adds test cases for changes in telemetry package
* go fmt
* Adds generated files for new step
* Reverts changes for http tests, causing problems with go1.15, changes need to be applied for newer go version >=1.17
* Adjusts test for sonarExecuteScan
* Adjusts test for sonarExecuteScan
* Adds explanation for customreportingConfig
* Makes disableing of customSend more obvious
* Adds custom step reporting to each step, updates generated files, adjusts helper testdata
* fixes unit test wrong usage of logging
* Send pipeline data altough there has been no error, adjust test cases
* Reverts changes for customReporting
* Updates generated files, removes customReporting
* Removes writing errorDetails to CPE
* Reverts usage of customreporting
* go fmt
* reverts changes in http_test
* reverts changes in http_test
* Skips integration cnb test
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-11-18 18:50:03 +02:00
var provider orchestrator . OrchestratorSpecificConfigProviding
var err error
2019-10-25 14:58:59 +02:00
Changes for Pipeline Reporting (#3213)
* Adds GetLog() function to orchestrator
* Fixes BUILD_NUMBER env variable
* Fixes correct env var for JENKINS_HOME
* Adds getEnv to read env variables with default value, adds test for jenkins GetLog() implementation
* Adds possibility to read errorJsons; updates splunk package for log files (WIP)
* Uncommenting dev code
* Adds GetLog() function to orchestrator
* Fixes BUILD_NUMBER env variable
* Fixes correct env var for JENKINS_HOME
* Adds getEnv to read env variables with default value, adds test for jenkins GetLog() implementation
* Adds possibility to read errorJsons; updates splunk package for log files (WIP)
* Uncommenting dev code
* Adds GetRequest function which holds the response in memory (not saved to disk)
* Implements GetLog() function for ADO, adds function to read PipelineRuntime
* PAT has been revoked
* Changes http package, s.t. if password only is required basic auth works too
* Adds env variable for azure token, error handling in case of unauthenticated/nil response
* Adds logging output in case env variable can not be read and fallback variable needs to be used
* Adds usage of environment variables for auth, uses jenkins api
* Adds init functionality for orchestrators, updates GetLog() and GetPipelineStartTime() function
* Adds initaliziation function for orchestrator authetnication
* Adds settings struct for orchestrator authentication
* Adds function to whole logfile to Splunk
* Struct for pipeline related telemetry information
* Increase messagebatch size to 10k
* Changes splunk package to a pointer based implementation, updates generated files and corresponding template and tests for splunk
* Changes telemetry package to pointer based implementation to have multiple telemetry objects, adjusted tests and splunk implementation
* Changes content type to txt
* Send telemetry independent of logfiles, increases amount of messages per file
* Adds JobURL for orchestrators and UnknownOrchestrator as fallback
* telemetry makes use of orchestrator specific information
* Adds orchestrator independent correlationID
* Adds custom fields for pipeline status
* go fmt
* Removes env var test - no env variables are read anymore
* Use UnknownOrchestratorConfigProvider in case the orchestrator can not be initalized
* Removes Custom fields from telemetry as these can not be reflected in SWA
* Adds custom telemetry information (piperHash,..) to each step telemetry information
* Removes falltrough in case no orchestrator has been found
* Updates tests for orchestrator package
* Adds orchestrator import in generated files
* Updates generator files for internal library
* Adds orchestrator telemetry information to steps
* Updates generated files, fatalHook writes to cpe
* Go generate from master, go fmt
* Adds Custom Data field LastErrorCode
* Removes GetLog() test
* Update init_unix.go
* Update docker_integration_test_executor.go
* Update integration_api_cli_test.go
* Reverts go1.17 fmt formatting
* Reverts go1.17 fmt formatting
* Reverts go1.17 fmt formatting
* Renames customTelemetryData to stepTelemetryData
* Adjustments to orchestrator-package, cleanup, adds JobName
* Adjusts commonPipelineEnvironment path
* Adds pipelineTelemetry struct to telemetry package, removes pipeline telemetry structs from splunk package
* Go fmt
* Changes path for errorDetails, adds debug information
* Removes custom fields from step, adds orchestrator, commithash to baseMetadata
* Adjusts tests for telemetry package
* Adds tests for orchestrator
* Updates generated files, initalization of splunk client only if its available in the config
* Fixes typo in helper go
* Update pkg/http/downloader.go
* Update pkg/http/downloader.go
* Update pkg/log/fatalHook.go
* Update fatalHook.go
* Update pkg/splunk/splunk.go
* Update pkg/telemetry/data.go
* Adds GetBuildStatus() and GetAPIInformation() to orchestrators
* error formatting
* Bugfix: dont send telemetry data if disabled, adjusts test
* go fmt
* Use correct error handling
* Update pkg/telemetry/telemetry.go
* Fixes telemetry disabled in the tests
* Fixes http tests
* Log fatal errors to logFile
* Adds CustomReportingConfig to hooks
* Cleanup comments in splunk package
* Adds possibility to send telemetry to custom endpoint
* Adds debug output for the payload
* Debug output for the payload as a string
* Adds test cases for changes in telemetry package
* go fmt
* Adds generated files for new step
* Reverts changes for http tests, causing problems with go1.15, changes need to be applied for newer go version >=1.17
* Adjusts test for sonarExecuteScan
* Adjusts test for sonarExecuteScan
* Adds explanation for customreportingConfig
* Makes disableing of customSend more obvious
* Adds custom step reporting to each step, updates generated files, adjusts helper testdata
* fixes unit test wrong usage of logging
* Send pipeline data altough there has been no error, adjust test cases
* Reverts changes for customReporting
* Updates generated files, removes customReporting
* Removes writing errorDetails to CPE
* Reverts usage of customreporting
* go fmt
* reverts changes in http_test
* reverts changes in http_test
* Skips integration cnb test
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-11-18 18:50:03 +02:00
provider , err = orchestrator . NewOrchestratorSpecificConfigProvider ( )
if err != nil {
log . Entry ( ) . Error ( err )
provider = & orchestrator . UnknownOrchestratorConfigProvider { }
}
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . CorrelationID , "correlationID" , provider . GetBuildUrl ( ) , "ID for unique identification of a pipeline run" )
2019-11-06 17:22:50 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . CustomConfig , "customConfig" , ".pipeline/config.yml" , "Path to the pipeline configuration file" )
2021-07-16 08:59:53 +02:00
rootCmd . PersistentFlags ( ) . StringSliceVar ( & GeneralConfig . GitHubTokens , "gitHubTokens" , AccessTokensFromEnvJSON ( os . Getenv ( "PIPER_gitHubTokens" ) ) , "List of entries in form of <hostname>:<token> to allow GitHub token authentication for downloading config / defaults" )
2019-11-21 17:09:57 +02:00
rootCmd . PersistentFlags ( ) . StringSliceVar ( & GeneralConfig . DefaultConfig , "defaultConfig" , [ ] string { ".pipeline/defaults.yaml" } , "Default configurations, passed as path to yaml file" )
2020-05-14 10:50:58 +02:00
rootCmd . PersistentFlags ( ) . BoolVar ( & GeneralConfig . IgnoreCustomDefaults , "ignoreCustomDefaults" , false , "Disables evaluation of the parameter 'customDefaults' in the pipeline configuration file" )
2019-11-06 17:22:50 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . ParametersJSON , "parametersJSON" , os . Getenv ( "PIPER_parametersJSON" ) , "Parameters to be considered in JSON format" )
2020-01-15 13:16:25 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . EnvRootPath , "envRootPath" , ".pipeline" , "Root path to Piper pipeline shared environments" )
2020-08-13 17:55:12 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . StageName , "stageName" , "" , "Name of the stage for which configuration should be included" )
2019-11-06 17:22:50 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . StepConfigJSON , "stepConfigJSON" , os . Getenv ( "PIPER_stepConfigJSON" ) , "Step configuration in JSON format" )
2020-01-29 14:17:54 +02:00
rootCmd . PersistentFlags ( ) . BoolVar ( & GeneralConfig . NoTelemetry , "noTelemetry" , false , "Disables telemetry reporting" )
2019-11-06 17:22:50 +02:00
rootCmd . PersistentFlags ( ) . BoolVarP ( & GeneralConfig . Verbose , "verbose" , "v" , false , "verbose output" )
2020-05-06 12:17:56 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . LogFormat , "logFormat" , "default" , "Log format to use. Options: default, timestamp, plain, full." )
2021-02-15 10:48:51 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . VaultServerURL , "vaultServerUrl" , "" , "The vault server which should be used to fetch credentials" )
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . VaultNamespace , "vaultNamespace" , "" , "The vault namespace which should be used to fetch credentials" )
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . VaultPath , "vaultPath" , "" , "The path which should be used to fetch credentials" )
2021-12-15 16:07:47 +02:00
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . GCPJsonKeyFilePath , "gcpJsonKeyFilePath" , "" , "File path to Google Cloud Platform JSON key file" )
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . GCSFolderPath , "gcsFolderPath" , "" , "GCS folder path. One of the components of GCS target folder" )
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . GCSBucketId , "gcsBucketId" , "" , "Bucket name for Google Cloud Storage" )
rootCmd . PersistentFlags ( ) . StringVar ( & GeneralConfig . GCSSubFolder , "gcsSubFolder" , "" , "Used to logically separate results of the same step result type" )
2019-10-24 10:59:58 +02:00
2019-10-25 14:58:59 +02:00
}
2021-07-08 15:26:07 +02:00
// ResolveAccessTokens reads a list of tokens in format host:token passed via command line
// and transfers this into a map as a more consumable format.
func ResolveAccessTokens ( tokenList [ ] string ) map [ string ] string {
tokenMap := map [ string ] string { }
for _ , tokenEntry := range tokenList {
log . Entry ( ) . Debugf ( "processing token %v" , tokenEntry )
parts := strings . Split ( tokenEntry , ":" )
if len ( parts ) != 2 {
log . Entry ( ) . Warningf ( "wrong format for access token %v" , tokenEntry )
} else {
tokenMap [ parts [ 0 ] ] = parts [ 1 ]
}
}
return tokenMap
}
2021-07-16 08:59:53 +02:00
// AccessTokensFromEnvJSON resolves access tokens when passed as JSON in an environment variable
func AccessTokensFromEnvJSON ( env string ) [ ] string {
2021-07-08 15:26:07 +02:00
accessTokens := [ ] string { }
if len ( env ) == 0 {
return accessTokens
}
err := json . Unmarshal ( [ ] byte ( env ) , & accessTokens )
if err != nil {
log . Entry ( ) . Infof ( "Token json '%v' has wrong format." , env )
}
return accessTokens
}
2020-08-13 17:55:12 +02:00
// initStageName initializes GeneralConfig.StageName from either GeneralConfig.ParametersJSON
2021-09-29 08:31:45 +02:00
// or the environment variable (orchestrator specific), unless it has been provided as command line option.
2020-08-13 17:55:12 +02:00
// Log output needs to be suppressed via outputToLog by the getConfig step.
func initStageName ( outputToLog bool ) {
var stageNameSource string
if outputToLog {
defer func ( ) {
log . Entry ( ) . Infof ( "Using stageName '%s' from %s" , GeneralConfig . StageName , stageNameSource )
} ( )
}
if GeneralConfig . StageName != "" {
// Means it was given as command line argument and has the highest precedence
stageNameSource = "command line arguments"
return
}
// Use stageName from ENV as fall-back, for when extracting it from parametersJSON fails below
2021-09-29 08:31:45 +02:00
provider , err := orchestrator . NewOrchestratorSpecificConfigProvider ( )
if err != nil {
log . Entry ( ) . WithError ( err ) . Warning ( "Cannot infer stage name from CI environment" )
} else {
stageNameSource = "env variable"
GeneralConfig . StageName = provider . GetStageName ( )
}
2020-08-13 17:55:12 +02:00
if len ( GeneralConfig . ParametersJSON ) == 0 {
return
}
var params map [ string ] interface { }
2021-09-29 08:31:45 +02:00
err = json . Unmarshal ( [ ] byte ( GeneralConfig . ParametersJSON ) , & params )
2020-08-13 17:55:12 +02:00
if err != nil {
if outputToLog {
log . Entry ( ) . Infof ( "Failed to extract 'stageName' from parametersJSON: %v" , err )
}
return
}
stageName , hasKey := params [ "stageName" ]
if ! hasKey {
return
}
if stageNameString , ok := stageName . ( string ) ; ok && stageNameString != "" {
stageNameSource = "parametersJSON"
GeneralConfig . StageName = stageNameString
}
}
2019-10-25 14:58:59 +02:00
// PrepareConfig reads step configuration from various sources and merges it (defaults, config file, flags, ...)
2021-07-08 15:26:07 +02:00
func PrepareConfig ( cmd * cobra . Command , metadata * config . StepData , stepName string , options interface { } , openFile func ( s string , t map [ string ] string ) ( io . ReadCloser , error ) ) error {
2019-10-25 14:58:59 +02:00
2020-08-13 17:55:12 +02:00
log . SetFormatter ( GeneralConfig . LogFormat )
initStageName ( true )
2019-10-25 14:58:59 +02:00
filters := metadata . GetParameterFilters ( )
2020-01-29 14:17:54 +02:00
// add telemetry parameter "collectTelemetryData" to ALL, GENERAL and PARAMETER filters
filters . All = append ( filters . All , "collectTelemetryData" )
filters . General = append ( filters . General , "collectTelemetryData" )
filters . Parameters = append ( filters . Parameters , "collectTelemetryData" )
2021-12-15 16:07:47 +02:00
envParams := metadata . GetResourceParameters ( GeneralConfig . EnvRootPath , "commonPipelineEnvironment" )
reportingEnvParams := config . ReportingParameters . GetResourceParameters ( GeneralConfig . EnvRootPath , "commonPipelineEnvironment" )
resourceParams := mergeResourceParameters ( envParams , reportingEnvParams )
2019-10-25 14:58:59 +02:00
flagValues := config . AvailableFlagValues ( cmd , & filters )
var myConfig config . Config
var stepConfig config . StepConfig
2020-09-16 14:50:09 +02:00
// add vault credentials so that configuration can be fetched from vault
if GeneralConfig . VaultRoleID == "" {
2020-10-13 14:14:47 +02:00
GeneralConfig . VaultRoleID = os . Getenv ( "PIPER_vaultAppRoleID" )
2020-09-16 14:50:09 +02:00
}
if GeneralConfig . VaultRoleSecretID == "" {
2020-10-13 14:14:47 +02:00
GeneralConfig . VaultRoleSecretID = os . Getenv ( "PIPER_vaultAppRoleSecretID" )
2020-09-16 14:50:09 +02:00
}
2021-02-15 10:48:51 +02:00
if GeneralConfig . VaultToken == "" {
GeneralConfig . VaultToken = os . Getenv ( "PIPER_vaultToken" )
}
myConfig . SetVaultCredentials ( GeneralConfig . VaultRoleID , GeneralConfig . VaultRoleSecretID , GeneralConfig . VaultToken )
2020-09-16 14:50:09 +02:00
2019-11-06 17:22:50 +02:00
if len ( GeneralConfig . StepConfigJSON ) != 0 {
2019-10-25 14:58:59 +02:00
// ignore config & defaults in favor of passed stepConfigJSON
2019-11-06 17:22:50 +02:00
stepConfig = config . GetStepConfigWithJSON ( flagValues , GeneralConfig . StepConfigJSON , filters )
2020-06-10 09:39:29 +02:00
log . Entry ( ) . Infof ( "Project config: passed via JSON" )
log . Entry ( ) . Infof ( "Project defaults: passed via JSON" )
2019-10-25 14:58:59 +02:00
} else {
// use config & defaults
2019-11-11 10:52:44 +02:00
var customConfig io . ReadCloser
var err error
2019-10-25 14:58:59 +02:00
//accept that config file and defaults cannot be loaded since both are not mandatory here
2019-12-11 11:13:23 +02:00
{
2020-02-06 10:08:15 +02:00
projectConfigFile := getProjectConfigFile ( GeneralConfig . CustomConfig )
2020-06-10 09:39:29 +02:00
if exists , err := piperutils . FileExists ( projectConfigFile ) ; exists {
log . Entry ( ) . Infof ( "Project config: '%s'" , projectConfigFile )
2021-07-08 15:26:07 +02:00
if customConfig , err = openFile ( projectConfigFile , GeneralConfig . GitHubAccessTokens ) ; err != nil {
2020-03-31 08:47:09 +02:00
return errors . Wrapf ( err , "Cannot read '%s'" , projectConfigFile )
2019-12-11 11:13:23 +02:00
}
} else {
2020-06-10 09:39:29 +02:00
log . Entry ( ) . Infof ( "Project config: NONE ('%s' does not exist)" , projectConfigFile )
2019-12-11 11:13:23 +02:00
customConfig = nil
}
}
2019-10-25 14:58:59 +02:00
var defaultConfig [ ] io . ReadCloser
2020-06-10 09:39:29 +02:00
if len ( GeneralConfig . DefaultConfig ) == 0 {
log . Entry ( ) . Info ( "Project defaults: NONE" )
}
for _ , projectDefaultFile := range GeneralConfig . DefaultConfig {
2021-07-08 15:26:07 +02:00
fc , err := openFile ( projectDefaultFile , GeneralConfig . GitHubAccessTokens )
2020-03-31 08:47:09 +02:00
// only create error for non-default values
2020-06-10 09:39:29 +02:00
if err != nil {
if projectDefaultFile != ".pipeline/defaults.yaml" {
log . Entry ( ) . Infof ( "Project defaults: '%s'" , projectDefaultFile )
return errors . Wrapf ( err , "Cannot read '%s'" , projectDefaultFile )
}
} else {
log . Entry ( ) . Infof ( "Project defaults: '%s'" , projectDefaultFile )
2020-03-31 08:47:09 +02:00
defaultConfig = append ( defaultConfig , fc )
2020-03-30 14:31:24 +02:00
}
2019-10-25 14:58:59 +02:00
}
2021-12-15 16:07:47 +02:00
stepConfig , err = myConfig . GetStepConfig ( flagValues , GeneralConfig . ParametersJSON , customConfig , defaultConfig , GeneralConfig . IgnoreCustomDefaults , filters , * metadata , resourceParams , GeneralConfig . StageName , stepName )
2021-03-23 13:06:23 +02:00
if verbose , ok := stepConfig . Config [ "verbose" ] . ( bool ) ; ok && verbose {
log . SetVerbose ( verbose )
GeneralConfig . Verbose = verbose
} else if ! ok && stepConfig . Config [ "verbose" ] != nil {
log . Entry ( ) . Warnf ( "invalid value for parameter verbose: '%v'" , stepConfig . Config [ "verbose" ] )
}
2019-10-25 14:58:59 +02:00
if err != nil {
return errors . Wrap ( err , "retrieving step configuration failed" )
}
2019-10-24 10:59:58 +02:00
}
2019-10-25 14:58:59 +02:00
2020-01-29 14:17:54 +02:00
if fmt . Sprintf ( "%v" , stepConfig . Config [ "collectTelemetryData" ] ) == "false" {
GeneralConfig . NoTelemetry = true
}
2020-05-06 17:43:32 +02:00
stepConfig . Config = checkTypes ( stepConfig . Config , options )
2019-10-25 14:58:59 +02:00
confJSON , _ := json . Marshal ( stepConfig . Config )
2020-04-01 20:46:33 +02:00
_ = json . Unmarshal ( confJSON , & options )
2019-10-25 14:58:59 +02:00
config . MarkFlagsWithValue ( cmd , stepConfig )
2020-07-28 17:19:33 +02:00
retrieveHookConfig ( stepConfig . HookConfig , & GeneralConfig . HookConfig )
2020-05-05 08:36:24 +02:00
2021-12-15 16:07:47 +02:00
if GeneralConfig . GCPJsonKeyFilePath == "" {
GeneralConfig . GCPJsonKeyFilePath , _ = stepConfig . Config [ "gcpJsonKeyFilePath" ] . ( string )
}
if GeneralConfig . GCSFolderPath == "" {
GeneralConfig . GCSFolderPath , _ = stepConfig . Config [ "gcsFolderPath" ] . ( string )
}
if GeneralConfig . GCSBucketId == "" {
GeneralConfig . GCSBucketId , _ = stepConfig . Config [ "gcsBucketId" ] . ( string )
}
if GeneralConfig . GCSSubFolder == "" {
GeneralConfig . GCSSubFolder , _ = stepConfig . Config [ "gcsSubFolder" ] . ( string )
}
2019-10-25 14:58:59 +02:00
return nil
2019-10-24 10:59:58 +02:00
}
2020-02-06 10:08:15 +02:00
2021-05-17 12:14:04 +02:00
func retrieveHookConfig ( source map [ string ] interface { } , target * HookConfiguration ) {
2020-07-28 17:19:33 +02:00
if source != nil {
log . Entry ( ) . Info ( "Retrieving hook configuration" )
2021-05-17 12:14:04 +02:00
b , err := json . Marshal ( source )
if err != nil {
log . Entry ( ) . Warningf ( "Failed to marshal source hook configuration: %v" , err )
}
err = json . Unmarshal ( b , target )
2020-07-28 17:19:33 +02:00
if err != nil {
log . Entry ( ) . Warningf ( "Failed to retrieve hook configuration: %v" , err )
}
}
}
2020-07-29 09:22:10 +02:00
var errIncompatibleTypes = fmt . Errorf ( "incompatible types" )
2020-05-06 17:43:32 +02:00
func checkTypes ( config map [ string ] interface { } , options interface { } ) map [ string ] interface { } {
2020-04-17 10:29:18 +02:00
optionsType := getStepOptionsStructType ( options )
for paramName := range config {
optionsField := findStructFieldByJSONTag ( paramName , optionsType )
if optionsField == nil {
continue
}
2020-07-29 09:22:10 +02:00
if config [ paramName ] == nil {
// There is a key, but no value. This can result from merging values from the CPE.
continue
}
2020-04-17 10:29:18 +02:00
paramValueType := reflect . ValueOf ( config [ paramName ] )
2020-07-29 09:22:10 +02:00
if optionsField . Type . Kind ( ) == paramValueType . Kind ( ) {
// Types already match, nothing to do
2020-04-17 10:29:18 +02:00
continue
}
2020-07-29 09:22:10 +02:00
var typeError error = nil
2020-04-17 10:29:18 +02:00
2020-07-29 09:22:10 +02:00
switch paramValueType . Kind ( ) {
2020-04-17 10:29:18 +02:00
case reflect . String :
2020-07-29 09:22:10 +02:00
typeError = convertValueFromString ( config , optionsField , paramName , paramValueType . String ( ) )
case reflect . Float32 , reflect . Float64 :
typeError = convertValueFromFloat ( config , optionsField , paramName , paramValueType . Float ( ) )
case reflect . Int , reflect . Int8 , reflect . Int16 , reflect . Int32 , reflect . Int64 :
typeError = convertValueFromInt ( config , optionsField , paramName , paramValueType . Int ( ) )
default :
log . Entry ( ) . Warnf ( "Config value for '%s' is of unexpected type %s, expected %s. " +
"The value may be ignored as a result. To avoid any risk, specify this value with explicit type." ,
paramName , paramValueType . Kind ( ) , optionsField . Type . Kind ( ) )
2020-04-17 10:29:18 +02:00
}
2020-07-29 09:22:10 +02:00
if typeError != nil {
typeError = fmt . Errorf ( "config value for '%s' is of unexpected type %s, expected %s: %w" ,
paramName , paramValueType . Kind ( ) , optionsField . Type . Kind ( ) , typeError )
log . SetErrorCategory ( log . ErrorConfiguration )
2020-08-12 15:41:29 +02:00
log . Entry ( ) . WithError ( typeError ) . Fatal ( "type error in configuration" )
2020-04-17 10:29:18 +02:00
}
}
return config
}
2020-07-29 09:22:10 +02:00
func convertValueFromString ( config map [ string ] interface { } , optionsField * reflect . StructField , paramName , paramValue string ) error {
switch optionsField . Type . Kind ( ) {
case reflect . Slice , reflect . Array :
// Could do automatic conversion for those types in theory,
// but that might obscure what really happens in error cases.
return fmt . Errorf ( "expected type to be a list (or slice, or array) but got string" )
case reflect . Bool :
// Sensible to convert strings "true"/"false" to respective boolean values as it is
// common practice to write booleans as string in yaml files.
paramValue = strings . ToLower ( paramValue )
if paramValue == "true" {
config [ paramName ] = true
return nil
} else if paramValue == "false" {
config [ paramName ] = false
return nil
}
}
return errIncompatibleTypes
}
func convertValueFromFloat ( config map [ string ] interface { } , optionsField * reflect . StructField , paramName string , paramValue float64 ) error {
switch optionsField . Type . Kind ( ) {
case reflect . String :
2020-10-27 16:14:00 +02:00
val := strconv . FormatFloat ( paramValue , 'f' , - 1 , 64 )
2020-10-30 09:01:30 +02:00
// if Sprinted value and val are equal, we can be pretty sure that the result fits
// for very large numbers for example an exponential format is printed
if val == fmt . Sprint ( paramValue ) {
config [ paramName ] = val
return nil
}
2020-10-27 16:14:00 +02:00
// allow float numbers containing a decimal separator
if strings . Contains ( val , "." ) {
config [ paramName ] = val
return nil
}
2020-10-30 09:01:30 +02:00
// if now no decimal separator is available we cannot be sure that the result is correct:
2020-10-27 16:14:00 +02:00
// long numbers like e.g. 73554900100200011600 will not be represented correctly after reading the yaml
// thus we cannot assume that the string is correct.
// short numbers will be handled as int anyway
return errIncompatibleTypes
2020-07-29 09:22:10 +02:00
case reflect . Float32 :
config [ paramName ] = float32 ( paramValue )
return nil
case reflect . Float64 :
config [ paramName ] = paramValue
return nil
case reflect . Int :
// Treat as type-mismatch only in case the conversion would be lossy.
// In that case, the json.Unmarshall() would indeed just drop it, so we want to fail.
if float64 ( int ( paramValue ) ) == paramValue {
config [ paramName ] = int ( paramValue )
return nil
}
}
return errIncompatibleTypes
}
func convertValueFromInt ( config map [ string ] interface { } , optionsField * reflect . StructField , paramName string , paramValue int64 ) error {
switch optionsField . Type . Kind ( ) {
case reflect . String :
config [ paramName ] = strconv . FormatInt ( paramValue , 10 )
return nil
case reflect . Float32 :
config [ paramName ] = float32 ( paramValue )
return nil
case reflect . Float64 :
config [ paramName ] = float64 ( paramValue )
return nil
}
return errIncompatibleTypes
}
2020-04-17 10:29:18 +02:00
func findStructFieldByJSONTag ( tagName string , optionsType reflect . Type ) * reflect . StructField {
for i := 0 ; i < optionsType . NumField ( ) ; i ++ {
field := optionsType . Field ( i )
tag := field . Tag . Get ( "json" )
if tagName == tag || tagName + ",omitempty" == tag {
return & field
}
}
return nil
}
func getStepOptionsStructType ( stepOptions interface { } ) reflect . Type {
typedOptions := reflect . ValueOf ( stepOptions )
if typedOptions . Kind ( ) == reflect . Ptr {
typedOptions = typedOptions . Elem ( )
}
return typedOptions . Type ( )
}
2020-02-06 10:08:15 +02:00
func getProjectConfigFile ( name string ) string {
var altName string
if ext := filepath . Ext ( name ) ; ext == ".yml" {
altName = fmt . Sprintf ( "%v.yaml" , strings . TrimSuffix ( name , ext ) )
} else if ext == "yaml" {
altName = fmt . Sprintf ( "%v.yml" , strings . TrimSuffix ( name , ext ) )
}
fileExists , _ := piperutils . FileExists ( name )
altExists , _ := piperutils . FileExists ( altName )
// configured filename will always take precedence, even if not existing
if ! fileExists && altExists {
return altName
}
return name
}
2021-12-15 16:07:47 +02:00
func mergeResourceParameters ( resParams ... map [ string ] interface { } ) map [ string ] interface { } {
result := make ( map [ string ] interface { } )
for _ , m := range resParams {
for k , v := range m {
result [ k ] = v
}
}
return result
}