Skip to content

Commit

Permalink
use bearer token for API auth (#369)
Browse files Browse the repository at this point in the history
* use bearer token for auth

* update docs for using API keys with API
  • Loading branch information
sami-alajrami authored Oct 28, 2024
1 parent 6c64d88 commit c23eac4
Show file tree
Hide file tree
Showing 65 changed files with 310 additions and 309 deletions.
10 changes: 5 additions & 5 deletions cmd/kosli/allowArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ func (o *allowArtifactOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/allowlists/%s/%s", global.Host, global.Org, o.environmentName)

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/archiveEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func newArchiveEnvironmentCmd(out io.Writer) *cobra.Command {
url := fmt.Sprintf("%s/api/v2/environments/%s/%s/archive", global.Host, global.Org, args[0])

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Payload: payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/archiveFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func newArchiveFlowCmd(out io.Writer) *cobra.Command {
url := fmt.Sprintf("%s/api/v2/flows/%s/%s/archive", global.Host, global.Org, args[0])

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Payload: payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/assertApproval.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ 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)

reqParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
Password: global.ApiToken,
Method: http.MethodGet,
URL: url,
Token: global.ApiToken,
}
response, err := kosliClient.Do(reqParams)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/assertArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func (o *assertArtifactOptions) run(out io.Writer, args []string) error {
url := fmt.Sprintf("%s/api/v2/artifacts/%s/%s/fingerprint/%s", global.Host, global.Org, o.flowName, o.fingerprint)

reqParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
Password: global.ApiToken,
Method: http.MethodGet,
URL: url,
Token: global.ApiToken,
}
response, err := kosliClient.Do(reqParams)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/assertSnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func run(out io.Writer, args []string) error {
url := fmt.Sprintf("%s/api/v2/snapshots/%s/%s/%d", global.Host, global.Org, envName, id)

reqParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
Password: global.ApiToken,
Method: http.MethodGet,
URL: url,
Token: global.ApiToken,
}
response, err := kosliClient.Do(reqParams)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/attachPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func (o *attachPolicyOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/environments/%s/%s/policies", global.Host, global.Org, env)
o.payload.PolicyNames = []string{args[0]}
reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/attestArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ func (o *attestArtifactOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/artifacts/%s/%s", global.Host, global.Org, o.flowName)

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/attestGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ func (o *attestGenericOptions) run(args []string) error {
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/attestJira.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ func (o *attestJiraOptions) run(args []string) error {
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/attestJunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ func (o *attestJunitOptions) run(args []string) error {
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/attestSnyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ func (o *attestSnykOptions) run(args []string) error {
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/attestSonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ func (o *attestSonarOptions) run(args []string) error {
}

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/beginTrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ func (o *beginTrailOptions) run(args []string) error {
}

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}

res, err := kosliClient.Do(reqParams)
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/createEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func (o *createEnvOptions) run(args []string) error {
o.payload.IncludeScaling = &myFalse
}
reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
20 changes: 10 additions & 10 deletions cmd/kosli/createFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,23 @@ func (o *createFlowOptions) run(args []string) error {
}

reqParams = &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}
} else {
// legacy flows
url = fmt.Sprintf("%s/api/v2/flows/%s", global.Host, global.Org)
o.payload.Template = injectArtifactIntoTemplateIfNotExisting(o.payload.Template)

reqParams = &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/createPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func (o *createPolicyOptions) run(args []string) error {
}

reqParams = &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Form: form,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Form: form,
DryRun: global.DryRun,
Token: global.ApiToken,
}

res, err := kosliClient.Do(reqParams)
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/detachPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func (o *detachPolicyOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/environments/%s/%s/policies", global.Host, global.Org, env)
o.payload.PolicyNames = []string{args[0]}
reqParams := &requests.RequestParams{
Method: http.MethodDelete,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodDelete,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/diffSnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func (o *diffSnapshotsOptions) run(out io.Writer, args []string) error {
global.Host, global.Org, url.QueryEscape(snappish1), url.QueryEscape(snappish2))

reqParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
Password: global.ApiToken,
Method: http.MethodGet,
URL: url,
Token: global.ApiToken,
}
response, err := kosliClient.Do(reqParams)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/disableBeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func (o *betaOptions) run(args []string) error {
}

reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPut,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
10 changes: 5 additions & 5 deletions cmd/kosli/expectDeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ func (o *expectDeploymentOptions) run(args []string) error {
url := fmt.Sprintf("%s/api/v2/deployments/%s/%s", global.Host, global.Org, o.flowName)

reqParams := &requests.RequestParams{
Method: http.MethodPost,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Password: global.ApiToken,
Method: http.MethodPost,
URL: url,
Payload: o.payload,
DryRun: global.DryRun,
Token: global.ApiToken,
}
_, err = kosliClient.Do(reqParams)
if err == nil && !global.DryRun {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/getApproval.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func (o *getApprovalOptions) run(out io.Writer, args []string) error {
url := fmt.Sprintf("%s/api/v2/approvals/%s/%s/%d", global.Host, global.Org, flowName, id)

reqParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
Password: global.ApiToken,
Method: http.MethodGet,
URL: url,
Token: global.ApiToken,
}
response, err := kosliClient.Do(reqParams)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/getArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func (o *getArtifactOptions) run(out io.Writer, args []string) error {
url = url + fmt.Sprintf("?trail=%s", o.trail)
}
reqParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
Password: global.ApiToken,
Method: http.MethodGet,
URL: url,
Token: global.ApiToken,
}

response, err := kosliClient.Do(reqParams)
Expand Down
6 changes: 3 additions & 3 deletions cmd/kosli/getDeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func (o *getDeploymentOptions) run(out io.Writer, args []string) error {
url := fmt.Sprintf("%s/api/v2/deployments/%s/%s/%d", global.Host, global.Org, flowName, id)

reqParams := &requests.RequestParams{
Method: http.MethodGet,
URL: url,
Password: global.ApiToken,
Method: http.MethodGet,
URL: url,
Token: global.ApiToken,
}
response, err := kosliClient.Do(reqParams)
if err != nil {
Expand Down
Loading

0 comments on commit c23eac4

Please sign in to comment.