diff options
| author | Mark Harrison <mark@mivok.net> | 2018-06-15 12:29:01 -0400 |
|---|---|---|
| committer | Mark Harrison <mark@mivok.net> | 2018-06-15 15:37:53 -0400 |
| commit | 3dcdf7934687db2313df88ce33dcd308c6edd01d (patch) | |
| tree | 2c55c2fe61f34dd6eff64b8bfde77c2a6068bdbd | |
| parent | aa4f3285f3e49919e29f40337183fd0510baaee5 (diff) | |
| download | chef-mh/missing_profile.tar.gz | |
Don't crash on non-existent credentials profilemh/missing_profile
If a credentials file exists, but doesn't contain the profile in
CHEF_PROFILE (or a default profile is CHEF_PROFILE is unset and there is
no context file), then an "Unable to parse Credentials file" error is
shown.
This change will print a better error message if the profile isn't found.
Additionally, in the case where there isn't a default profile, we just
fall back to normal credential loading without using anything in the
credentials file (similarly to if the credentials file didn't exist at
all).
Signed-off-by: Mark Harrison <mark@mivok.net>
| -rw-r--r-- | chef-config/lib/chef-config/mixin/credentials.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/chef-config/lib/chef-config/mixin/credentials.rb b/chef-config/lib/chef-config/mixin/credentials.rb index 4c0192fff8..0a526527e2 100644 --- a/chef-config/lib/chef-config/mixin/credentials.rb +++ b/chef-config/lib/chef-config/mixin/credentials.rb @@ -43,6 +43,12 @@ module ChefConfig end config = Tomlrb.load_file(credentials_file) + + if config[profile].nil? + return if profile == 'default' + raise ChefConfig::ConfigurationError, "Profile #{profile} doesn't exist. Please add it to #{credentials_file}." + end + apply_credentials(config[profile], profile) rescue ChefConfig::ConfigurationError raise |
