Skip to content
Merged
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
44 changes: 9 additions & 35 deletions cmd/kosli/attestCustom.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -157,12 +153,7 @@ func newAttestCustomCmd(out io.Writer) *cobra.Command {
}

func (o *attestCustomOptions) run(args []string) error {
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "custom")
if err != nil {
return err
}

err = o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
err := o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
if err != nil {
return err
}
Expand All @@ -172,29 +163,12 @@ func (o *attestCustomOptions) run(args []string) error {
return fmt.Errorf("failed to load attestation data. %s", err)
}

form, cleanupNeeded, evidencePath, err := prepareAttestationForm(o.payload, o.attachments)
if err != nil {
return err
}
// if we created a tar package, remove it after uploading it
if cleanupNeeded {
defer func() {
if err := os.Remove(evidencePath); err != nil {
logger.Warn("failed to remove evidence file: %v", err)
}
}()
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("custom:%s attestation '%s' is reported to trail: %s", o.payload.TypeName, o.payload.AttestationName, o.trailName)
}
return wrapAttestationError(err)
return newAttestationSubmitter().submit(attestationSubmission{
flow: o.flowName,
trail: o.trailName,
slug: "custom",
label: "custom:" + o.payload.TypeName,
payload: o.payload,
attachments: o.attachments,
})
}
43 changes: 9 additions & 34 deletions cmd/kosli/attestDecision.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -153,38 +149,17 @@ func newAttestDecisionCmd(out io.Writer) *cobra.Command {
}

func (o *attestDecisionOptions) run(args []string) error {
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "system")
err := o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
if err != nil {
return err
}

err = o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
if err != nil {
return err
}

form, cleanupNeeded, evidencePath, err := prepareAttestationForm(o.payload, o.attachments)
if err != nil {
return err
}
if cleanupNeeded {
defer func() {
if err := os.Remove(evidencePath); err != nil {
logger.Warn("failed to remove evidence file: %v", err)
}
}()
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("decision attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}
return wrapAttestationError(err)
return newAttestationSubmitter().submit(attestationSubmission{
flow: o.flowName,
trail: o.trailName,
slug: "system",
label: "decision",
payload: o.payload,
attachments: o.attachments,
})
}
44 changes: 9 additions & 35 deletions cmd/kosli/attestGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -150,39 +146,17 @@ func newAttestGenericCmd(out io.Writer) *cobra.Command {
}

func (o *attestGenericOptions) run(args []string) error {
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "generic")
err := o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
if err != nil {
return err
}

err = o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
if err != nil {
return err
}

form, cleanupNeeded, evidencePath, err := prepareAttestationForm(o.payload, o.attachments)
if err != nil {
return err
}
// if we created a tar package, remove it after uploading it
if cleanupNeeded {
defer func() {
if err := os.Remove(evidencePath); err != nil {
logger.Warn("failed to remove evidence file: %v", err)
}
}()
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("generic attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}
return wrapAttestationError(err)
return newAttestationSubmitter().submit(attestationSubmission{
flow: o.flowName,
trail: o.trailName,
slug: "generic",
label: "generic",
payload: o.payload,
attachments: o.attachments,
})
}
67 changes: 17 additions & 50 deletions cmd/kosli/attestJira.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"regexp"
"slices"
"strings"
"unicode"

"github.com/kosli-dev/cli/internal/gitview"
"github.com/kosli-dev/cli/internal/jira"
"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -325,13 +321,8 @@ func newAttestJiraCmd(out io.Writer) *cobra.Command {
}

func (o *attestJiraOptions) run(args []string) error {
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "jira")
if err != nil {
return err
}

o.commitRequiredFor = "search for Jira issue keys"
err = o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
err := o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
if err != nil {
return err
}
Expand Down Expand Up @@ -418,53 +409,29 @@ func (o *attestJiraOptions) run(args []string) error {
logger.Warn("%s", jiraUnconfirmedWarning(unconfirmedIDs, unconfirmedReasons))
}

form, cleanupNeeded, evidencePath, err := prepareAttestationForm(o.payload, o.attachments)
if err != nil {
return err
}
// if we created a tar package, remove it after uploading it
if cleanupNeeded {
defer func() {
if err := os.Remove(evidencePath); err != nil {
logger.Warn("failed to remove evidence file: %v", err)
}
}()
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
var assertFailures []error
if o.assert && len(issueIDs) == 0 {
assertFailures = append(assertFailures, fmt.Errorf("no Jira references are found in %s", issueSource))
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("jira attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}

if len(issueIDs) == 0 && o.assert && !global.DryRun {
errString := ""
if err != nil {
errString = fmt.Sprintf("%s\nError: ", err.Error())
}
err = fmt.Errorf("%sno Jira references are found in %s", errString, issueSource)
}

if issueFoundCount != len(issueIDs) && o.assert && !global.DryRun {
errString := ""
if err != nil {
errString = fmt.Sprintf("%s\nError: ", err.Error())
}
if o.assert && issueFoundCount != len(issueIDs) {
// prefixed, so it does not read as another entry in the issue list it follows
reasonLog := ""
for _, reason := range unconfirmedReasons {
reasonLog += fmt.Sprintf("\n\treason: %s", reason)
}
err = fmt.Errorf("%s%s from references found in %s%s%s", errString,
jiraAssertHeadline(len(issueIDs)-issueFoundCount-len(unconfirmedIDs), len(unconfirmedIDs)), issueSource, issueLog, reasonLog)
assertFailures = append(assertFailures, fmt.Errorf("%s from references found in %s%s%s",
jiraAssertHeadline(len(issueIDs)-issueFoundCount-len(unconfirmedIDs), len(unconfirmedIDs)), issueSource, issueLog, reasonLog))
}
return wrapAttestationError(err)

return newAttestationSubmitter().submit(attestationSubmission{
flow: o.flowName,
trail: o.trailName,
slug: "jira",
label: "jira",
payload: o.payload,
attachments: o.attachments,
assertFailures: assertFailures,
})
}

// jiraAssertHeadline names what went wrong in the first line of an --assert failure. A
Expand Down
44 changes: 9 additions & 35 deletions cmd/kosli/attestJunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import (
"fmt"
"io"
"io/fs"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"time"

junit "github.com/joshdk/go-junit"
"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -155,12 +151,7 @@ func newAttestJunitCmd(out io.Writer) *cobra.Command {
}

func (o *attestJunitOptions) run(args []string) error {
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "junit")
if err != nil {
return err
}

err = o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
err := o.CommonAttestationOptions.run(args, o.payload.CommonAttestationPayload)
if err != nil {
return err
}
Expand All @@ -175,31 +166,14 @@ func (o *attestJunitOptions) run(args []string) error {
o.attachments = append(o.attachments, junitFilenames...)
}

form, cleanupNeeded, evidencePath, err := prepareAttestationForm(o.payload, o.attachments)
if err != nil {
return err
}
// if we created a tar package, remove it after uploading it
if cleanupNeeded {
defer func() {
if err := os.Remove(evidencePath); err != nil {
logger.Warn("failed to remove evidence file %s: %v", evidencePath, err)
}
}()
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("junit attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}
return wrapAttestationError(err)
return newAttestationSubmitter().submit(attestationSubmission{
flow: o.flowName,
trail: o.trailName,
slug: "junit",
label: "junit",
payload: o.payload,
attachments: o.attachments,
})
}

type JUnitResults struct {
Expand Down
Loading
Loading