Skip to content

Commit

Permalink
Merge pull request #31 from rightscale/support_eu
Browse files Browse the repository at this point in the history
Support Flexera One EU and other fixes
  • Loading branch information
douglaswth authored Mar 1, 2021
2 parents 756b1e0 + d059262 commit 9cef5d4
Show file tree
Hide file tree
Showing 87 changed files with 173 additions and 106 deletions.
29 changes: 22 additions & 7 deletions client/policy/applied_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ package policy

import (
"context"
"github.com/pkg/errors"
"github.com/rightscale/policy_sdk/sdk/applied_policy"
goahttp "goa.design/goa/v3/http"
"encoding/json"
"io"
"io/ioutil"
"net/http"

"github.com/pkg/errors"
appliedpolicy "github.com/rightscale/policy_sdk/sdk/applied_policy"
apclient "github.com/rightscale/policy_sdk/sdk/http/applied_policy/client"
goahttp "goa.design/goa/v3/http"
)

// CreateAppliedPolicy an applied policy
Expand Down Expand Up @@ -150,11 +153,23 @@ func (d *showLogDecoder) Decode(v interface{}) error {
return err
}

s, ok := v.(*string)
if !ok {
return errors.Errorf("expected type to be string, got %T", v)
switch t := v.(type) {
case *string:
*t = string(bodyBytes)
case *apclient.ShowLogNotFoundResponseBody:
if len(bodyBytes) > 0 {
json.Unmarshal(bodyBytes, t)
} else {
t.Name = strPtr("not_found")
t.ID = strPtr("missing")
t.Message = strPtr("log not found")
t.Temporary = boolPtr(false)
t.Timeout = boolPtr(false)
t.Fault = boolPtr(false)
}
default:
json.Unmarshal(bodyBytes, t)
}
*s = string(bodyBytes)
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion client/policy/policy_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"

"github.com/pkg/errors"
"github.com/rightscale/policy_sdk/sdk/policy_template"
policytemplate "github.com/rightscale/policy_sdk/sdk/policy_template"
)

// UploadPolicyTemplate a policy template
Expand Down Expand Up @@ -150,3 +150,4 @@ func (c *client) RetrieveData(ctx context.Context, templateID string, names []st
}

func strPtr(s string) *string { return &s }
func boolPtr(b bool) *bool { return &b }
7 changes: 7 additions & 0 deletions cmd/fpt/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v1.3.0 / 2021-03-01
-------------------
* Add support for Flexera One EU using `eu-central-1.policy-eu.flexeraeng.com` for the host configuration item
* Display Flexera One URLs in `fpt run` out when using Flexera One EU or the refresh token is for Flexera One
instead of RightScale
* Fix a bug where `fpt run` would hang trying to print the log after the policy execution completed

v1.2.2 / 2021-01-15
-------------------
* Fix a bug in `fpt script` parameter parsing where non-numeric bare parameters came through as `nil` and numeric
Expand Down
48 changes: 34 additions & 14 deletions cmd/fpt/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"time"

"github.com/pkg/errors"
goa "goa.design/goa/v3/pkg"

