Skip to content

Commit

Permalink
Version 0.6.0 (#2)
Browse files Browse the repository at this point in the history
* removed un-neceesary import

* added test for keyring

* version 0.6.0

* testing keyring

* added ubuntu scripts

* added root

* removed ubuntu

* don't test keyring with ubuntu

* version 0.6.0, toml update

* removed special ubuntu workflow
  • Loading branch information
keithrozario committed Nov 13, 2020
1 parent 488774c commit ab16936
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ jobs:
- name: Poetry install
run: poetry install

# - name: Build Ubuntu packages
# if: contains(matrix.os, 'ubuntu')
# run: |
# poetry add secretstorage
# sudo apt-get install libdbus-1-dev libdbus-glib-1-dev
# poetry add dbus-python

- name: Poetry test
env:
CREDENTIALS_FILE_CONTENTS : ${{ secrets.AWS_CREDENTIALS_FILE_CONTENTS }}
Expand Down
2 changes: 1 addition & 1 deletion mentaws/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.3"
__version__ = "0.6.0"
2 changes: 2 additions & 0 deletions mentaws/cryptographic_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def get_key(app_name: str, key_name: str) -> Fernet:

def decrypt_keys(profiles: List[dict], app_name: str, key_name: str) -> dict:
"""
Key refers to AWS Secret keys, not encryption keys
Args:
profiles: dictionary of format {'profile': <value>, 'aws_secret_access_key': <value>}
app_name: app name of key in keychain
Expand Down Expand Up @@ -70,6 +71,7 @@ def decrypt_keys(profiles: List[dict], app_name: str, key_name: str) -> dict:

def encrypt_keys(profiles: List[dict], app_name: str, key_name: str) -> dict:
"""
Key refers to AWS Secret keys, not encryption keys
Args:
profiles: dictionary of format {'profile': <value>, 'aws_secret_access_key': <value>}
app_name: app name of key in keychain
Expand Down
40 changes: 14 additions & 26 deletions mentaws/main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import configparser
import sys
import copy
import os
from typing import List

import click

from mentaws.__init__ import __version__
from mentaws.aws_operations import get_token, get_region
from mentaws.operations import (
setup_new_db,
list_profiles_in_db,
get_plaintext_credentials,
write_creds_file,
remove_profile_from_db,
check_new_profiles,
check_profile_in_db,
creds_file_contents,
remove_mentaws_db
)
from mentaws import aws_operations
from mentaws import operations
import mentaws.config as mentaws_config


Expand All @@ -32,7 +20,7 @@ def setup():
"""
First time setup of mentaws.
"""
profiles = setup_new_db()
profiles = operations.setup_new_db()

if profiles is None:
safe_print(mentaws_config.already_setup_message)
Expand All @@ -58,7 +46,7 @@ def refresh(profiles: str = ""):
Refreshes AWS credentials in security file.
"""

new_profiles = check_new_profiles()
new_profiles = operations.check_new_profiles()
if len(new_profiles) > 0:
safe_print(
f"\nFound {len(new_profiles)} new profiles in credentials file, added these to mentaws:"
Expand All @@ -67,7 +55,7 @@ def refresh(profiles: str = ""):
safe_print(f"{profile}")

# Return credentials only for specified profiles
creds = get_plaintext_credentials(profiles)
creds = operations.get_plaintext_credentials(profiles)

# Generate temp credentials
temp_config = configparser.ConfigParser()
Expand All @@ -76,8 +64,8 @@ def refresh(profiles: str = ""):
safe_print(f"\n👷🏿 Profile{' ' * 20}🌎 Region:{' '*12}⏰ Tokens expire at")
for section in creds:

region = get_region(profile=section["profile"])
temp_token = get_token(
region = aws_operations.get_region(profile=section["profile"])
temp_token = aws_operations.get_token(
key_id=section["aws_access_key_id"],
secret_access_key=section["aws_secret_access_key"],
region=region,
Expand All @@ -88,7 +76,7 @@ def refresh(profiles: str = ""):
)

# Replace ~/.aws/credentials
write_creds_file(config=temp_config, replace=False)
operations.write_creds_file(config=temp_config, replace=False)
safe_print(mentaws_config.refresh_message)

return
Expand All @@ -107,8 +95,8 @@ def remove(profiles: str="") -> bool:
profiles_list = profiles.split(",")

for profile_name in profiles_list:
if check_profile_in_db(profile_name):
remove_profile_from_db(profile_name)
if operations.check_profile_in_db(profile_name):
operations.remove_profile_from_db(profile_name)
safe_print(f"Profile {profile_name} was deleted")
else:
safe_print(f"Profile {profile_name} not found")
Expand All @@ -122,7 +110,7 @@ def status() -> List[dict]:
List out all Profiles, key IDs and expiry times of tokens
"""

creds = creds_file_contents()
creds = operations.creds_file_contents()
profiles = list()

safe_print(f"\n👷🏿 Profile{' ' * 20}🔑 Key:{' '*18}⏰ Tokens expire at")
Expand Down Expand Up @@ -156,7 +144,7 @@ def unsetup() -> bool:
Deletes the mentaws db -- does not actually delete mentaws (hence we call it unsetup)
"""

creds = get_plaintext_credentials(all=True)
creds = operations.get_plaintext_credentials(all=True)
temp_config = configparser.ConfigParser()

for section in creds:
Expand All @@ -169,8 +157,8 @@ def unsetup() -> bool:
if temp_config[profile][key] == "":
del temp_config[profile][key]

write_creds_file(config=temp_config, replace=True)
mentaws_db_path = remove_mentaws_db()
operations.write_creds_file(config=temp_config, replace=True)
mentaws_db_path = operations.remove_mentaws_db()

safe_print(f"{mentaws_db_path} has been been deleted, it's like we were never here")
safe_print(mentaws_config.unsetup_message)
Expand Down
20 changes: 19 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
[tool.poetry]
name = "mentaws"
version = "0.5.3"
version = "0.6.0"
description = "moMENTary AWS credentials"
authors = ["keithrozario <[email protected]>"]
repository = "https://github.com/keithrozario/mentaws"
homepage = "https://github.com/keithrozario/mentaws"
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
]
readme = "README.MD"
license = "MIT"
keywords = ["aws", "mentaws", "tokens", "credentials", "temporary"]


[tool.poetry.dependencies]
python = "^3.6"
Expand All @@ -24,3 +39,6 @@ mts = "mentaws.main:main"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/keithrozario/mentaws/issues"
2 changes: 1 addition & 1 deletion tests/test_01_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def mock_set_key(*args, **kwargs):


def test_version():
assert __version__ == "0.5.3"
assert __version__ == "0.6.0"


def test_setup(monkeypatch):
Expand Down
38 changes: 38 additions & 0 deletions tests/test_04_keyring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import platform

import keyring
from cryptography.fernet import Fernet, InvalidToken
from mentaws import cryptographic_operations

app_name = "mentaws"
key_name = "test_key"

def test_keyring_on_os():

"""
Can't test on Linux with Github actions because installing backend is quite complex
"""

if not platform.system() == "Linux":
key = cryptographic_operations.gen_key()
assert len(key) == 44

assert cryptographic_operations.setup_key(app_name=app_name, key_name=key_name) == True

encryption_key = cryptographic_operations.get_key(app_name=app_name, key_name=key_name)
assert isinstance(encryption_key, Fernet)

def test_encrypt_decrypt():

"""
Can't test on Linux with Github actions because installing backend is quite complex
"""

if not platform.system() == "Linux":
test_string = "abc12345dsfafsafdfsdf3-12934019u423oyrewkbf1!@#%^IU^&(&%&*)_()_)()((*&*%$^%#$@#?>:{}|"

key = cryptographic_operations.get_key(app_name=app_name, key_name=key_name)
encrypted_string = key.encrypt(test_string.encode('utf-8')).decode('utf-8')

decrypted_string = key.decrypt(encrypted_string.encode('utf-8'))
assert decrypted_string.decode('utf-8') == test_string

0 comments on commit ab16936

Please sign in to comment.