Skip to content

Commit

Permalink
Merge pull request #664 from synfinatic/remove-deprecated
Browse files Browse the repository at this point in the history
Remove deprecated
  • Loading branch information
synfinatic authored Nov 1, 2023
2 parents f8ff509 + 25918ae commit 4976709
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 119 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@
* `aws-sso` commands other than `cache` and `login` no longer can trigger a cache refresh or
update of `~/.aws/config` file

### Removed Commands and Flags
### Removed Commands, Config Options and Flags
* Remove `config`, `config-profiles` and `completions` commands
and replace with `setup`
* Remove `flush` command. Use `logout`
* Remove `flush` command. Use `logout` instead
* Remove `--no-cache` flag
* Remove `CacheRefresh` configuration option. `aws-sso` will only update the cache
when you ask it to via `aws-sso cache`
* Remove `tags --force-update` flag
* Remove `AutoConfigCheck` configuration option.
* Remove references to all deprecated features:
* `AccountIdStr()` function for `ProfileFormat`.
* `AccountIdStr` field is replaced by `AccountIdPad` in `list` command and `ListFields` in config.yaml
* `ARN` field is replaced by `Arn` in `list` command and `ListFields` in config.yaml
* `ExpiresStr` field is replaced by `Expires` in `list` command and `ListFields` in config.yaml
* `FirefoxOpenUrlInContainer` config option
* `ConfigUrlAction` config option

## [v1.14.2] - 2023-10-19