"github.com/rightscale/policy_sdk/client/policy"
"github.com/rightscale/policy_sdk/config"
appliedpolicy "github.com/rightscale/policy_sdk/sdk/applied_policy"
"github.com/rightscale/policy_sdk/sdk/incident"
policytemplate "github.com/rightscale/policy_sdk/sdk/policy_template"
Expand Down Expand Up @@ -96,19 +98,27 @@ func policyTemplateRun(ctx context.Context, cli policy.Client, file string, runO

log, logErr := cli.ShowAppliedPolicyLog(ctx, ap.ID, lastEtag)
if logErr != nil {
// Most logErrs are of the 304 Not Modified variety and can be ignored
continue
}
if *log.Etag == lastEtag {
continue
// technically the Goa client should not consider 304 an error
if strings.Contains(logErr.Error(), "invalid response code 304") {
goto checkStatus
}
// the log may not be available yet so we retry 404s
if gse, ok := logErr.(*goa.ServiceError); ok && gse.Name == "not_found" {
goto checkStatus
}
return logErr
}
lastSize := len(lastLog)
lastEtag = *log.Etag
lastLog = *log.ResponseBody
if !noLog {
fmt.Print(lastLog[lastSize:])

if *log.Etag != lastEtag {
lastSize := len(lastLog)
lastEtag = *log.Etag
lastLog = *log.ResponseBody
if !noLog {
fmt.Print(lastLog[lastSize:])
}
}

checkStatus:
//fmt.Printf("STATUS: %s\n", dump(status))
if status.LastEvaluationFinish != nil {
break
Expand Down Expand Up @@ -293,11 +303,21 @@ func dump(v interface{}) string {
}

func appliedPolicyUILink(ap *appliedpolicy.AppliedPolicy) string {
return fmt.Sprintf("https://governance.rightscale.com/org/%d/projects/%d/applied-policies/%s",
ap.Project.OrgID, ap.Project.ID, ap.ID)
host, flexera := config.Config.Account.AppHostAndIsFlexera()
if flexera {
return fmt.Sprintf("https://%s/orgs/%d/policy/projects/%d/applied-policies/%s",
host, ap.Project.OrgID, ap.Project.ID, ap.ID)
}
return fmt.Sprintf("https://%s/org/%d/projects/%d/applied-policies/%s",
host, ap.Project.OrgID, ap.Project.ID, ap.ID)
}

func incidentUILink(i *incident.Incident) string {
return fmt.Sprintf("https://governance.rightscale.com/org/%d/projects/%d/policy-incidents/%s",
i.Project.OrgID, i.Project.ID, i.ID)
host, flexera := config.Config.Account.AppHostAndIsFlexera()
if flexera {
return fmt.Sprintf("https://%s/orgs/%d/policy/projects/%d/incidents/%s",
host, i.Project.OrgID, i.Project.ID, i.ID)
}
return fmt.Sprintf("https://%s/org/%d/projects/%d/policy-incidents/%s",
host, i.Project.OrgID, i.Project.ID, i.ID)
}
28 changes: 26 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type (
var (
Config ConfigViper
boolRegexp = regexp.MustCompile(`^(?i:true)$`)
hostRegexp = regexp.MustCompile(`^governance-(\d+)\.(test.)?rightscale\.com$`)
hostRegexp = regexp.MustCompile(`^(?:governance-(\d+)\.(test.)?rightscale\.com|eu-central-1\.policy-eu\.flexeraeng\.com)$`)
)

func init() {
Expand Down Expand Up @@ -268,7 +268,9 @@ func (a *Account) AuthHost() string {
}
shardNum := matches[1]
testHost := matches[2]
if a.Flexera != nil && *a.Flexera {
if shardNum == "" {
return "login.flexera.eu"
} else if a.Flexera != nil && *a.Flexera {
if testHost != "" {
return "login.flexeratest.com"
}
Expand All @@ -284,3 +286,25 @@ func (a *Account) AuthHost() string {
return fmt.Sprintf("%s-%s.%srightscale.com", prefix, shardNum, testHost)
}
}

func (a *Account) AppHostAndIsFlexera() (string, bool) {
matches := hostRegexp.FindStringSubmatch(a.Host)
if len(matches) == 0 {
return "", false
}
shardNum := matches[1]
testHost := matches[2]
if shardNum == "" {
return "app.flexera.eu", true
} else if a.Flexera != nil && *a.Flexera {
if testHost != "" {
return "app.flexeratest.com", true
}
return "app.flexera.com", true
} else {
if testHost != "" {
return "governance.test.rightscale.com", false
}
return "governance.rightscale.com", false
}
}
2 changes: 1 addition & 1 deletion sdk/action_status/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/action_status/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/action_status/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/action_status/views/view.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/applied_policy/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/applied_policy/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/applied_policy/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/applied_policy/views/view.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/approval/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/approval/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/approval/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/approval/views/view.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/archived_incident/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/archived_incident/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/archived_incident/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/archived_incident/views/view.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/http/action_status/client/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/http/action_status/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/http/action_status/client/encode_decode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/http/action_status/client/paths.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/http/action_status/client/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/http/applied_policy/client/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/http/applied_policy/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9cef5d4

Please sign in to comment.