fix(release): support environment validation in containers
This commit is contained in:
@@ -108,7 +108,12 @@ def validate(values: dict[str, str], strict_external: bool) -> list[str]:
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("env_file", type=Path)
|
||||
parser.add_argument("env_file", type=Path, nargs="?", help="Env file to validate. Omit with --from-environ.")
|
||||
parser.add_argument(
|
||||
"--from-environ",
|
||||
action="store_true",
|
||||
help="Validate the current process environment instead of reading an env file.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--strict-external",
|
||||
action="store_true",
|
||||
@@ -116,14 +121,24 @@ def main() -> int:
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
values = parse_env_file(args.env_file)
|
||||
if args.from_environ:
|
||||
import os
|
||||
|
||||
values = dict(os.environ)
|
||||
source = "process environment"
|
||||
else:
|
||||
if args.env_file is None:
|
||||
parser.error("env_file is required unless --from-environ is set")
|
||||
values = parse_env_file(args.env_file)
|
||||
source = str(args.env_file)
|
||||
|
||||
errors = validate(values, args.strict_external)
|
||||
if errors:
|
||||
for error in errors:
|
||||
print(f"ERROR: {error}")
|
||||
return 1
|
||||
|
||||
print(f"OK: {args.env_file} passed release env validation")
|
||||
print(f"OK: {source} passed release env validation")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user