Class: Aws::SharedConfig Private
- Inherits:
-
Object
- Object
- Aws::SharedConfig
- Defined in:
- lib/aws-sdk-core/shared_config.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #config_path ⇒ String readonly private
- #credentials_path ⇒ String readonly private
- #profile_name ⇒ String readonly private
Instance Method Summary collapse
-
#assume_role_credentials_from_config(opts = {}) ⇒ Object
private
Attempts to assume a role from shared config or shared credentials file.
-
#config_enabled? ⇒ Boolean
private
Returns ‘true` if use of the shared config file is enabled.
-
#credentials(opts = {}) ⇒ Aws::Credentials
private
Sources static credentials from shared credential/config files.
- #endpoint_discovery(opts = {}) ⇒ Object private
- #fresh(options = {}) ⇒ Object private
-
#initialize(options = {}) ⇒ SharedConfig
constructor
private
Constructs a new SharedConfig provider object.
-
#loadable?(path) ⇒ Boolean
private
Returns ‘true` if a credential file exists and has appropriate read permissions at #path.
- #region(opts = {}) ⇒ Object private
Constructor Details
#initialize(options = {}) ⇒ SharedConfig
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Constructs a new SharedConfig provider object. This will load the shared credentials file, and optionally the shared configuration file, as ini files which support profiles.
By default, the shared credential file (the default path for which is ‘~/.aws/credentials`) and the shared config file (the default path for which is `~/.aws/config`) are loaded. However, if you set the `ENV` environment variable, only the shared credential file will be loaded.
The default profile name is ‘default’. You can specify the profile name with the ‘ENV` environment variable or with the `:profile_name` option.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aws-sdk-core/shared_config.rb', line 40 def initialize( = {}) @profile_name = determine_profile() @config_enabled = [:config_enabled] @credentials_path = [:credentials_path] || determine_credentials_path @parsed_credentials = {} load_credentials_file if loadable?(@credentials_path) if @config_enabled @config_path = [:config_path] || determine_config_path load_config_file if loadable?(@config_path) end end |
Instance Attribute Details
#config_path ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'lib/aws-sdk-core/shared_config.rb', line 10 def config_path @config_path end |
#credentials_path ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 |
# File 'lib/aws-sdk-core/shared_config.rb', line 7 def credentials_path @credentials_path end |
#profile_name ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/aws-sdk-core/shared_config.rb', line 13 def profile_name @profile_name end |
Instance Method Details
#assume_role_credentials_from_config(opts = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Attempts to assume a role from shared config or shared credentials file. Will always attempt first to assume a role from the shared credentials file, if present.
107 108 109 110 111 112 113 114 |
# File 'lib/aws-sdk-core/shared_config.rb', line 107 def assume_role_credentials_from_config(opts = {}) p = opts.delete(:profile) || @profile_name credentials = assume_role_from_profile(@parsed_credentials, p, opts) if @parsed_config credentials ||= assume_role_from_profile(@parsed_config, p, opts) end credentials end |
#config_enabled? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns ‘true` if use of the shared config file is enabled.
81 82 83 |
# File 'lib/aws-sdk-core/shared_config.rb', line 81 def config_enabled? @config_enabled ? true : false end |
#credentials(opts = {}) ⇒ Aws::Credentials
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sources static credentials from shared credential/config files.
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/aws-sdk-core/shared_config.rb', line 92 def credentials(opts = {}) p = opts[:profile] || @profile_name validate_profile_exists(p) if credentials_present? if credentials = credentials_from_shared(p, opts) credentials elsif credentials = credentials_from_config(p, opts) credentials else nil end end |
#endpoint_discovery(opts = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
131 132 133 134 135 136 |
# File 'lib/aws-sdk-core/shared_config.rb', line 131 def endpoint_discovery(opts = {}) p = opts[:profile] || @profile_name if @config_enabled && @parsed_config @parsed_config.fetch(p, {})["endpoint_discovery_enabled"] end end |
#fresh(options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/aws-sdk-core/shared_config.rb', line 54 def fresh( = {}) @profile_name = nil @credentials_path = nil @config_path = nil @parsed_credentials = {} @parsed_config = nil @config_enabled = [:config_enabled] ? true : false @profile_name = determine_profile() @credentials_path = [:credentials_path] || determine_credentials_path load_credentials_file if loadable?(@credentials_path) if @config_enabled @config_path = [:config_path] || determine_config_path load_config_file if loadable?(@config_path) end end |
#loadable?(path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method does not indicate if the file found at #path will be parsable, only if it can be read.
Returns ‘true` if a credential file exists and has appropriate read permissions at #path.
75 76 77 |
# File 'lib/aws-sdk-core/shared_config.rb', line 75 def loadable?(path) !path.nil? && File.exist?(path) && File.readable?(path) end |
#region(opts = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/aws-sdk-core/shared_config.rb', line 116 def region(opts = {}) p = opts[:profile] || @profile_name if @config_enabled if @parsed_credentials region = @parsed_credentials.fetch(p, {})["region"] end if @parsed_config region ||= @parsed_config.fetch(p, {})["region"] end region else nil end end |