mirror of
https://github.com/dtomlinson91/csops.git
synced 2025-12-22 05:45:45 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fd751aad2 | |||
| 91519e232d | |||
| 1a90618808 | |||
| 24a3dd8ed3 | |||
| a375ac1807 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -152,3 +152,5 @@ cython_debug/
|
||||
#.idea/
|
||||
|
||||
|
||||
|
||||
.vscode/
|
||||
|
||||
14
CHANGELOG.md
14
CHANGELOG.md
@@ -3,6 +3,20 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
<!-- marker -->
|
||||
## [v0.2.1](https://github.com/dtomlinson91/csops/commits/v0.2.1) - 2022-01-27
|
||||
<small>[Compare with v0.2.0](https://github.com/dtomlinson91/csops/compare/v0.2.0..v0.2.1)</small>
|
||||
|
||||
### ✨ Features
|
||||
|
||||
- Add `--version` flag ([a375ac1](https://github.com/dtomlinson91/csops/commit/a375ac18075341ffc3cf410d26837d327d682ea7))
|
||||
|
||||
### 📘 Documentation
|
||||
|
||||
- Reformat environment variable example ([1a90618](https://github.com/dtomlinson91/csops/commit/1a9061880814d6171f599fc3a0d14eead0514d9a))
|
||||
|
||||
### 🛠 Refactor/Improvement
|
||||
|
||||
- Disable spawning a shell on subprocess ([91519e2](https://github.com/dtomlinson91/csops/commit/91519e232d1f1cfe19fd13a7a0ac45c80506195c))
|
||||
## [v0.2.0](https://github.com/dtomlinson91/csops/commits/v0.2.0) - 2022-01-17
|
||||
<small>[Compare with v0.1.0](https://github.com/dtomlinson91/csops/compare/v0.1.0..v0.2.0)</small>
|
||||
|
||||
|
||||
@@ -21,7 +21,10 @@ csops:
|
||||
gcp_kms_key: projects/plex-mozilla-sops/locations/global/keyRings/sops/cryptoKeys/sops-key
|
||||
```
|
||||
|
||||
Or set the environment variable `CSOPS_GCP_KMS_KEY="projects/plex-mozilla-sops/locations/global/keyRings/sops/cryptoKeys/sops-keys"`
|
||||
Or set the environment variable
|
||||
```bash
|
||||
CSOPS_GCP_KMS_KEY="projects/plex-mozilla-sops/locations/global/keyRings/sops/cryptoKeys/sops-keys"
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""Module containing the version of csops."""
|
||||
|
||||
__version__ = "0.2.0"
|
||||
__version__ = "0.2.1"
|
||||
|
||||
21
csops/run.py
21
csops/run.py
@@ -3,29 +3,35 @@ import pathlib
|
||||
import subprocess
|
||||
|
||||
from csops import CONFIG
|
||||
from csops._version import __version__
|
||||
|
||||
|
||||
def encrypt(args):
|
||||
encrypted_filename = f"{args.file.stem}.enc{args.file.suffix}"
|
||||
subprocess.run(
|
||||
"sops --encrypt --gcp-kms "
|
||||
f"{CONFIG.gcp_kms_key} {args.file} > {encrypted_filename}",
|
||||
encrypted_contents = subprocess.run(
|
||||
["sops", "--encrypt", "--gcp-kms", CONFIG.gcp_kms_key, args.file],
|
||||
check=True,
|
||||
text=True,
|
||||
shell=True,
|
||||
shell=False,
|
||||
capture_output=True,
|
||||
)
|
||||
with pathlib.Path(encrypted_filename).open("w", encoding="utf-8") as file:
|
||||
file.write(encrypted_contents.stdout)
|
||||
print(encrypted_filename)
|
||||
raise SystemExit(0)
|
||||
|
||||
|
||||
def decrypt(args):
|
||||
decrypted_filename = f"{args.file.stem.split('.')[0]}{args.file.suffix}"
|
||||
subprocess.run(
|
||||
f"sops --decrypt {args.file} > {decrypted_filename}",
|
||||
decrypted_contents = subprocess.run(
|
||||
["sops", "--decrypt", args.file],
|
||||
check=True,
|
||||
text=True,
|
||||
shell=True,
|
||||
shell=False,
|
||||
capture_output=True,
|
||||
)
|
||||
with pathlib.Path(decrypted_filename).open("w", encoding="utf-8") as file:
|
||||
file.write(decrypted_contents.stdout)
|
||||
print(decrypted_filename)
|
||||
raise SystemExit(0)
|
||||
|
||||
@@ -34,6 +40,7 @@ def run():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("flag", type=str, nargs=1)
|
||||
parser.add_argument("file", type=pathlib.Path)
|
||||
parser.add_argument("-v", "--version", action="version", version="%(prog)s " + __version__)
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "csops"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
description = ""
|
||||
authors = ["Daniel Tomlinson <dtomlinson@panaetius.co.uk>"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user