From edd0b4149f847af88f8583c1a92e8060a1ed5a49 Mon Sep 17 00:00:00 2001 From: Ewelina Wilkosz Date: Tue, 5 Sep 2023 09:58:04 +0200 Subject: [PATCH] Improve code for --name flag kosli-dev/server#882 --- charts/k8s-reporter/README.md | 4 ++-- cmd/kosli/reportArtifact.go | 25 ++++++++++--------------- cmd/kosli/testHelpers.go | 7 +++++-- docs.kosli.com/content/helm/_index.md | 4 ++-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/charts/k8s-reporter/README.md b/charts/k8s-reporter/README.md index a67e3c0a6..579937da7 100644 --- a/charts/k8s-reporter/README.md +++ b/charts/k8s-reporter/README.md @@ -61,7 +61,7 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter | kosliApiToken.secretKey | string | `""` | the name of the key in the secret data which contains the kosli API token | | kosliApiToken.secretName | string | `""` | the name of the secret containing the kosli API token | | nameOverride | string | `""` | overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one | -| podAnnotations | object | `{}` | | +| podAnnotations | object | `{}` | any custom annotations to be added to the cronjob | | reporterConfig.dryRun | bool | `false` | whether the dry run mode is enabled or not. In dry run mode, the reporter logs the reports to stdout and does not send them to kosli. | | reporterConfig.kosliEnvironmentName | string | `""` | the name of kosli environment that the k8s cluster/namespace correlates to | | reporterConfig.kosliOrg | string | `""` | the name of the kosli org | @@ -74,5 +74,5 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter | serviceAccount.name | string | `""` | the name of the service account to use. If not set and create is true, a name is generated using the fullname template | ---------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0) +Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0) diff --git a/cmd/kosli/reportArtifact.go b/cmd/kosli/reportArtifact.go index ac1841264..b6023f839 100644 --- a/cmd/kosli/reportArtifact.go +++ b/cmd/kosli/reportArtifact.go @@ -104,29 +104,24 @@ func newReportArtifactCmd(out io.Writer) *cobra.Command { } func (o *reportArtifactOptions) run(args []string) error { - if o.payload.Fingerprint != "" { - if o.name != "" { - o.payload.Filename = o.name + + if o.name != "" { + o.payload.Filename = o.name + } else { + if o.fingerprintOptions.artifactType == "dir" || o.fingerprintOptions.artifactType == "file" { + o.payload.Filename = filepath.Base(args[0]) } else { o.payload.Filename = args[0] } - } else { + + } + + if o.payload.Fingerprint == "" { var err error o.payload.Fingerprint, err = GetSha256Digest(args[0], o.fingerprintOptions, logger) if err != nil { return err } - - if o.name != "" { - o.payload.Filename = o.name - } else { - if o.fingerprintOptions.artifactType == "dir" || o.fingerprintOptions.artifactType == "file" { - o.payload.Filename = filepath.Base(args[0]) - } else { - o.payload.Filename = args[0] - } - } - } gitView, err := gitview.New(o.srcRepoRoot) diff --git a/cmd/kosli/testHelpers.go b/cmd/kosli/testHelpers.go index bae831a77..cf999b243 100644 --- a/cmd/kosli/testHelpers.go +++ b/cmd/kosli/testHelpers.go @@ -185,8 +185,9 @@ func CreateWorkflowEvidence(auditTrailName, externalId string, t *testing.T) { func CreateArtifact(flowName, artifactFingerprint, artifactName string, t *testing.T) { t.Helper() o := &reportArtifactOptions{ - srcRepoRoot: "../..", - flowName: flowName, + srcRepoRoot: "../..", + flowName: flowName, + //name: "", gitReference: "0fc1ba9876f91b215679f3649b8668085d820ab5", payload: ArtifactPayload{ Fingerprint: artifactFingerprint, @@ -196,6 +197,8 @@ func CreateArtifact(flowName, artifactFingerprint, artifactName string, t *testi }, } + o.fingerprintOptions = new(fingerprintOptions) + err := o.run([]string{artifactName}) require.NoError(t, err, "artifact should be created without error") } diff --git a/docs.kosli.com/content/helm/_index.md b/docs.kosli.com/content/helm/_index.md index a67e3c0a6..579937da7 100644 --- a/docs.kosli.com/content/helm/_index.md +++ b/docs.kosli.com/content/helm/_index.md @@ -61,7 +61,7 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter | kosliApiToken.secretKey | string | `""` | the name of the key in the secret data which contains the kosli API token | | kosliApiToken.secretName | string | `""` | the name of the secret containing the kosli API token | | nameOverride | string | `""` | overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one | -| podAnnotations | object | `{}` | | +| podAnnotations | object | `{}` | any custom annotations to be added to the cronjob | | reporterConfig.dryRun | bool | `false` | whether the dry run mode is enabled or not. In dry run mode, the reporter logs the reports to stdout and does not send them to kosli. | | reporterConfig.kosliEnvironmentName | string | `""` | the name of kosli environment that the k8s cluster/namespace correlates to | | reporterConfig.kosliOrg | string | `""` | the name of the kosli org | @@ -74,5 +74,5 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter | serviceAccount.name | string | `""` | the name of the service account to use. If not set and create is true, a name is generated using the fullname template | ---------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0) +Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)