Skip to content

Commit

Permalink
Add mask string method
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
  • Loading branch information
Vivek Singh committed Dec 11, 2019
1 parent 98cb1b0 commit bba4ee6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/chef/knife/ec2_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def connection_string
Chef::Log.debug "Using iam profile for authentication as use_iam_profile set"
Aws::InstanceProfileCredentials.new
else
Chef::Log.debug "Setting up AWS connection using aws_access_key_id #{locate_config_value(:aws_access_key_id)} aws_secret_access_key: #{locate_config_value(:aws_secret_access_key)} aws_session_token: #{locate_config_value(:aws_session_token)}"
Chef::Log.debug "Setting up AWS connection using aws_access_key_id: #{mask(locate_config_value(:aws_access_key_id))} aws_secret_access_key: #{mask(locate_config_value(:aws_secret_access_key))} aws_session_token: #{mask(locate_config_value(:aws_session_token))}"

Aws::Credentials.new(locate_config_value(:aws_access_key_id), locate_config_value(:aws_secret_access_key), locate_config_value(:aws_session_token))
end
conn
Expand Down Expand Up @@ -343,5 +344,16 @@ def validate_aws_credential_file!
raise ArgumentError, "The provided --aws-profile '#{profile}' is invalid. Does the credential file at '#{aws_cred_file_location}' contain this profile?"
end
end

# Mask the given string with char `X`
# Discard the chars based on from value
def mask(key, from = 4)
str = key.dup
if str && str.length > from
str[from...str.length] = "X" * (str[from...str.length].length)
end

str
end
end
end

0 comments on commit bba4ee6

Please sign in to comment.