Skip to content

Commit

Permalink
Improve code for --name flag kosli-dev/server#882
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewelina Wilkosz committed Sep 5, 2023
1 parent 6306bfe commit edd0b41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions charts/k8s-reporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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)

25 changes: 10 additions & 15 deletions cmd/kosli/reportArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions cmd/kosli/testHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions docs.kosli.com/content/helm/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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)

0 comments on commit edd0b41

Please sign in to comment.