Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/kosli/allowArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (o *allowArtifactOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("artifact %s was allow listed in environment: %s", o.payload.Fingerprint, o.environmentName)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/archiveEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newArchiveEnvironmentCmd(out io.Writer) *cobra.Command {
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("environment %s was archived", args[0])
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/archiveFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newArchiveFlowCmd(out io.Writer) *cobra.Command {
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("flow %s was archived", args[0])
}
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/kosli/attachPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func newAttachPolicyCmd(out io.Writer) *cobra.Command {
}

cmd.Flags().StringSliceVarP(&o.environments, "environment", "e", []string{}, attachPolicyEnvFlag)
addDryRunFlag(cmd)

err := RequireFlags(cmd, []string{"environment"})
if err != nil {
Expand All @@ -79,7 +80,7 @@ func (o *attachPolicyOptions) run(args []string) error {
break
}
}
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("policy '%s' is attached to environments: %s", args[0], o.environments)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/attestArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (o *attestArtifactOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("artifact %s was attested with fingerprint: %s", o.payload.Filename, o.payload.Fingerprint)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/attestGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (o *attestGenericOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("generic attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}
return wrapAttestationError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/attestJira.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (o *attestJiraOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("jira attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/attestJunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (o *attestJunitOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("junit attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}
return wrapAttestationError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/attestSnyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (o *attestSnykOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("snyk attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}
return wrapAttestationError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/attestSonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (o *attestSonarOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("sonar attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/beginTrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (o *beginTrailOptions) run(args []string) error {
}

res, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
verb := "begun"
if res.Resp.StatusCode == 200 {
verb = "updated"
Expand Down
14 changes: 2 additions & 12 deletions cmd/kosli/cli_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"
"reflect"
"slices"
"strconv"
"strings"
"text/tabwriter"
Expand Down Expand Up @@ -523,7 +522,7 @@ func ValidateAttestationArtifactArg(args []string, artifactType, inputSha256 str
return fmt.Errorf("artifact name argument is required when --artifact-type is set")
}
if artifactType == "" && inputSha256 == "" && len(args) > 0 {
return fmt.Errorf("--artifact-type or --fingerprint must be specified when artifact name ('%s') argument is supplied.%s", args[0], BooleanArgsMessageLink(args))
return fmt.Errorf("--artifact-type or --fingerprint must be specified when artifact name ('%s') argument is supplied.", args[0])
}

if inputSha256 != "" {
Expand Down Expand Up @@ -801,17 +800,8 @@ func prefixEachLine(multilineString, prefix string) string {
// Custom error message instead of cobra.MaximumNArgs(1)
func CustomMaximumNArgs(max int, args []string) error {
if len(args) > max {
return fmt.Errorf("accepts at most 1 arg(s), received %v %v%s", len(args), args, BooleanArgsMessageLink(args))
return fmt.Errorf("accepts at most 1 arg(s), received %v %v", len(args), args)
} else {
return nil
}
}

func BooleanArgsMessageLink(args []string) string {
if slices.Contains(args, "true") || slices.Contains(args, "false") {
return "\nSee https://docs.kosli.com//faq/#boolean-flags"
} else {
return ""
}

}
2 changes: 1 addition & 1 deletion cmd/kosli/createEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (o *createEnvOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("environment %s was created", o.payload.Name)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/createFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (o *createFlowOptions) run(args []string) error {
}

res, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
verb := "created"
if res.Resp.StatusCode == 200 {
verb = "updated"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/createPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (o *createPolicyOptions) run(args []string) error {
}

res, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
verb := "created"
if res.Resp.StatusCode == 200 {
verb = "updated"
Expand Down
3 changes: 2 additions & 1 deletion cmd/kosli/detachPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func newDetachPolicyCmd(out io.Writer) *cobra.Command {
}

cmd.Flags().StringSliceVarP(&o.environments, "environment", "e", []string{}, detachPolicyEnvFlag)
addDryRunFlag(cmd)

err := RequireFlags(cmd, []string{"environment"})
if err != nil {
Expand All @@ -75,7 +76,7 @@ func (o *detachPolicyOptions) run(args []string) error {
break
}
}
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("policy '%s' is detached from environments: %s", args[0], o.environments)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/disableBeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (o *betaOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("beta features have been %s for organization: %s", action, global.Org)
}
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/kosli/doubledHost.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func runDoubledHost(args []string) (string, error) {

// Return subsidiary-call's output in debug mode only.
stdOut := output0
if opts.debug && output1 != "" {
if opts.debug == "true" && output1 != "" {
stdOut += fmt.Sprintf("\n[debug] [%s]", opts.hosts[1])
stdOut += fmt.Sprintf("\n%s", output1)
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func runBufferedInnerMain(args []string) (string, error) {
type DoubledOpts struct {
hosts []string
apiTokens []string
debug bool
debug string
}

func getDoubledOpts() DoubledOpts {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/expectDeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (o *expectDeploymentOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("expect deployment of artifact %s was reported to: %s", o.payload.Fingerprint, o.payload.Environment)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func addAWSAuthFlags(cmd *cobra.Command, o *aws.AWSStaticCreds) {
}

func addDryRunFlag(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&global.DryRun, "dry-run", "D", false, dryRunFlag)
cmd.Flags().StringVarP(&global.DryRun, "dry-run", "D", "false", dryRunFlag)
}

func addBitbucketFlags(cmd *cobra.Command, bbConfig *bbUtils.Config, ci string) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/joinEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newJoinEnvironmentCmd(out io.Writer) *cobra.Command {
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("environment '%s' was joined to '%s'", o.payload.Physical, o.logical)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func innerMain(cmd *cobra.Command, args []string) error {
logger.Error("%s\navailable subcommands are: %s", errMessage, strings.Join(availableSubcommands, " | "))
}
}
if global.DryRun {
if global.DryRun == "true" {
logger.Info("Error: %s", err.Error())
logger.Warning("Encountered an error but --dry-run is enabled. Exiting with 0 exit code.")
return nil
Expand Down
12 changes: 6 additions & 6 deletions cmd/kosli/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func (o *pullRequestArtifactOptions) run(out io.Writer, args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("%s %s evidence is reported to artifact: %s", o.payload.GitProvider, label, o.payload.ArtifactFingerprint)
}

if len(pullRequestsEvidence) == 0 && o.pullRequestOptions.assert && !global.DryRun {
if len(pullRequestsEvidence) == 0 && o.pullRequestOptions.assert && global.DryRun == "false" {
return fmt.Errorf("assert failed: no %s found for the given commit: %s", label, o.commit)
}
return err
Expand Down Expand Up @@ -148,11 +148,11 @@ func (o *attestPROptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("%s %s attestation '%s' is reported to trail: %s", o.payload.GitProvider, label, o.payload.AttestationName, o.trailName)
}

if len(pullRequestsEvidence) == 0 && o.assert && !global.DryRun {
if len(pullRequestsEvidence) == 0 && o.assert && global.DryRun == "false" {
return fmt.Errorf("assert failed: no %s found for the given commit: %s", label, o.payload.Commit.Sha1)
}
return wrapAttestationError(err)
Expand Down Expand Up @@ -204,11 +204,11 @@ func (o *pullRequestCommitOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("%s %s evidence is reported to commit: %s", o.payload.GitProvider, label, o.payload.CommitSHA)
}

if len(pullRequestsEvidence) == 0 && o.pullRequestOptions.assert && !global.DryRun {
if len(pullRequestsEvidence) == 0 && o.pullRequestOptions.assert && global.DryRun == "false" {
return fmt.Errorf("assert failed: no %s found for the given commit: %s", label, o.payload.CommitSHA)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/renameEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func newRenameEnvironmentCmd(out io.Writer) *cobra.Command {
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("environment %s was renamed to %s", args[0], payload.NewName)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/renameFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newRenameFlowCmd(out io.Writer) *cobra.Command {
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("flow %s was renamed to %s", args[0], payload.NewName)
}
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/reportApproval.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ func (o *reportApprovalOptions) run(args []string, request bool) error {
getLastApprovedGitCommitParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
DryRun: false,
DryRun: "false",
Password: global.ApiToken,
}

lastApprovedGitCommitResponse, err := kosliClient.Do(getLastApprovedGitCommitParams)

if err != nil {
if !global.DryRun {
if global.DryRun == "false" {
// error and not dry run -> print error message and return err
return err
} else {
Expand Down Expand Up @@ -216,7 +216,7 @@ func (o *reportApprovalOptions) run(args []string, request bool) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("approval created for artifact: %s", o.payload.ArtifactFingerprint)
}
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/reportArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ func (o *reportArtifactOptions) run(args []string) error {
previousCommit, err := o.latestCommit(currentBranch(gitView))
if err == nil {
o.payload.CommitsList, err = gitView.ChangeLog(o.payload.GitCommit, previousCommit, logger)
if err != nil && !global.DryRun {
if err != nil && global.DryRun == "false" {
return err
}
} else if !global.DryRun {
} else if global.DryRun == "false" {
return err
}

Expand All @@ -161,7 +161,7 @@ func (o *reportArtifactOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("artifact %s was reported with fingerprint: %s", o.payload.Filename, o.payload.Fingerprint)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/reportEvidenceArtifactGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (o *reportEvidenceArtifactGenericOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("generic evidence '%s' is reported to artifact: %s", o.payload.EvidenceName, o.payload.ArtifactFingerprint)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/reportEvidenceArtifactJunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (o *reportEvidenceArtifactJunitOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("junit test evidence is reported to artifact: %s", o.payload.ArtifactFingerprint)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/reportEvidenceArtifactSnyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (o *reportEvidenceArtifactSnykOptions) run(args []string) error {
Password: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("snyk scan evidence is reported to artifact: %s", o.payload.ArtifactFingerprint)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/reportEvidenceCommitGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (o *reportEvidenceCommitGenericOptions) run(args []string) error {
}

_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
if err == nil && global.DryRun == "false" {
logger.Info("generic evidence '%s' is reported to commit: %s", o.payload.EvidenceName, o.payload.CommitSHA)
}
return err
Expand Down
Loading