Skip to content

Commit 57d1a82

Browse files
authored
Improved code quality (#7)
- Squashed potential bugs. - Deepsource tags: BAN-B104, PTC-W0019, PTC-W0049, PYL-W0125, BAN-B605, PYL-R1710, PYL-R1722, PYL-W0621, PYL-W0613.
1 parent 0b25f4d commit 57d1a82

File tree

11 files changed

+29
-19
lines changed

11 files changed

+29
-19
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
env:
3737
IMG_NAME: ${{ 'krishnaalagiri/ssm' }}
3838
# Versioning: MAJOR.MINOR.PATCH (eg., 1.2.3)
39-
VERSION_FULL: ${{ '1.1.1' }}
39+
VERSION_FULL: ${{ '1.1.2' }}
4040
# For v1.2.3, VERSION_SHORT is '1.2'
4141
VERSION_SHORT: ${{ '1.1' }}
4242
# For v1.2.3, VERSION_MAJOR is '1'

Access/is_auth.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010

1111

1212
@token.verify_token
13-
def abort_if_authorization_fail(token):
13+
def abort_if_authorization_fail(token_to_check):
1414
""" Check if an API token is valid
1515
Args:
16-
token (str): API Token
16+
token_to_check (str): API Token
1717
"""
18-
check, username = conn.tokens.is_authorized(token)
18+
check, username = conn.tokens.is_authorized(token_to_check)
1919
if check:
2020
return username
2121
api.abort(401, "Not Authorized to access the requested resource")
22+
return None
2223

2324

2425
@userpass.verify_password
2526
def verify_userpass(username, password):
2627
if conn.userpass.is_authorized(username, password):
2728
return username
2829
api.abort(401, "Not Authorized to access the requested resource")
30+
return None

Access/tokens.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
""" Token authentication for Secrets Manager
33
"""
4-
# TODO: Max TTL, Access Control
4+
# TODO: Implement Max TTL, Access Control
55

66
from bson.timestamp import Timestamp
77
import datetime as dt
@@ -30,6 +30,7 @@ def generate(self, username, max_ttl=15811200):
3030
data = {
3131
"token": token,
3232
"owner": username,
33+
"max_ttl": max_ttl,
3334
"generated_on": Timestamp(int(dt.datetime.today().timestamp()), 1),
3435
}
3536
_ = self._tokens.insert_one(data)
@@ -66,4 +67,5 @@ def is_authorized(self, token):
6667
return True, finder["owner"]
6768

6869
def renew(self):
70+
# TODO: Implement renew to extend MAX TTL
6971
pass

Api/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
conn = Connection()
1919
api_v1 = Blueprint("api", __name__, url_prefix="/api")
20-
api = Api(api_v1, version="1.1.1", title="Simple Secrets Manager",
20+
api = Api(api_v1, version="1.1.2", title="Simple Secrets Manager",
2121
description="Secrets management simplified",
2222
authorizations=authorizations)
2323
app = Flask(__name__)
@@ -26,6 +26,7 @@
2626

2727
# Import API Resources
2828
# The below conditions prevents IDE auto-formatting
29+
# skipcq: PYL-W0125
2930
if True:
3031
# Secret Engines
3132
from Api.resources.secrets.kv_resource import Engine_KV # noqa: F401

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
FROM python:3.8-slim-buster
44

55
LABEL com.ssm.title="Simple Secrets Manager"
6-
LABEL com.ssm.version="1.1.1"
6+
LABEL com.ssm.version="1.1.2"
77
LABEL com.ssm.author.name="Krishnakanth Alagiri"
88
LABEL com.ssm.author.github="https://github.com/bearlike"
99
LABEL com.ssm.repo="https://github.com/bearlike/simple-secrets-manager"

Engines/kv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def add(self, path, key, value):
4040
# Create a Path where kv(s) goes into
4141
finder = {
4242
"path": path,
43-
"data": dict(),
43+
"data": {},
4444
}
4545
_ = self._kv.insert_one(finder)
4646
if key not in finder["data"].keys():

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# $ docker login -u <username>
55
#
66
# We try to follow [SemVer v2.0.0](https://semver.org/)
7-
VERSION="1.1.1"
7+
VERSION="1.1.2"
88
# If $VERSION = "1.2.3"
99
# ${VERSION::3} will be "1.2"
1010
# ${VERSION::1} will be "1"

connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python3
2-
""" Brains for the Secrets Manager
2+
""" Database model for the Secrets Manager
33
"""
44
import pymongo
55
import logging
66
import os
7-
# Secret Engines
7+
import sys
8+
# Secret engines imports
89
from Engines.kv import Key_Value_Secrets as _KV
9-
# Auth Methods
10+
# Auth methods imports
1011
from Access.tokens import Tokens as _Tokens
1112
from Access.userpass import User_Pass as _User_Pass
1213

@@ -15,7 +16,7 @@ class Connection:
1516
def __init__(self):
1617
if os.environ.get("CONNECTION_STRING") is None:
1718
logging.error("CONNECTION_STRING variable not found")
18-
exit(-1)
19+
sys.exit(-1)
1920
# Create a connection using MongoClient.
2021
self._client = pymongo.MongoClient(os.environ["CONNECTION_STRING"])
2122
self._data = self._client["secrets_manager_data"]

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
networks:
2323
- app-tier
2424

25-
app:
25+
ssm-app:
2626
image: krishnaalagiri/ssm:latest
2727
restart: always
2828
depends_on:

docs/README_dockerhub.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Secure storage, and delivery for tokens, passwords, API keys, and other secrets
1313
1414

1515
## Supported tags and respective [Dockerfile](https://github.com/bearlike/simple-secrets-manager/blob/main/Dockerfile) links
16-
- [`1.1.1`, `1.1`, `1`, `latest`](https://github.com/bearlike/simple-secrets-manager/blob/releases/v1.1.1/Dockerfile)
16+
- [`1.1.2`, `1.1`, `1`, `latest`](https://github.com/bearlike/simple-secrets-manager/blob/releases/v1.1.2/Dockerfile)
17+
- [`1.1.1`](https://github.com/bearlike/simple-secrets-manager/blob/releases/v1.1.1/Dockerfile)
1718
- [`1.1.0`](https://github.com/bearlike/simple-secrets-manager/blob/releases/v1.1.0/Dockerfile)
1819
- [`1.0.0`, `1.0`](https://github.com/bearlike/simple-secrets-manager/blob/releases/v1.0.0/Dockerfile)
1920

@@ -49,13 +50,16 @@ Hashi Corp Vault works well but it was meant for enterprises. Therefore, it was
4950
## Getting started
5051
### Automated Install: [`docker-compose`](https://docs.docker.com/compose/install/) (Recommended)
5152
1. Run the [stack](https://github.com/bearlike/simple-secrets-manager/blob/main/docker-compose.yml) by executing `docker-compose up -d`.
52-
53+
2. Stop stack by executing `docker-compose down`
5354
```yaml
5455
version: '3'
5556
volumes:
5657
mongo_data:
5758

5859
services:
60+
# From v5.0.0, mongoDB requires atleast ARMv8.2-A microarchitecture to run.
61+
# So we're going with v4 to improve compatibility on SBCs such as
62+
# Raspberry Pi 4 and Odroid C2 with ARMv8.0-A
5963
mongo:
6064
image: mongo:4
6165
restart: always
@@ -67,8 +71,9 @@ services:
6771
networks:
6872
- app-tier
6973

70-
app:
74+
ssm-app:
7175
image: krishnaalagiri/ssm:latest
76+
restart: always
7277
depends_on:
7378
- mongo
7479
ports:

server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515

1616
def init_app():
1717
from Api.api import app
18-
app.run(host='0.0.0.0',
18+
app.run(host=os.environ.get("BIND_HOST", '0.0.0.0'),
1919
port=os.environ.get("PORT", 5000),
2020
debug=bool(strtobool(os.getenv('DEBUG', 'False'))),
2121
use_reloader=True)
2222

2323

2424
if __name__ == "__main__":
25-
os.system('cls' if os.name == 'nt' else 'clear')
2625
print("Server started...")
2726
init_app()

0 commit comments

Comments
 (0)