Skip to content

Commit

Permalink
QE-14488 Redact only values in config yaml (#415)
Browse files Browse the repository at this point in the history
If keys are redacted in yaml file, the yaml file will become invalid.
  • Loading branch information
ddl-xin authored Dec 20, 2023
1 parent 8fb0855 commit 9fd4479
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project closely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.181.0
- Change - only obfuscate values in config yaml file

## 0.180.0
- Change - only obfuscate certain parts in json output

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cucu"
version = "0.180.0"
version = "0.181.0"
license = "MIT"
description = "Easy BDD web testing"
authors = ["Domino Data Lab <open-source@dominodatalab.com>"]
Expand Down
30 changes: 9 additions & 21 deletions src/cucu/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,15 @@ def to_yaml_without_secrets(self):
]

config = {k: self[k] for k in sorted(keys)}
results = self.hide_secrets(yaml.dump(config))
# fix leading '*' issue
is_bytes = isinstance(results, bytes)
if is_bytes:
results = results.decode()

lines = results.split("\n")
for x in range(len(lines)):
parts = lines[x].split(": ", 1)
if len(parts) != 2:
continue

key, value = parts[0], parts[1]
if value.startswith("*"):
lines[x] = f"{key}: '{value}'"
results = "\n".join(lines)

if is_bytes:
results = results.encode()
for k, v in config.items():
if isinstance(v, str):
v = self.hide_secrets(v)
# fix leading '*' issue
if v.startswith("*"):
v = f"'{v}'"
config[k] = v

return results
return yaml.dump(config)


# global config object
Expand All @@ -348,7 +336,7 @@ def _get_local_address():
CONFIG.define(
"CWD",
"the current working directory of the cucu process",
default=os.getcwd,
default=os.getcwd(),
)
CONFIG.define(
"CUCU_SECRETS",
Expand Down

0 comments on commit 9fd4479

Please sign in to comment.