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 ( ) )
2022-01-24 14:55:28 +02:00
rootCmd . AddCommand ( DefaultsCommand ( ) )
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 ( ) )
2022-02-10 11:25:03 +02:00
rootCmd . AddCommand ( HelmExecuteCommand ( ) )
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 ( ) )
2022-05-23 15:15:22 +02:00
rootCmd . AddCommand ( AbapEnvironmentCreateTagCommand ( ) )
2020-11-03 13:02:13 +02:00
rootCmd . AddCommand ( AbapEnvironmentCreateSystemCommand ( ) )
2020-01-28 00:40:53 +02:00
rootCmd . AddCommand ( CheckmarxExecuteScanCommand ( ) )
Adding support for CheckmarxOne platform (#4317)
* Initial in progress
* compiling but not yet functional
* Missed file
* updated checkmarxone step
* Working up to fetching a project then breaks
* Missed file
* Breaks when retrieving projects+proxy set
* Create project & run scan working, now polling
* Fixed polling
* added back the zipfile remove command
* Fixed polling again
* Generates and downloads PDF report
* Updated and working, prep for refactor
* Added compliance steps
* Cleanup, reporting, added groovy connector
* fixed groovy file
* checkmarxone to checkmarxOne
* checkmarxone to checkmarxOne
* split credentials (id+secret, apikey), renamed pullrequestname to branch, groovy fix
* Fixed filenames & yaml
* missed the metadata_generated.go
* added json to sarif conversion
* fix:type in new checkmarxone package
* fix:type in new checkmarxone package
* removed test logs, added temp error log for creds
* extra debugging to fix crash
* improved auth logging, fixed query parse issue
* fixed bug with group fetch when using oauth user
* CWE can be -1 if not defined, can't be uint
* Query also had CweID
* Disabled predicates-fetch in sarif generation
* Removing leftover info log message
* Better error handling
* fixed default preset configuration
* removing .bat files - sorry
* Cleanup per initial review
* refactoring per Gist, fixed project find, add apps
* small fix - sorry for commit noise while testing
* Fixing issues with incremental scans.
* removing maxretries
* Updated per PR feedback, further changes todo toda
* JSON Report changes and reporting cleanup
* removing .bat (again?)
* adding docs, groovy unit test, linter fixes
* Started adding tests maybe 15% covered
* fix(checkmarxOne): test cases for pkg and reporting
* fix(checkmarxOne):fix formatting
* feat(checkmarxone): update interface with missing method
* feat(checkmarxone):change runStep signature to be able to inject dependency
* feat(checkmarxone): add tests for step (wip)
* Adding a bit more coverage
* feat(checkmarxOne): fix code review
* feat(checkmarxOne): fix code review
* feat(checkmarxOne): fix code review
* feat(checkmarxOne): fix integration test PR
---------
Co-authored-by: thtri <trinhthanhhai@gmail.com>
Co-authored-by: Thanh-Hai Trinh <thanh.hai.trinh@sap.com>
2023-05-05 14:05:58 +02:00
rootCmd . AddCommand ( CheckmarxOneExecuteScanCommand ( ) )
2020-05-25 19:48:59 +02:00
rootCmd . AddCommand ( FortifyExecuteScanCommand ( ) )
2022-06-24 09:04:24 +02:00
rootCmd . AddCommand ( CodeqlExecuteScanCommand ( ) )
2023-04-04 16:57:15 +02:00
rootCmd . AddCommand ( CredentialdiggerScanCommand ( ) )
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 ( ) )
Add step abapEnvironmentPushATCSystemConfig (#3426)
* Checkin Go File - Push ATC Config
* ATC Push Config - Testfile
* Initial generated go files for ATC System Configuration
* ApiProxyUpload Command (#3295)
* ApiProxyUpload Command
* Code Review Fixes
* CodeReview Changes
* CodeReview Fixes
* YAML fixes
* CodeReview Fix
* Code Review Fixes
* CodeReview Fixes
* Code Climate Fixes
* Code Review Fixes
* Code Review Fixes
Co-authored-by: Roland Stengel <r.stengel@sap.com>
Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
* Fetch Xcrsf-Token
* Update abapEnvironmentPushATCSystemConfig.yaml
* docs: fix urls (#3400)
* fix stash and adapt unit tests accordingly (#3403)
* Push ATC System Configuration - File read, send request, parse response
* fetchATCXcsrfToken
* fix(whitesourceExecuteScan): added missing credential declaration for the docker config (#3404)
* insert command in piper.go
* feat(cnbBuild): remove docker config after parsing (#3417)
Co-authored-by: Philipp Stehle <philipp.stehle@sap.com>
* more funcs
* more funcs
* Revert "feat: Add debug output to getConfig (#3341)" (#3396)
This reverts commit b760bf48e76ab010c520d70ae4d967c0a5b56f9d.
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* feat (kubernetesDeploy) allow secret creation in cluster with kubectl as deploy tool (#3398)
* defaulting deocker config json location
* function change
* harmonising secret creation via json config apply
* adding the env path to kaniko
* env var
* adding path
* adding path
* adding path
* rolling back changes for path
* adapting condition for secret creation
* conditions based on username and password only
* fix unit test as per new secret creation
* update documentation with regards to secret creation
* fixing yaml lint empty line
* fixing trailing line from kaniko yaml
* error condition when path of the docker config json file is not found
Co-authored-by: anilkeshav27 <you@example.com>
* readPipelineEnv -> Serialize Directly to os.Stdout (#3180)
* Serialize CPE Directly to os.Stdout
* Response Error Handling 1
* Add easy mode for AUnit & ATC (#3389)
* remove mandatory flag from config files
* Enable repo.yml as config
* Adapt to merge
* Refactoring
* Refactoring
* avoid panic
* Add comments
* Add easy mode for atc
* Add tests
* Add test
* Refactor
* Add test for MPS
* Updates
* Rename functions
* Add files to gitignore
* Rename
* Renaming
* Renaming
* Renaming
* Improve error messages
* Update documentation
* Add logging
* Rename
* Extend gitignore
* fix(sonar): fix file patterns for gcs upload (#3406)
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* testing piper forks (#3420)
* developer doku update on how to test with forked repos
Co-authored-by: rosemarieB <45030247+rosemarieB@users.noreply.github.com>
* Error Messages parsing
* Update yaml parameter
* feat (npmExecuteScripts) create seperate npmrc file for publish to private repo (#3422)
* creating new npm rc file
* publishing to registry staging
* exposing base64 version of env variables
* changing encoding param
* fixing unit test for the new path
* debugging env var
* remove debug message
* update docu
* changing new npmrc file name
* adding new npmrc to ignore
* adding new npmrc to ignore
Co-authored-by: anilkeshav27 <you@example.com>
* minor
* small changes
* small changes
* UNIT Test
* Unit Test 2
* Update .gitignore
Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
* Update abapEnvironmentAddons.md: Unable to update target vectors with unchanged SWC version (#3392)
* Update abapEnvironmentAddons.md
* Update documentation/docs/scenarios/abapEnvironmentAddons.md
Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
* Update abapEnvironmentAddons.md
Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
* Returning earlier & parseOdataResp 1
* new Parameter for overwrite existing
* feat(cnbBuild): preserve maven test results in the workspace (#3429)
Co-authored-by: Pavel Busko <pavel.busko@sap.com>
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
* Update Introduction (#3433)
* Check Existence of configuration
* Quote strings in addon.yml (#3435)
* including vaultSecretFile to parameter generator docu (#3436)
Co-authored-by: anilkeshav27 <you@example.com>
* fix: wrong command line format for multiple extension files (#3434)
* feat(cnbBuild) containerImageName will be defaulted if possible (#3437)
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
Co-authored-by: Johannes Dillmann <j.dillmann@sap.com>
Co-authored-by: Sumit Kulhadia <sumit.kulhadia@sap.com>
* Corr. check existence
* check existence 2
* existence handling 2
* refinement existence handling & param rename
* config yaml change - no mandatory for bool param
* PATCH for existing Configuration
* fix: correct typo in log message (#3439)
Closes #3438
* feat(protecode): add versioning model (#3373)
* changes to detectExec before master merge
* changes for detectExecuteScan
* self generated code added
* fix syntax errors and update docu
* added unit tests for fail and Group
* fix failOn bug
* add Groups as string array
* add Groups as string array
* tests and validation for groups, failOn
* Updated docs and added more tests
* documentation md files should not be changed
* Handle merge conflicts from PR 1845
* fix merge errors
* remove duplicate groups, merge error
* adding buildCode and buildTool as params
* switching build options
* building maven modules
* parameter correction
* parameter correction
* gnerate with new build parameter
* adding comments
* removing piper lib master and modifying goUtils to download 1.5.7 release
* first cleaning then installing
* multi module maven built
* multi module maven built removing unwanted code
* multi module maven built moving inside switch
* testing
* modifying the default use case to also call maven build
* modifying the default use case to also call maven build wih --
* corrected maven build command
* corrected maven build command with %v
* skipping test runs
* testing for MTA project with single pom
* adding absolute path to m2 path
* clean up
* adding switch for mta and maven and removing env from containers
* commiting changes for new detect step
* correting log message
* code clean up
* unit tests changes to detectExecute
* basic tests for new change
* restoring piperGoUtils to download correct piper binary
* code clean up
* code clean up
* protecodeExecuteScan :: versioning model draft - 1
* protecodeExecuteScan :: version model draft-2
* protecodeExecuteScan :: changing filename and version concatenation
* protecodeExecuteScan :: update documentation
* protecodeExecuteScan :: double URL encoding has been corrected & console messaging improved
* protecodeExecuteScan :: fixed Go/generate validation fail
* protecodeExecuteScan :: fixing failed unit tests
* protecodeExecuteScan :: Version field added
* protecodeExecuteScan :: Version field add => minor changes
* protecodeExecuteScan :: Version field add => fixing tests
Co-authored-by: D072410 <giridhar.shenoy@sap.com>
Co-authored-by: Keshav <anil.keshav@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
* GCS Upload fixes (#3387)
* Fixed argument type in persist function
* Fixed gcp upload to be usable in internal piper
* Fixed import of packages
* Updated logs
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Unit Test 2
* Unit Tests
* Add gcs upload to mavenExecuteIntegration step (#3432)
* Add gcs upload to mavenExecuteIntegration step
* go generate
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Check times refine
* Permwrite 0644
* disable http retry (#3447)
* Update maxWaitTime timeout for WhiteSource (#3284)
* Update scanPolling.go
Changing maxWaitTime from 15 to 30 to overcome WhiteSource results reflection in the backend issue.
* Update configHelper.go
* Reset configHelper changes to fix PR 3284
Committer: raghunathd8
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
Co-authored-by: raghunathd8 <root@docker-evaluation.openstack.eu-nl-1.cloud.sap>
Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
* removed trailing spaces
* yaml Update
* minor mock for token & Unit Tests
* rename Parameter Patch
* lil refactor & Unit Test
* fixes PATCH & more Unit Tests
* add log at certain points
* not writing configuration file back
* feat(malwareExecuteScan): refactoring and docker support (#3421)
* feat(malwareExecuteScan): add support for scanning docker images
* refactoring
* print out finding if available
* generate toolrecord for malware scan
* persist scan report
* docs
* fix
* fix
* rollback cmd/init_unix.go
* auhenticated pull
* fix
* fix: report shall be consistent with the api model
* gcs upload
* fix linter
* Fix potential nil reference (#3460)
* Add gcs upload to karmaExecuteTests step (#3431)
* Add gcs upload to karmaExecuteTests step
* go generate
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Add gcs upload to gaugeExecuteTests step (#3410)
* Add gcs upload to gaugeExecuteTests step
* go generate
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Add gcs upload to newmanExecute step (#3408)
* Add gcs upload to newmanExecute step
* go generate
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* feat(GitHub): fetch commit statistics (#3381)
* fetch GH statistics
* move GH and Sonar integration tests to own files
* fix imports
* add integration test case
* add result type
* Apply suggestions from code review
* feat: add command to fetch default files (#3445)
* some ideas..
* Add getDefaults command (WIP) (#3444)
* add getYAML function for configs
* create getDefaults command(based on getConfig)
* add getDefaults command to CLI
* read defaults files, using github tokens as well
* write defaults to stdout as JSON object with YAMLs embedded
* catch case where no input files are given
* actually write output to file if outputFile is specified
* mark defaultsFile flag as required
* add basic tests
* add output (string) test
* adapt generateDefaults() to return output (used for test of previous commit)
* Changes to getDefaults() JSON output (#3449)
* change JSON output to contain separate fields
* filename -> filepath
* Apply suggestions from code review
* Apply suggestions from code review
* Update pkg/config/config_test.go
Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com>
* BATCH request preparation
* Add gcs upload to mtaBuild step (#3405)
* Add gcs upload to mtaBuild
* Patterns was updated
* go generate
* removed patterns related to sapGenerateEnvironmentInfo step
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Add gcs upload to mavenBuild step (#3394)
* Add gcs upload to mavenBuild step
* Patterns were updated
* go generate
* removed patterns related to sapGenerateEnvironmentInfo step
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* feat(gradleExecuteBuild): add stage scope to path parameter, fix project dir exist issue (#3401)
* add stage scope to path parameter, fix project dir exist issue
* fix unit test for gradleExecuteBuild
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Add gcs upload to uiVeri5ExecuteTests step (#3409)
* Add gcs upload to uiVeri5ExecuteTests step
* go generate
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Address further nil references (#3462)
* Address further nil references
* Message text
* Final checks
* fix (npmExecuteScripts) allow npm pack before npm publish (#3455)
* adding config to piperNpmr
* scope in cli
* adding scope to repo url and npmrc
* publish to scoped
* removing scope
* changing scope position
* adding scope to userconfig
* adding registry=
* pack and then tar
* not removing tmp folder
* adding flag
* pack before publish
* adding log
* debug
* debug with change directory
* publishing created tar ball
* debug
* üath
* adding main npmrc
* renaming old npmrc file
* error renaming old npmrc file
* renaming err
* correcting npmrc file path
* renaming file back to original
* current working directory
* renaming the npmrc file
* avoiding change directory
* with current working dir
* adding dot
* renaming npmrc and defer removal
* rename files
* Update pkg/npm/publish.go
* Update pkg/npm/publish.go
Co-authored-by: anilkeshav27 <you@example.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Add testing for helm during acceptance stage (#3402)
* Add kubernetesDeploy to Acceptance
* Add more kubernetesDeploy
* Add helm tests
* Change documentation
* Fix docu
* Change generated
* Add tests
* Add groovy tests
* Fix tests
* Change tests
Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
* Batch Request for Patches
* Fix(gctsDeploy) : add client in config url, disable retry for create and pull (#3464)
* minor Unit Test correction
* lil cleanup
* lil refactoring
* removed nuneeded linebreaks
* refactoring Command on Entity in Batch
* some Unit Tests for Build Batch Request
* more Unittests - Build Batch Request
* fix(fortifyExecuteScan): User assignment based on PR ownership (#3472)
* Debug PR user details
* Check association
* Change to login
* Fix PR creator assignment
* Improve docs
* Fix test
* Update gradle version (#3476)
* Update gradle version
* Update generated file
* small correction Text & Test
* chore(kubernetesDeploy): add telemetry for deployTool (#3469)
* chore(kubernetesDeploy): add telemetry for deployTool
* Update cmd/kubernetesDeploy.go
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* rename Parameter patchIfExisting
* fix (mtaBuild) keep mtar artifact name in synch with maven gav (#3454)
* keep mtar name in synch with maven gav
* retaining slashes
* keeping dots in artifact name
Co-authored-by: anilkeshav27 <you@example.com>
* Update image for gradle build (#3479)
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* Last Changed not Zero check added
* Added pseudo_comment_policy in struct
* Unit Test adaption
* smaller refactoring, Unit Test, removed doubles
* fix(cnbBuild) do not add complete path to telemetry (#3487)
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
Co-authored-by: Philipp Stehle <philipp.stehle@sap.com>
* Add limitation that table keys are exported generically (#3490)
* Add limitation that table keys are exported generically
* Fix formatting
* Clarify delta calculation of different package types (#3482)
Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>
* Add troubleshooting for missing add-on registration (#3491)
Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>
* feat (Documentation) documentation for mavenBuild and npmExecuteScripts that consume dependencies from a private repo. (#3484)
* build depdency docu for maven and npm
* removing trailing white space in yaml
* Update resources/metadata/mavenBuild.yaml
* relative url for vault and mta docu
* running go generate
* keeping vault relative path
* go generate
* reverting to global paths
* go generate
* wild card for a higher level dir
* searching on top folder only
* relative level above
* pointing to infrastructure
* correcting links
Co-authored-by: anilkeshav27 <you@example.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* fix(kanikoExecute): tmp dir (#3478)
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* feat(golangBuild): add support for publishing binaries (#3495)
* fix(golangBuild): keep track of the artifactversion in binary names (#3498)
* fix(golangBuild): keep track of the artifactversion in binary names
* improve the naming scheme
* fix (build dependency) typo corrections (#3494)
* typo corrections
* trailing white space
* go generate
Co-authored-by: anilkeshav27 <you@example.com>
* Revert "fix(golangBuild): keep track of the artifactversion in binary names (#3498)" (#3499)
This reverts commit ec783b0da65a508b3067b9baf5f9587cbbf0d30c.
* sonarqube coverage: additional metrics (#3465)
* sonarqube coverage: additional metrics
* sonarExecuteScan: add lines of code and language distribution to sonarscan.json
* sonarExecuteScan: consider branch in componentService requests
* SonarQube: Do not omit empty values in SonarCoverage
* sonarExecuteScan: Add integration tests for ComponentService getLinesOfCode
* fix tests
* sonarExecuteScan: use pullRequest in componentService
Co-authored-by: I550025 <r.kloe@sap.com>
Co-authored-by: Marc Bormeth <marc.bormeth@sap.com>
* fix(golangBuild): targetRepositoryUrl (#3502)
* fix(golangBuild): targetRepositoryUrl
* regen
* fix(httpclient): folder permissions (#3506)
* fix(golangBuild): use PUT instead of POST (#3504)
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* feat(golangBuild): publish to subfolder (#3503)
* feat(golangBuild): publish to subfolder
* edge case handling
* fix
* fix(golangBuild): expect status 201 instead of 200 (#3508)
* feat(kanikoExecute): allow building multiple images (#3443)
* feat(kanikoExecute): allow building multiple images
* enhance tests
* chore: allow running tests in parallel
* small fixes
* fix: fix destination bug
* update formatting and defaults
* fix yml formatting
* chore: change cpe parameter names
* chore: improve variable naming
* Changes GetJobName value to repositoryname (#3509)
* Update npmExecuteScripts step (#3211)
* Update npmExecuteScripts step
* Fixed failing build
* Fixed path issue
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Christian Volk <christian.volk@sap.com>
* Ignore violations if failOn is NONE (#3513)
* fix(sonarExecuteScan): error handling for report metrics (#3512)
* Generic step input from addon descriptor (#3467)
* enhance build step to run based on addon.yml in steampunk environment
Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>
* feat(golangBuild): add BOM creation (#3496)
* Added BOM creation
* Fix cyclonedx install
* undo config.yml changes
* metadata was updated
* Update golangBuild.go
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
* If statement dearrangement
Co-authored-by: Daniel Bernd <93763187+danManSAP@users.noreply.github.com>
Co-authored-by: Mayur Belur Mohan <68264167+mayurmohan@users.noreply.github.com>
Co-authored-by: Roland Stengel <r.stengel@sap.com>
Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com>
Co-authored-by: Jesse Awan <jesse.awan@sap.com>
Co-authored-by: Pavel Busko <pavel.busko@sap.com>
Co-authored-by: Philipp Stehle <philipp.stehle@sap.com>
Co-authored-by: Marc Bormeth <marc.bormeth@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
Co-authored-by: Anil Keshav <anil.keshav@sap.com>
Co-authored-by: anilkeshav27 <you@example.com>
Co-authored-by: tiloKo <70266685+tiloKo@users.noreply.github.com>
Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
Co-authored-by: Siarhei Pazdniakou <siarhei.pazdniakou@sap.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Peter Persiel <6087940+peterpersiel@users.noreply.github.com>
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
Co-authored-by: Marcus Holl <marcus.holl@sap.com>
Co-authored-by: Johannes Dillmann <j.dillmann@sap.com>
Co-authored-by: Sumit Kulhadia <sumit.kulhadia@sap.com>
Co-authored-by: Nikolay Grechanov <nikolay.grechanov@sap.com>
Co-authored-by: Umidjon Urunov <79094563+UmidjonUrunov@users.noreply.github.com>
Co-authored-by: D072410 <giridhar.shenoy@sap.com>
Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
Co-authored-by: Sarat Krishnan <78093145+sarat-krk@users.noreply.github.com>
Co-authored-by: Raghunath Deshpande <raghunath.deshpande@sap.com>
Co-authored-by: raghunathd8 <root@docker-evaluation.openstack.eu-nl-1.cloud.sap>
Co-authored-by: Christian Volk <christian.volk@sap.com>
Co-authored-by: Eugene Kortelyov <eugene.kortelyov@sap.com>
Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>
Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
Co-authored-by: Matthias Scudlik <matthias.scudlik@gmail.com>
Co-authored-by: I550025 <r.kloe@sap.com>
Co-authored-by: ffeldmann <f.feldmann@sap.com>
Co-authored-by: ManjunathMS35 <manjunathms35@gmail.com>
Co-authored-by: Matthias Scudlik <matthias.scudlik@sap.com>
Co-authored-by: rosemarieB <45030247+rosemarieB@users.noreply.github.com>
2022-02-08 17:14:29 +02:00
rootCmd . AddCommand ( AbapEnvironmentPushATCSystemConfigCommand ( ) )
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 ( ) )
2022-02-22 10:58:22 +02:00
rootCmd . AddCommand ( GctsExecuteABAPQualityChecksCommand ( ) )
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 ( ) )
2022-03-09 14:07:23 +02:00
rootCmd . AddCommand ( ApiProviderDownloadCommand ( ) )
2021-12-28 10:31:50 +02:00
rootCmd . AddCommand ( ApiProxyUploadCommand ( ) )
2021-12-22 16:34:36 +02:00
rootCmd . AddCommand ( GradleExecuteBuildCommand ( ) )
2022-03-07 12:03:44 +02:00
rootCmd . AddCommand ( ApiKeyValueMapUploadCommand ( ) )
2022-03-29 19:01:44 +02:00
rootCmd . AddCommand ( PythonBuildCommand ( ) )
2022-06-15 09:41:02 +02:00
rootCmd . AddCommand ( AzureBlobUploadCommand ( ) )
2022-05-18 10:37:54 +02:00
rootCmd . AddCommand ( AwsS3UploadCommand ( ) )
2022-06-21 13:08:00 +02:00
rootCmd . AddCommand ( ApiProxyListCommand ( ) )
2022-06-21 15:45:07 +02:00
rootCmd . AddCommand ( AnsSendEventCommand ( ) )
2022-07-07 14:48:59 +02:00
rootCmd . AddCommand ( ApiProviderListCommand ( ) )
[TMS] Reimplement tmsUpload step in Go (#3399)
* Initially generated tmsUpload<...> files
* First provisioning of parameters supported by tmsUpload step
* Refer to Go step from tmsUpload.groovy
* Initial client implementation
* Reverting line delimiters in tmsUpoad.groovy back to Unix ones
* Temporarily remove when-condition for Release stage
* Define useGoStep parameter in tmsUpload.groovy
* Unstash buildResult if useGoStep is true
* No unstashing and empty credentials, when using go step
* Register TmsUploadCommand in piper.go
* Cleanup groovy-related changes - they will be temporarily implemented in a different repo
* Make getting OAuth token success
* Look through the code and cleanup it a bit
* Read service key from Jenkins credentials store
* Provide initial set of unit tests for methods in /pkg/tms/tms.go file
* Minor improvements on logging response on http call error
* Check, if positive HTTP status code is as expected
* Cleanup tms.yaml file, provide additional unit test for tms.go
* Provide unit test for the case, when request body contains spaces
* Specify nodeExtDescriptorMapping parameter as of type map in tms.yaml
* Implement client method for getting nodes
* Write tests for GetNodes method
* Add GetMtaExtDescriptor client method and cover it with unit tests
* Provide first implementation for Update- and UploadMtaExtDescriptor
client methods
* Provide first implementation for Update- and UploadMtaExtDescriptor
client methods
* Provide UploadFile and UploadFileToNode client methods
* Provide tests for Update- and UploadMtaExtDescriptor client methods
* Write tests for FileUpload and FileUploadToNode client methods
* Minor corrections
* Remove some TODO comments
* Rename some of response structures
* Revert change for line delimiters in cmd/piper.go
* Add uploadType string parameter to UploadFile and UploadRequest methods
of uploader mock to reflect the changed Uploader implementation
* Start to implement execution logic in tmsUpload.go
* Changes in tms.yaml file
- remove resources from inputs in tms.yaml and implement mtaPath
parameter settings in the yaml file the same way, as it is done in
cloudFoundryDeploy.yaml
- rename tms.yaml to tmsUpload.yaml, since some generation policy
changed meanwhile
* Rename tms.yaml to tmsUpload.yaml and do go generate
* Use provided proxy on communication with UAA and TMS
* Set proxy even before getting OAuth token
* Further implementation of tmsUpload.go
* Continuation on implementing the tmsUpload.go executor
* Get mtarFilePath and git commitId from commonPipelineEnvironment, if
they are missing in configuration file + minor changes
* Implement a happy path test for tmsUpload logic
* Cover with unit tests main happy and error paths of tmsUpload.go logic
* Extend set of unit tests for tmsUpload.go
* Eliminate some TODOs, extend unit tests for tmsUpload.go
* Delete some TODOs
* Remove a couple of more TODOs from tms_test.go file
* Provide additional unit test for error due unexpected positive http
status code on upload
* Revert back line delimiters in cmd/piper.go
* Comment out file uploading calls in tmsUpload.go
* Run go generate to update generated files
* Convert line delimiters in tmsUpload.yaml to Unix ones, as well as
provide new line character in the end of the file, plus minor fix for
logging in tmsUpload.go file (pipeline complained)
* Correct description of a parameter in tmsUpload.yaml, extend unit tests
to check for trimming a slash in the end of TMS url for client methods
that do upload
* [minor] Add a comment in the test code
* Add stashContent parameter to do unstashing in tmsUpload.groovy, remove
some of the clarified TODOs
* Uncomment uploading file calls in tmsUpload.go, declare buildResult
stash in tmsUpload.yaml
* Remove clarified TODOs from the tmsUpload.go file
* Run go fmt for jenkins-library/pkg/tms
* Do not get explicitly values from common pipeline environment - all
configurations are provided in yaml file
* Remove unused struct from tmsUpload_test.go
* Run go fmt jenkins-library\pkg\tms
* Revise descriptions of parameters provided in tmsUpload.yaml file
* Specify STAGES scope for tmsUpload parameters
* Provide STAGES scope for the tmsUpload parameters, provide default value
for stashContent parameter
* Remove trailing space from tmsUpload.yaml
* Provide unit tests for proxy-related changes in http.go file
* Improve proxy implementation in tmsUpload.go file
* Make tmsServiceKey again a mandatory parameter
* Run go generate command to make the generated files correspond the yaml
state
* Change line delimiters back to Unix ones (were switched while resolving
the conflicts)
* Remove trailing spaces from tmsUpload.yaml
* Minor change in a comment to trigger pipelines with commit
* Improve checks for zero-structs and for empty maps, as well as use
different package to read files in the tests
* Revert line endings in http.go
* Revert comments formatting changes in files that do not belong to the tmsUpload step
2022-08-30 10:16:09 +02:00
rootCmd . AddCommand ( TmsUploadCommand ( ) )
2023-03-27 16:55:29 +02:00
rootCmd . AddCommand ( TmsExportCommand ( ) )
2022-12-20 13:15:36 +02:00
rootCmd . AddCommand ( IntegrationArtifactTransportCommand ( ) )
2023-04-18 08:56:32 +02:00
rootCmd . AddCommand ( AscAppUploadCommand ( ) )
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 { }
}
2022-03-28 09:52:15 +02:00
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-12-21 12:52:10 +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" )
2021-02-15 10:48:51 +02:00
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 ( ) {
2023-04-06 08:31:22 +02:00
log . Entry ( ) . Debugf ( "Using stageName '%s' from %s" , GeneralConfig . StageName , stageNameSource )
2020-08-13 17:55:12 +02:00
} ( )
}
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 {
2023-04-06 08:31:22 +02:00
log . Entry ( ) . Debugf ( "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" {
2023-04-06 08:31:22 +02:00
log . Entry ( ) . Debugf ( "Project defaults: '%s'" , projectDefaultFile )
2020-06-10 09:39:29 +02:00
return errors . Wrapf ( err , "Cannot read '%s'" , projectDefaultFile )
}
} else {
2023-04-06 08:31:22 +02:00
log . Entry ( ) . Debugf ( "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 {
2023-04-06 08:31:22 +02:00
log . Entry ( ) . Debug ( "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
}