forked from uber/assume-role-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
66 lines (56 loc) · 2.07 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (c) 2018 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package assumerole
import (
"io/ioutil"
"time"
"github.com/ghodss/yaml"
)
// Config is the config for the AssumeRole app.
type Config struct {
// RefreshBeforeExpiry is a duration prior to the credentials expiring
// where we'll refresh them anyway. This is to prevent a command running
// just before credentials are about to expire. Defaults to 15m.
RefreshBeforeExpiry time.Duration `json:"refresh_before_expiry"`
// RolePrefix allows the user to specify a prefix for the role ARN that
// will be combined with what is specified as the role when executing the
// app. For example, if the prefix is "arn:aws:iam::123:role/" and the user
// executes the app with role "foobar", the final ARN will become:
// "arn:aws:iam::123:role/foobar".
RolePrefix string `json:"role_prefix"`
// ProfileNamePrefix is a prefix that will prepended to the role name to
// create the profile name under which the AWS configuration will be saved.
ProfileNamePrefix string `json:"profile_name_prefix"`
}
// SetDefaults sets any default values for unset variables.
func (c *Config) setDefaults() {
if c.RefreshBeforeExpiry == 0 {
c.RefreshBeforeExpiry = time.Minute * 15
}
}
// LoadConfig reads config values from a file and returns the config.
func LoadConfig(configFilePath string) (*Config, error) {
var config Config
b, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(b, &config)
if err != nil {
return nil, err
}
return &config, nil
}