Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RHOAS_VERSION ?= "dev"
REPOSITORY_OWNER ?= "redhat-developer"
REPOSITORY_NAME ?= "app-services-cli"
TERMS_REVIEW_EVENT_CODE ?= "register"
TERMS_REVIEW_SITE_CODE ?= "ocm"
TERMS_SPEC_URL ?= "https://raw.githubusercontent.com/redhat-developer/app-services-ui/main/static/configs/terms-conditions-spec.json"
SSO_REDIRECT_PATH ?= "sso-redhat-callback"
MAS_SSO_REDIRECT_PATH ?= "mas-sso-callback"

Expand All @@ -17,8 +17,7 @@ DEFAULT_PAGE_SIZE ?= "10"
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.Version=$(RHOAS_VERSION) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.RepositoryOwner=$(REPOSITORY_OWNER) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.RepositoryName=$(REPOSITORY_NAME) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.TermsReviewEventCode=$(TERMS_REVIEW_EVENT_CODE) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.TermsReviewSiteCode=$(TERMS_REVIEW_SITE_CODE) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.TermsReviewSpecURL=$(TERMS_SPEC_URL) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.DefaultPageSize=$(DEFAULT_PAGE_SIZE) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.DefaultPageNumber=$(DEFAULT_PAGE_NUMBER) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.SSORedirectPath=$(SSO_REDIRECT_PATH) $(GO_LDFLAGS)
Expand Down
7 changes: 2 additions & 5 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ var (
// RepositoryName is the remote GitHub repository for the releases
RepositoryName = "app-services-cli"

// TermsReviewEventCode is the event code used when checking the terms review
TermsReviewEventCode = "register"

// TermsReviewSiteCode is the site code used when checking the terms review
TermsReviewSiteCode = "ocm"
// TermsReviewSpecURL Url used to download terms and conditions specification
TermsReviewSpecURL = "https://raw.githubusercontent.com/redhat-developer/app-services-ui/main/static/configs/terms-conditions-spec.json"

// DefaultPageSize is the default number of items per page when using list commands
DefaultPageSize = "10"
Expand Down
12 changes: 12 additions & 0 deletions pkg/ams/TermsAndConditionsSpec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ams

type TermsAndConditionsSpec struct {
Kafka ServiceTermsSpec `json:"kafka"`
ServiceRegistry ServiceTermsSpec `json:"service-registry"`
}

type ServiceTermsSpec struct {
EventCode string `json:"EventCode"`
SiteCode string `json:"SiteCode"`
StopOnTermsChange bool `json:"StopOnTermsChange"`
}
7 changes: 3 additions & 4 deletions pkg/ams/ams.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import (
"context"
"errors"

"github.com/redhat-developer/app-services-cli/internal/build"
"github.com/redhat-developer/app-services-cli/pkg/api/ams/amsclient"
"github.com/redhat-developer/app-services-cli/pkg/connection"
)

func CheckTermsAccepted(ctx context.Context, conn connection.Connection) (accepted bool, redirectURI string, err error) {
func CheckTermsAccepted(ctx context.Context, spec ServiceTermsSpec, conn connection.Connection) (accepted bool, redirectURI string, err error) {
termsReview, _, err := conn.API().AccountMgmt().
ApiAuthorizationsV1SelfTermsReviewPost(ctx).
SelfTermsReview(amsclient.SelfTermsReview{
EventCode: &build.TermsReviewEventCode,
SiteCode: &build.TermsReviewSiteCode,
EventCode: &spec.EventCode,
SiteCode: &spec.SiteCode,
}).
Execute()
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions pkg/ams/terms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ams

import (
"encoding/json"
"io/ioutil"
"net/http"

"github.com/redhat-developer/app-services-cli/internal/build"
)

var fallbackTocSpec = []byte(`{
"kafka":{
"EventCode":"register",
"SiteCode":"ocm",
"StopOnTermsChange": true
},
"service-registry":{
"EventCode":"onlineService",
"SiteCode":"ocm",
"StopOnTermsChange": true
}
}
`)

func GetRemoteTermsSpec() TermsAndConditionsSpec {
response, err := http.Get(build.TermsReviewSpecURL)

var specJson []byte
if err != nil {
// TODO log error?
specJson = fallbackTocSpec
} else {
specJson, err = ioutil.ReadAll(response.Body)
if err != nil {
// TODO log error?
specJson = fallbackTocSpec
}
}

var termsAndConditionsSpec TermsAndConditionsSpec
json.Unmarshal([]byte(specJson), &termsAndConditionsSpec)
return termsAndConditionsSpec
}
3 changes: 2 additions & 1 deletion pkg/cmd/kafka/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func runCreate(opts *options) error {

// the user must have accepted the terms and conditions from the provider
// before they can create a kafka instance
termsAccepted, termsURL, err := ams.CheckTermsAccepted(opts.Context, conn)
termsSpec := ams.GetRemoteTermsSpec()
termsAccepted, termsURL, err := ams.CheckTermsAccepted(opts.Context, termsSpec.Kafka, conn)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/registry/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"fmt"

"github.com/redhat-developer/app-services-cli/pkg/ams"
"github.com/redhat-developer/app-services-cli/pkg/icon"

"github.com/redhat-developer/app-services-cli/pkg/localize"
"github.com/redhat-developer/app-services-cli/pkg/serviceregistry"

"github.com/redhat-developer/app-services-cli/pkg/ams"
"github.com/redhat-developer/app-services-cli/pkg/cmd/flag"
flagutil "github.com/redhat-developer/app-services-cli/pkg/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/connection"
Expand Down Expand Up @@ -119,7 +119,8 @@ func runCreate(opts *options) error {

// the user must have accepted the terms and conditions from the provider
// before they can create a registry instance
termsAccepted, termsURL, err := ams.CheckTermsAccepted(opts.Context, conn)
termsSpec := ams.GetRemoteTermsSpec()
termsAccepted, termsURL, err := ams.CheckTermsAccepted(opts.Context, termsSpec.ServiceRegistry, conn)
if err != nil {
return err
}
Expand Down