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
9 changes: 6 additions & 3 deletions cmd/kosli/allowArtifact.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"io"
"net/http"
"net/url"
"path/filepath"

"github.com/kosli-dev/cli/internal/requests"
Expand Down Expand Up @@ -82,7 +82,10 @@ func (o *allowArtifactOptions) run(args []string) error {
}
}

url := fmt.Sprintf("%s/api/v2/allowlists/%s/%s", global.Host, global.Org, o.environmentName)
url, err := url.JoinPath(global.Host, "api/v2/allowlists", global.Org, o.environmentName)
if err != nil {
return err
}

reqParams := &requests.RequestParams{
Method: http.MethodPut,
Expand All @@ -91,7 +94,7 @@ func (o *allowArtifactOptions) run(args []string) error {
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("artifact %s was allow listed in environment: %s", o.payload.Fingerprint, o.environmentName)
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/kosli/archiveAttestationType.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,15 +38,18 @@ func newArchiveAttestationTypeCmd(out io.Writer) *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
url := fmt.Sprintf("%s/api/v2/custom-attestation-types/%s/%s/archive", global.Host, global.Org, args[0])
url, err := url.JoinPath(global.Host, "api/v2/custom-attestation-types", global.Org, args[0], "archive")
if err != nil {
return err
}

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("Custom attestation type %s was archived", args[0])
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/kosli/archiveEnvironment.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,15 +38,18 @@ func newArchiveEnvironmentCmd(out io.Writer) *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
url := fmt.Sprintf("%s/api/v2/environments/%s/%s/archive", global.Host, global.Org, args[0])
url, err := url.JoinPath(global.Host, "api/v2/environments", global.Org, args[0], "archive")
if err != nil {
return err
}

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("environment %s was archived", args[0])
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/kosli/archiveFlow.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,15 +38,18 @@ func newArchiveFlowCmd(out io.Writer) *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
url := fmt.Sprintf("%s/api/v2/flows/%s/%s/archive", global.Host, global.Org, args[0])
url, err := url.JoinPath(global.Host, "api/v2/flows", global.Org, args[0], "archive")
if err != nil {
return err
}

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
logger.Info("flow %s was archived", args[0])
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/kosli/assertApproval.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -93,7 +94,10 @@ func (o *assertApprovalOptions) run(args []string) error {
}
}

url := fmt.Sprintf("%s/api/v2/artifacts/%s/%s/%s/approvals", global.Host, global.Org, o.flowName, o.fingerprint)
url, err := url.JoinPath(global.Host, "api/v2/artifacts", global.Org, o.flowName, o.fingerprint, "approvals")
if err != nil {
return err
}

reqParams := &requests.RequestParams{
Method: http.MethodGet,
Expand Down
5 changes: 4 additions & 1 deletion cmd/kosli/assertArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ func (o *assertArtifactOptions) run(out io.Writer, args []string) error {
}
}

baseURL := fmt.Sprintf("%s/api/v2/asserts/%s/fingerprint/%s", global.Host, global.Org, o.fingerprint)
baseURL, err := url.JoinPath(global.Host, "api/v2/asserts", global.Org, "fingerprint", o.fingerprint)
if err != nil {
return err
}
params := url.Values{}

if o.flowName != "" {
Expand Down
7 changes: 6 additions & 1 deletion cmd/kosli/assertSnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strconv"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -61,7 +63,10 @@ func run(out io.Writer, args []string) error {
if err != nil {
return err
}
url := fmt.Sprintf("%s/api/v2/snapshots/%s/%s/%d", global.Host, global.Org, envName, id)
url, err := url.JoinPath(global.Host, "api/v2/snapshots", global.Org, envName, strconv.Itoa(id))
if err != nil {
return err
}

reqParams := &requests.RequestParams{
Method: http.MethodGet,
Expand Down
7 changes: 5 additions & 2 deletions cmd/kosli/attachPolicy.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -65,7 +65,10 @@ func newAttachPolicyCmd(out io.Writer) *cobra.Command {
func (o *attachPolicyOptions) run(args []string) error {
var err error
for _, env := range o.environments {
url := fmt.Sprintf("%s/api/v2/environments/%s/%s/policies", global.Host, global.Org, env)
url, err := url.JoinPath(global.Host, "api/v2/environments", global.Org, env, "policies")
if err != nil {
return err
}
o.payload.PolicyNames = []string{args[0]}
reqParams := &requests.RequestParams{
Method: http.MethodPost,
Expand Down
6 changes: 5 additions & 1 deletion cmd/kosli/attestArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"path/filepath"

"github.com/kosli-dev/cli/internal/gitview"
Expand Down Expand Up @@ -201,7 +202,10 @@ func (o *attestArtifactOptions) run(args []string) error {
logger.Warn("Repo URL will not be reported, %s", err.Error())
}

url := fmt.Sprintf("%s/api/v2/artifacts/%s/%s", global.Host, global.Org, o.flowName)
url, err := url.JoinPath(global.Host, "api/v2/artifacts", global.Org, o.flowName)
if err != nil {
return err
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
Expand Down
8 changes: 6 additions & 2 deletions cmd/kosli/attestCustom.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"

"github.com/kosli-dev/cli/internal/requests"
Expand Down Expand Up @@ -152,9 +153,12 @@ func newAttestCustomCmd(out io.Writer) *cobra.Command {
}

func (o *attestCustomOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/attestations/%s/%s/trail/%s/custom", global.Host, global.Org, o.flowName, o.trailName)
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 Down
8 changes: 6 additions & 2 deletions cmd/kosli/attestGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"

"github.com/kosli-dev/cli/internal/requests"
Expand Down Expand Up @@ -145,9 +146,12 @@ func newAttestGenericCmd(out io.Writer) *cobra.Command {
}

func (o *attestGenericOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/attestations/%s/%s/trail/%s/generic", global.Host, global.Org, o.flowName, o.trailName)
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "generic")
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 Down
8 changes: 6 additions & 2 deletions cmd/kosli/attestJira.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -250,9 +251,12 @@ func newAttestJiraCmd(out io.Writer) *cobra.Command {
}

func (o *attestJiraOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/attestations/%s/%s/trail/%s/jira", global.Host, global.Org, o.flowName, o.trailName)
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "jira")
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 Down
8 changes: 6 additions & 2 deletions cmd/kosli/attestJunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -149,9 +150,12 @@ func newAttestJunitCmd(out io.Writer) *cobra.Command {
}

func (o *attestJunitOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/attestations/%s/%s/trail/%s/junit", global.Host, global.Org, o.flowName, o.trailName)
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 Down
8 changes: 6 additions & 2 deletions cmd/kosli/attestSnyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"

"github.com/kosli-dev/cli/internal/requests"
Expand Down Expand Up @@ -162,9 +163,12 @@ func newAttestSnykCmd(out io.Writer) *cobra.Command {
}

func (o *attestSnykOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/attestations/%s/%s/trail/%s/snyk", global.Host, global.Org, o.flowName, o.trailName)
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "snyk")
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 Down
9 changes: 6 additions & 3 deletions cmd/kosli/attestSonar.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"io"
"net/http"
"net/url"
"os"

"github.com/kosli-dev/cli/internal/requests"
Expand Down Expand Up @@ -175,9 +175,12 @@ func newAttestSonarCmd(out io.Writer) *cobra.Command {
}

func (o *attestSonarOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/attestations/%s/%s/trail/%s/sonar", global.Host, global.Org, o.flowName, o.trailName)
url, err := url.JoinPath(global.Host, "api/v2/attestations", global.Org, o.flowName, "trail", o.trailName, "sonar")
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 Down
7 changes: 5 additions & 2 deletions cmd/kosli/beginTrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"

"github.com/kosli-dev/cli/internal/gitview"
"github.com/kosli-dev/cli/internal/requests"
Expand Down Expand Up @@ -101,11 +102,13 @@ func newBeginTrailCmd(out io.Writer) *cobra.Command {
}

func (o *beginTrailOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/trails/%s/%s", global.Host, global.Org, o.flow)
url, err := url.JoinPath(global.Host, "api/v2/trails", global.Org, o.flow)
if err != nil {
return err
}

o.payload.Name = args[0]

var err error
o.payload.UserData, err = LoadJsonData(o.userDataFile)
if err != nil {
return err
Expand Down
Loading