Skip to content

Commit b4e2882

Browse files
authored
Merge pull request #3 from godaddy/cicd
Set up the beginnings of CI/CD -- most importantly publishing
2 parents 64b729f + acf3dac commit b4e2882

File tree

9 files changed

+183
-8
lines changed

9 files changed

+183
-8
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ main ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ main ]
20+
schedule:
21+
- cron: '17 21 * * 6'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'python' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v2
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v1
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
52+
53+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54+
# If this step fails, then you should remove it and run the build manually (see below)
55+
- name: Autobuild
56+
uses: github/codeql-action/autobuild@v1
57+
58+
# ℹ️ Command-line programs to run using the OS shell.
59+
# 📚 https://git.io/JvXDl
60+
61+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62+
# and modify them (or add more) to build your code if your project
63+
# uses a compiled language
64+
65+
#- run: |
66+
# make bootstrap
67+
# make release
68+
69+
- name: Perform CodeQL Analysis
70+
uses: github/codeql-action/analyze@v1

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: publish
2+
3+
on:
4+
release:
5+
types: [published] # Trigger when release is created
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
12+
- name: Set up Python 3.7
13+
uses: actions/setup-python@3105fb18c05ddd93efea5f9e0bef7a03a6e9e7df
14+
with:
15+
python-version: 3.7
16+
- name: Install dependencies
17+
run: |
18+
pip install --upgrade pip
19+
pip install --upgrade poetry
20+
- name: Download Asherah binaries
21+
run: |
22+
./download-libasherah.sh
23+
- name: Package and publish with Poetry
24+
run: |
25+
poetry config pypi-token.pypi $PYPI_TOKEN
26+
poetry publish --build
27+
env:
28+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

asherah/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Asherah application encryption library"""
2+
13
from .asherah import Asherah
24
from .types import AsherahConfig
35

asherah/asherah.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
"""Main Asherah class, for encrypting and decrypting of data"""
2+
# pylint: disable=line-too-long, too-many-locals
3+
14
import os
2-
from cobhan import Cobhan
35
from datetime import datetime, timezone
46
from typing import ByteString, Union
57

8+
from cobhan import Cobhan
9+
610
from . import exceptions, types
711

812

913
class Asherah:
14+
"""The main class for providing encryption and decryption functionality"""
15+
1016
KEY_SIZE = 64
1117

1218
def __init__(self):
@@ -22,6 +28,7 @@ def __init__(self):
2228
)
2329

2430
def setup(self, config: types.AsherahConfig) -> None:
31+
"""Set up/initialize the underlying encryption library."""
2532
kms_type_buf = self.__cobhan.str_to_buf(config.kms_type)
2633
metastore_buf = self.__cobhan.str_to_buf(config.metastore)
2734
service_name_buf = self.__cobhan.str_to_buf(config.service_name)
@@ -61,6 +68,7 @@ def setup(self, config: types.AsherahConfig) -> None:
6168
)
6269

6370
def encrypt(self, partition_id: str, data: Union[ByteString, str]):
71+
"""Encrypt a chunk of data"""
6472
if isinstance(data, str):
6573
data = data.encode("utf-8")
6674
# Inputs
@@ -108,6 +116,7 @@ def encrypt(self, partition_id: str, data: Union[ByteString, str]):
108116
def decrypt(
109117
self, partition_id: str, data_row_record: types.DataRowRecord
110118
) -> bytearray:
119+
"""Decrypt data that was previously encrypted by Asherah"""
111120
# Inputs
112121
partition_id_buf = self.__cobhan.str_to_buf(partition_id)
113122
encrypted_data_buf = self.__cobhan.bytearray_to_buf(data_row_record.data)

asherah/exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
"""Custom exceptions for Asherah"""
2+
3+
14
class AsherahException(Exception):
25
"""Base exception class for any problems encountered in Asherah"""

asherah/types.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,51 @@
1+
"""Type definitions for the Asherah library"""
2+
# pylint: disable=too-many-instance-attributes,invalid-name
3+
14
from dataclasses import dataclass
25
from datetime import datetime
3-
from typing import ByteString
6+
from typing import ByteString, Optional
47

58

69
@dataclass
710
class AsherahConfig:
11+
"""Configuration options for Asherah setup"""
12+
813
kms_type: str
914
metastore: str
1015
service_name: str
1116
product_id: str
12-
rdbms_connection_string: str = None
13-
dynamo_db_endpoint: str = None
14-
dynamo_db_region: str = None
15-
dynamo_db_table_name: str = None
17+
rdbms_connection_string: Optional[str] = None
18+
dynamo_db_endpoint: Optional[str] = None
19+
dynamo_db_region: Optional[str] = None
20+
dynamo_db_table_name: Optional[str] = None
1621
enable_region_suffix: bool = False
17-
preferred_region: str = None
18-
region_map: str = None
22+
preferred_region: Optional[str] = None
23+
region_map: Optional[str] = None
1924
verbose: bool = False
2025
session_cache: bool = False
2126
debug_output: bool = False
2227

2328

2429
@dataclass
2530
class KeyMeta:
31+
"""Metadata about an encryption key"""
32+
2633
id: str
2734
created: datetime
2835

2936

3037
@dataclass
3138
class EnvelopeKeyRecord:
39+
"""Information about an encryption envelope"""
40+
3241
encrypted_key: ByteString
3342
created: datetime
3443
parent_key_meta: KeyMeta
3544

3645

3746
@dataclass
3847
class DataRowRecord:
48+
"""Encrypted data and its related information"""
49+
3950
data: ByteString
4051
key: EnvelopeKeyRecord

tests/__init__.py

Whitespace-only changes.

tests/test_asherah.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# pylint: disable=missing-function-docstring,missing-class-docstring,missing-module-docstring
2+
3+
from unittest import TestCase
4+
5+
6+
class AsherahTest(TestCase):
7+
def test_fake(self):
8+
self.assertEqual(True, True)

tox.ini

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[tox]
2+
minversion = 3.7.0
3+
toxworkdir = {env:TOX_WORK_DIR:.tox}
4+
skip_missing_interpreters = True
5+
envlist = py{37,38,39,310},black,mypy,pylint
6+
parallel_show_output = True
7+
isolated_build = True
8+
9+
[gh-actions]
10+
python =
11+
3.7: py37
12+
3.8: py38
13+
3.9: py39
14+
3.10: py310
15+
16+
[testenv]
17+
whitelist_externals =
18+
poetry
19+
pytest
20+
setenv =
21+
PYTHONDONTWRITEBYTECODE=1
22+
PYTHONHASHSEED=0
23+
PYTHONWARNINGS=ignore
24+
commands =
25+
poetry install --no-root -v
26+
poetry run pytest {posargs}
27+
28+
[testenv:black]
29+
basepython = python3.7
30+
commands =
31+
poetry install --no-root -v
32+
poetry run black --check .
33+
34+
[testenv:mypy]
35+
basepython = python3.7
36+
commands =
37+
poetry install --no-root -v
38+
poetry run mypy .
39+
40+
[testenv:pylint]
41+
basepython = python3.7
42+
commands =
43+
poetry install --no-root -v
44+
poetry run pylint asherah/ tests/

0 commit comments

Comments
 (0)