Expand Down
1 change: 0 additions & 1 deletion cmd/aws-sso/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ var DEFAULT_CONFIG map[string]interface{} = map[string]interface{}{
"ConsoleDuration": 60,
"DefaultRegion": "us-east-1",
"DefaultSSO": "Default",
"FirefoxOpenUrlInContainer": false,
"FullTextSearch": true,
"HistoryLimit": 10,
"HistoryMinutes": 1440, // 24hrs
Expand Down
11 changes: 1 addition & 10 deletions cmd/aws-sso/setup_wizard_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ func setupWizard(ctx *RunContext, reconfig, addSSO, advanced bool) error {
`)

if reconfig {
// migrate old boolean flag to enum
if s.FirefoxOpenUrlInContainer {
s.UrlAction = url.OpenUrlContainer
}

// upgrade deprecated config option
if s.ConfigUrlAction != "" && s.ConfigProfilesUrlAction == "" {
s.ConfigProfilesUrlAction, _ = url.NewConfigProfilesAction(s.ConfigUrlAction)
s.ConfigUrlAction = ""
}
// Usually this is where we do migrations & upgrades for deprecations
// skips:
// - SSORegion
// - DefaultRegion
Expand Down
1 change: 0 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ By default, `ProfileFormat` is set to `{{ .AccountIdPad }}:{{ .RoleName }}`.
AWS SSO CLI uses [sprig](http://masterminds.github.io/sprig/) for most of its
functions, but a few custom functions are available:

* `AccountIdStr(x)` -- Converts the `.AccountId` variable to a string. Deprecated. Use `.AccountIdPad` variable instead.
* `EmptyString(x)` -- Returns true/false if the value `x` is an empty string
* `FirstItem([]x)` -- Returns the first item in a list that is not an empty string
* `StringsJoin(x, []y)` -- Joins the items in `y` with the string `x`
Expand Down
103 changes: 31 additions & 72 deletions sso/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,35 @@ const (
)

type Settings struct {
configFile string // name of this file
cacheFile string // name of cache file; always passed in via CLI args
Cache *Cache `yaml:"-"` // our cache data
SSO map[string]*SSOConfig `koanf:"SSOConfig" yaml:"SSOConfig,omitempty"`
DefaultSSO string `koanf:"DefaultSSO" yaml:"DefaultSSO,omitempty"` // specify default SSO by key
SecureStore string `koanf:"SecureStore" yaml:"SecureStore,omitempty"` // json or keyring
DefaultRegion string `koanf:"DefaultRegion" yaml:"DefaultRegion,omitempty"`
ConsoleDuration int32 `koanf:"ConsoleDuration" yaml:"ConsoleDuration,omitempty"`
JsonStore string `koanf:"JsonStore" yaml:"JsonStore,omitempty"`
Threads int `koanf:"Threads" yaml:"Threads,omitempty"`
MaxBackoff int `koanf:"MaxBackoff" yaml:"MaxBackoff,omitempty"`
MaxRetry int `koanf:"MaxRetry" yaml:"MaxRetry,omitempty"`
FirefoxOpenUrlInContainer bool `koanf:"FirefoxOpenUrlInContainer" yaml:"FirefoxOpenUrlInContainer,omitempty"` // deprecated
UrlAction url.Action `koanf:"UrlAction" yaml:"UrlAction"`
Browser string `koanf:"Browser" yaml:"Browser,omitempty"`
ConfigUrlAction string `koanf:"ConfigUrlAction" yaml:"ConfigUrlAction,omitempty"` // deprecated
ConfigProfilesBinaryPath string `koanf:"ConfigProfilesBinaryPath" yaml:"ConfigProfilesBinaryPath,omitempty"`
ConfigProfilesUrlAction url.ConfigProfilesAction `koanf:"ConfigProfilesUrlAction" yaml:"ConfigProfilesUrlAction,omitempty"`
UrlExecCommand []string `koanf:"UrlExecCommand" yaml:"UrlExecCommand,omitempty"` // string or list
LogLevel string `koanf:"LogLevel" yaml:"LogLevel,omitempty"`
LogLines bool `koanf:"LogLines" yaml:"LogLines,omitempty"`
HistoryLimit int64 `koanf:"HistoryLimit" yaml:"HistoryLimit,omitempty"`
HistoryMinutes int64 `koanf:"HistoryMinutes" yaml:"HistoryMinutes,omitempty"`
ProfileFormat string `koanf:"ProfileFormat" yaml:"ProfileFormat,omitempty"`
AccountPrimaryTag []string `koanf:"AccountPrimaryTag" yaml:"AccountPrimaryTag,omitempty"`
FirstTag string `koanf:"FirstTag" yaml:"FirstTag,omitempty"`
PromptColors PromptColors `koanf:"PromptColors" yaml:"PromptColors,omitempty"` // go-prompt colors
ListFields []string `koanf:"ListFields" yaml:"ListFields,omitempty"`
ConfigVariables map[string]interface{} `koanf:"ConfigVariables" yaml:"ConfigVariables,omitempty"`
EnvVarTags []string `koanf:"EnvVarTags" yaml:"EnvVarTags,omitempty"`
FullTextSearch bool `koanf:"FullTextSearch" yaml:"FullTextSearch"`
configFile string // name of this file
cacheFile string // name of cache file; always passed in via CLI args
Cache *Cache `yaml:"-"` // our cache data
SSO map[string]*SSOConfig `koanf:"SSOConfig" yaml:"SSOConfig,omitempty"`
DefaultSSO string `koanf:"DefaultSSO" yaml:"DefaultSSO,omitempty"` // specify default SSO by key
SecureStore string `koanf:"SecureStore" yaml:"SecureStore,omitempty"` // json or keyring
DefaultRegion string `koanf:"DefaultRegion" yaml:"DefaultRegion,omitempty"`
ConsoleDuration int32 `koanf:"ConsoleDuration" yaml:"ConsoleDuration,omitempty"`
JsonStore string `koanf:"JsonStore" yaml:"JsonStore,omitempty"`
Threads int `koanf:"Threads" yaml:"Threads,omitempty"`
MaxBackoff int `koanf:"MaxBackoff" yaml:"MaxBackoff,omitempty"`
MaxRetry int `koanf:"MaxRetry" yaml:"MaxRetry,omitempty"`
UrlAction url.Action `koanf:"UrlAction" yaml:"UrlAction"`
Browser string `koanf:"Browser" yaml:"Browser,omitempty"`
ConfigProfilesBinaryPath string `koanf:"ConfigProfilesBinaryPath" yaml:"ConfigProfilesBinaryPath,omitempty"`
ConfigProfilesUrlAction url.ConfigProfilesAction `koanf:"ConfigProfilesUrlAction" yaml:"ConfigProfilesUrlAction,omitempty"`
UrlExecCommand []string `koanf:"UrlExecCommand" yaml:"UrlExecCommand,omitempty"` // string or list
LogLevel string `koanf:"LogLevel" yaml:"LogLevel,omitempty"`
LogLines bool `koanf:"LogLines" yaml:"LogLines,omitempty"`
HistoryLimit int64 `koanf:"HistoryLimit" yaml:"HistoryLimit,omitempty"`
HistoryMinutes int64 `koanf:"HistoryMinutes" yaml:"HistoryMinutes,omitempty"`
ProfileFormat string `koanf:"ProfileFormat" yaml:"ProfileFormat,omitempty"`
AccountPrimaryTag []string `koanf:"AccountPrimaryTag" yaml:"AccountPrimaryTag,omitempty"`
FirstTag string `koanf:"FirstTag" yaml:"FirstTag,omitempty"`
PromptColors PromptColors `koanf:"PromptColors" yaml:"PromptColors,omitempty"` // go-prompt colors
ListFields []string `koanf:"ListFields" yaml:"ListFields,omitempty"`
ConfigVariables map[string]interface{} `koanf:"ConfigVariables" yaml:"ConfigVariables,omitempty"`
EnvVarTags []string `koanf:"EnvVarTags" yaml:"EnvVarTags,omitempty"`
FullTextSearch bool `koanf:"FullTextSearch" yaml:"FullTextSearch"`
}

// GetDefaultRegion scans the config settings file to pick the most local DefaultRegion from the tree
Expand Down Expand Up @@ -220,47 +218,8 @@ func (s *Settings) Validate() error {
// applyDeprecations migrates old config options to the new one and returns true
// if we made a change
func (s *Settings) applyDeprecations() bool {
var change = false
var err error

// Upgrade ConfigUrlAction to ConfigProfilesUrlAction because we want to
// deprecate ConfigUrlAction.
if s.ConfigUrlAction != "" && s.ConfigProfilesUrlAction == "" {
s.ConfigProfilesUrlAction, err = url.NewConfigProfilesAction(s.ConfigUrlAction)
if err != nil {
log.Warnf("Invalid value for ConfigUrlAction: %s", s.ConfigUrlAction)
}
s.ConfigUrlAction = string(url.Undef) // disable old value so it is omitempty
change = true
}

// Upgrade FirefoxOpenUrlInContainer to UrlAction = open-url-in-container
if s.FirefoxOpenUrlInContainer {
s.UrlAction = url.OpenUrlContainer
s.FirefoxOpenUrlInContainer = false // disable old value so it is omitempty
change = true
}

// ExpiresStr => Expires in v1.11.0
// AccountIdStr => AccountIdPad v1.11.0
// ARN => Arn v1.11.0
if len(s.ListFields) > 0 {
for i, v := range s.ListFields {
switch v {
case "ExpiresStr":
s.ListFields[i] = "Expires"
case "AccountIdStr":
s.ListFields[i] = "AccountIdPad"
case "ARN":
s.ListFields[i] = "Arn"
}
}
}

// AccountIdStr .AccountId => .AccountIdPad in v1.11.0
s.ProfileFormat = strings.ReplaceAll(s.ProfileFormat, "AccountIdStr .AccountId", ".AccountIdPad")

return change
// no deprecations yet in v2.0 :)
return false
}

// Save overwrites the current config file with our settings (not recommended)
Expand Down
33 changes: 1 addition & 32 deletions sso/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ func (suite *SettingsTestSuite) TestLoadSettings() {
t := suite.T()

assert.Equal(t, TEST_SETTINGS_FILE, suite.settings.ConfigFile())

// ensure we upgraded ConfigUrlAction to ConfigProfilesUrlAction
assert.Equal(t, "", suite.settings.ConfigUrlAction)
assert.Equal(t, url.ConfigProfilesOpen, suite.settings.ConfigProfilesUrlAction)

// ensure we upgraded FirefoxOpenUrlInContainer
assert.False(t, suite.settings.FirefoxOpenUrlInContainer)
assert.Equal(t, url.OpenUrlContainer, suite.settings.UrlAction)
}

func (suite *SettingsTestSuite) TestGetSelectedSSO() {
Expand Down Expand Up @@ -331,30 +323,7 @@ func TestCreatedAt(t *testing.T) {
}

func TestApplyDeprecations(t *testing.T) {
s := &Settings{
ListFields: []string{"Foo", "Bar", "ExpiresStr", "AccountIdStr", "ARN"},
ProfileFormat: "{{ AccountIdStr .AccountId }}:{{ .RoleName }}",
FirefoxOpenUrlInContainer: true,
ConfigProfilesUrlAction: url.ConfigProfilesUndef,
ConfigUrlAction: string(url.Exec),
}

r := s.applyDeprecations()
assert.True(t, r)

// Upgrade ConfigUrlAction to ConfigProfilesUrlAction
assert.Equal(t, string(url.Undef), s.ConfigUrlAction)
assert.Equal(t, url.ConfigProfilesExec, s.ConfigProfilesUrlAction)

// Upgrade FirefoxOpenUrlInContainer to UrlAction
assert.Equal(t, url.OpenUrlContainer, s.UrlAction)
assert.Equal(t, false, s.FirefoxOpenUrlInContainer)

// ExpiresStr => Expires, etc
assert.Equal(t, []string{"Foo", "Bar", "Expires", "AccountIdPad", "Arn"}, s.ListFields)

// AccountIdStr .AccountId => .AccountIdPad
assert.Equal(t, "{{ .AccountIdPad }}:{{ .RoleName }}", s.ProfileFormat)
// as of v2.0 it does nothing...
}

func TestGetExecutable(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion sso/testdata/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ SSOConfig:
DefaultSSO: Default
Browser: /Applications/Firefox.app
UrlAction: print
FirefoxOpenUrlInContainer: true
SecureStore: json
JsonStore: ./testdata/store.json
ProfileFormat: '{{.AccountName}}/{{.RoleName}}'
Expand Down

0 comments on commit 4976709

Please sign in to comment.