Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to hide sensitive data in logs #115

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/core/controlplane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def profile_exists?(profile)
end

def profile_create(profile, token)
@sensitive_data_pattern = /(?<=--token )(\S+)/
rafaelgomesxyz marked this conversation as resolved.
Show resolved Hide resolved
cmd = "cpln profile create #{profile} --token #{token}"
cmd += " > /dev/null" if Shell.should_hide_output?
perform!(cmd)
Expand Down Expand Up @@ -341,19 +342,19 @@ def parse_apply_result(result) # rubocop:disable Metrics/CyclomaticComplexity, M
private

def perform(cmd)
Shell.debug("CMD", cmd)
Shell.debug("CMD", hide_sensitive_data(cmd))
rafaelgomesxyz marked this conversation as resolved.
Show resolved Hide resolved

system(cmd)
end

def perform!(cmd)
Shell.debug("CMD", cmd)
Shell.debug("CMD", hide_sensitive_data(cmd))

system(cmd) || exit(false)
end

def perform_yaml(cmd)
Shell.debug("CMD", cmd)
Shell.debug("CMD", hide_sensitive_data(cmd))

result = `#{cmd}`
$CHILD_STATUS.success? ? YAML.safe_load(result) : exit(false)
Expand All @@ -362,4 +363,11 @@ def perform_yaml(cmd)
def gvc_org
"--gvc #{gvc} --org #{org}"
end

def hide_sensitive_data(message)
pattern = @sensitive_data_pattern
return message unless pattern.is_a?(Regexp)
rafaelgomesxyz marked this conversation as resolved.
Show resolved Hide resolved

message.gsub(pattern, "XXXXXXX")
end
end