Skip to content

Commit 5b72e27

Browse files
committed
Merge commit 'a937417d7de37a800b281dbc1e4a9be87a247850'
2 parents c5ed484 + a937417 commit 5b72e27

File tree

9 files changed

+126
-111
lines changed

9 files changed

+126
-111
lines changed

.github/workflows/build-golang-macos.yaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,20 @@ jobs:
7676
# FIXME: Add more caching
7777
- name: Add gopy dependencies and build wheel
7878
run: |
79-
# Since we don't have our wheel build / install configured yet we use '--no-root'
80-
poetry install --no-root
81-
82-
source $(poetry env info --path)/bin/activate
83-
84-
# Add Go bin directory to PATH
85-
echo "export PATH=$PATH:~/.local/go/bin" >> $GITHUB_ENV
86-
87-
go install golang.org/x/tools/cmd/goimports@latest
88-
89-
go install github.com/go-python/gopy@latest
90-
91-
poetry run pip install --upgrade setuptools wheel
92-
93-
gopy build --output=otdf_python -vm=python3 .
94-
95-
poetry run python3 setup.py bdist_wheel
79+
./ci-build.sh
9680
9781
- name: Test Python wheel
9882
run: |
9983
# Test wheel installation
100-
pip install dist/otdf_python-0.0.15-py3-none-any.whl
84+
pip install dist/otdf_python-0.1.0-py3-none-any.whl
10185
10286
# Test wheel functionality
10387
# python3 validate_otdf_python.py
10488
89+
- uses: ./.github/workflows/platform-integration-test.yaml
90+
with:
91+
wheel: dist/otdf_python-0.1.0-py3-none-any.whl
92+
10593
# release:
10694
# needs: build
10795
# runs-on: macos-latest

.github/workflows/build-golang-ubuntu.yaml

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -57,78 +57,36 @@ jobs:
5757
# FIXME: Add more caching
5858
- name: Add gopy dependencies and build wheel
5959
run: |
60-
# Since we don't have our wheel build / install configured yet we use '--no-root'
61-
poetry install --no-root
62-
63-
source $(poetry env info --path)/bin/activate
64-
65-
# Add Go bin directory to PATH
66-
echo "export PATH=$PATH:~/.local/go/bin" >> $GITHUB_ENV
67-
68-
go install golang.org/x/tools/cmd/goimports@latest
69-
70-
go install github.com/go-python/gopy@latest
71-
72-
poetry run pip install --upgrade setuptools wheel
73-
74-
gopy build --output=otdf_python -vm=python3 .
75-
76-
poetry run python3 setup.py bdist_wheel
77-
78-
# TODO: Can this be a distinct job?
79-
# exercise-ssh:
80-
# needs: build
81-
82-
# runs-on: ubuntu-latest
83-
84-
# steps:
85-
# - uses: actions/checkout@v4
60+
./ci-build.sh
8661
8762
- name: Check existing workspace content
8863
run: |
8964
ls -la
9065
ls -la dist/
9166
92-
# - name: Set up Docker Buildx
93-
# uses: docker/setup-buildx-action@v3
94-
95-
# - name: Install Vagrant
96-
# run: sudo apt-get update && sudo apt-get install -y vagrant
97-
98-
# - name: Create Vagrantfile
99-
# run: |
100-
# cat << EOF > Vagrantfile
101-
# Vagrant.configure("2") do |config|
102-
# config.vm.provider "docker" do |d|
103-
# d.image = "ubuntu"
104-
# d.cmd = [ "/bin/bash", "-c", "echo 'Hello world'" ]
105-
# d.remains_running = false
106-
# end
107-
# end
108-
# EOF
109-
110-
# - name: Run vagrant up
111-
# run: vagrant up --provider=docker
112-
113-
# - name: Launch the Docker/Vagrant test machine
114-
# run: |
115-
# # Change directory
116-
# cd ssh-servers/docker-in-vagrant
117-
118-
# # List content in the directory
119-
# ls -la
120-
121-
# # Launch machine
122-
# vagrant up --provider=docker
123-
124-
# # Connect to it with SSH
125-
# vagrant ssh -c "echo 'Hello Ubuntu'"
126-
12767
- name: Test Python wheel
12868
run: |
12969
# Test wheel installation
130-
pip install dist/otdf_python-0.0.15-py3-none-any.whl
70+
pip install dist/otdf_python-0.1.0-py3-none-any.whl
13171
13272
# DISABLED: Need to figure out Ubuntu nested VM
13373
# Test wheel functionality
13474
# python3 validate_otdf_python.py
75+
76+
- uses: actions/cache/restore@v4
77+
with:
78+
path: dist/otdf_python-0.1.0-py3-none-any.whl
79+
key: ${{ runner.os }}-data-${{ github.sha }}
80+
81+
- uses: actions/cache/save@v4
82+
with:
83+
path: dist/otdf_python-0.1.0-py3-none-any.whl
84+
key: ${{ runner.os }}-data-${{ github.sha }}
85+
restore-keys: |
86+
${{ runner.os }}-data-
87+
88+
integration-test:
89+
needs: build
90+
uses: ./.github/workflows/platform-integration-test.yaml
91+
with:
92+
wheel: dist/otdf_python-0.1.0-py3-none-any.whl

.github/workflows/platform-integration-test.yaml

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
# Based on
22
# https://github.com/opentdf/java-sdk/blob/v0.6.1/.github/workflows/checks.yaml
3+
#
4+
# Except, that this is a "Composite Action", and specifies 'shell: bash' for
5+
# each 'run:' step.
36
name: "Platform Integration testing"
47

58
on:
6-
pull_request:
7-
8-
# on:
9-
# pull_request:
10-
# branches:
11-
# - main
12-
# push:
13-
# branches:
14-
# - main
9+
workflow_call:
10+
inputs:
11+
wheel:
12+
description: The Python wheel to test
13+
required: true
14+
type: string
1515

1616
permissions:
1717
contents: read
1818

1919
jobs:
20-
21-
platform-integration:
22-
runs-on: ubuntu-22.04
20+
integration_test:
21+
runs-on: ubuntu-latest
2322
steps:
24-
- name: Checkout Java SDK
23+
- name: Checkout this repo
2524
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
26-
- uses: bufbuild/buf-setup-action@382440cdb8ec7bc25a68d7b4711163d95f7cc3aa
25+
26+
- uses: actions/cache/restore@v4
2727
with:
28-
github_token: ${{ secrets.GITHUB_TOKEN }}
28+
path: dist/otdf_python-0.1.0-py3-none-any.whl
29+
key: ${{ runner.os }}-data-${{ github.sha }}
30+
31+
- name: Prove that the input file is available
32+
shell: bash
33+
run: |
34+
ls -la
35+
ls -la "${{ inputs.wheel }}"
36+
du -sh "${{ inputs.wheel }}"
37+
38+
# - uses: bufbuild/buf-setup-action@382440cdb8ec7bc25a68d7b4711163d95f7cc3aa
39+
# with:
40+
# github_token: ${{ secrets.GITHUB_TOKEN }}
2941

3042
- name: Check out platform
3143
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
@@ -44,10 +56,13 @@ jobs:
4456
platform/protocol/go/go.sum
4557
platform/sdk/go.sum
4658
- run: go mod download
59+
shell: bash
4760
working-directory: platform
4861
- run: go mod verify
62+
shell: bash
4963
working-directory: platform
5064
- name: Create keys
65+
shell: bash
5166
run: |
5267
.github/scripts/init-temp-keys.sh
5368
cp opentdf-dev.yaml opentdf.yaml
@@ -64,12 +79,15 @@ jobs:
6479
# -alias localhost-for-tests
6580
# working-directory: platform/keys
6681
- name: Bring the services up
82+
shell: bash
6783
run: docker compose up -d --wait --wait-timeout 240
6884
working-directory: platform
6985
- name: Provision keycloak
86+
shell: bash
7087
run: go run ./service provision keycloak
7188
working-directory: platform
7289
- name: Provision fixtures
90+
shell: bash
7391
run: go run ./service provision fixtures
7492
working-directory: platform
7593
- name: Start server in background
@@ -83,12 +101,37 @@ jobs:
83101
wait-for: 90s
84102
working-directory: platform
85103
- name: Get grpcurl
104+
shell: bash
86105
run: go install github.com/fullstorydev/grpcurl/cmd/[email protected]
87106
- name: Make sure that the platform is up
107+
shell: bash
88108
run: |
89109
grpcurl -plaintext localhost:8080 list && \
90110
grpcurl -plaintext localhost:8080 kas.AccessService/PublicKey
91111
112+
- name: Set up Python
113+
uses: actions/setup-python@v4
114+
with:
115+
python-version: '3.11'
116+
117+
- name: Validate the Python SDK
118+
env:
119+
OPENTDF_CLIENT_ID: "opentdf-sdk"
120+
OPENTDF_CLIENT_SECRET: "secret"
121+
OPENTDF_HOSTNAME: "localhost:8080"
122+
OIDC_TOKEN_ENDPOINT: "http://localhost:8888/auth/realms/opentdf/protocol/openid-connect/token"
123+
OPENTDF_KAS_URL: "http://localhost:8080/kas"
124+
run: |
125+
mkdir validation
126+
wheel="$(basename ${{ inputs.wheel }} )"
127+
cp -v "${{ inputs.wheel }}" validation/
128+
cp -v validate_otdf_python.py validation/
129+
cd validation
130+
python -m venv .venv
131+
source .venv/bin/activate
132+
pip install ./"$wheel"
133+
python validate_otdf_python.py
134+
92135
# - name: Validate the SDK through the command line interface
93136
# run: |
94137
# printf 'here is some data to encrypt' > data

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exclude: |
77
# See https://pre-commit.com/hooks.html for more hooks#
88
repos:
99
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v4.6.0
10+
rev: v5.0.0
1111
hooks:
1212
- id: check-yaml
1313
- id: end-of-file-fixer
@@ -40,7 +40,7 @@ repos:
4040

4141
- repo: https://github.com/astral-sh/ruff-pre-commit
4242
# Ruff version.
43-
rev: v0.6.9
43+
rev: v0.7.4
4444
hooks:
4545
# Run the linter.
4646
- id: ruff

ci-build.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -eou pipefail
4+
5+
# Since we don't have our wheel build / install configured yet we use '--no-root'
6+
poetry install --no-root
7+
8+
source $(poetry env info --path)/bin/activate
9+
10+
# Add Go bin directory to PATH
11+
echo "export PATH=$PATH:~/.local/go/bin" >> $GITHUB_ENV
12+
13+
go install golang.org/x/tools/cmd/goimports@latest
14+
15+
go install github.com/go-python/gopy@latest
16+
17+
poetry run pip install --upgrade setuptools wheel
18+
19+
gopy build --output=otdf_python -vm=python3 .
20+
21+
poetry run python3 setup.py bdist_wheel

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "otdf-python"
33
# Should match 'setup.py' version number (used for gopy/pybindgen)
4-
version = "0.0.15"
4+
version = "0.1.0"
55
description = "Unofficial OpenTDF SDK for Python."
66
authors = ["b-long <[email protected]>"]
77
readme = "README.md"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
url="https://github.com/b-long/opentdf-python-sdk",
2525
package_data={"otdf_python": ["*.so"]},
2626
# Should match 'pyproject.toml' version number
27-
version="0.0.15",
27+
version="0.1.0",
2828
author_email="[email protected]",
2929
include_package_data=True,
3030
)

setup_ci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def build_extension(self, ext: Extension):
8181

8282
setuptools.setup(
8383
name="otdf_python",
84-
version="0.0.15",
84+
version="0.1.0",
8585
author="b-long",
8686
description="Unofficial OpenTDF SDK for Python.",
8787
long_description_content_type="text/markdown",

validate_otdf_python.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import tempfile
66
from pathlib import Path
77
from zipfile import is_zipfile
8+
from os import environ
89

910
from otdf_python.gotdf_python import EncryptionConfig
1011

11-
SOME_PLAINTEXT_FILE = Path(__file__).parent / "go.mod"
12-
1312

1413
def verify_hello():
1514
from otdf_python.gotdf_python import Hello
@@ -22,11 +21,14 @@ def _get_configuration() -> EncryptionConfig:
2221
platformEndpoint = "localhost:8080"
2322

2423
config: EncryptionConfig = EncryptionConfig(
25-
ClientId="opentdf-sdk",
26-
ClientSecret="secret",
27-
PlatformEndpoint=platformEndpoint,
28-
TokenEndpoint="http://localhost:8888/auth/realms/opentdf/protocol/openid-connect/token",
29-
KasUrl=f"http://{platformEndpoint}/kas",
24+
ClientId=environ.get("OPENTDF_CLIENT_ID", "opentdf-sdk"),
25+
ClientSecret=environ.get("OPENTDF_CLIENT_SECRET", "secret"),
26+
PlatformEndpoint=environ.get("OPENTDF_HOSTNAME", platformEndpoint),
27+
TokenEndpoint=environ.get(
28+
"OIDC_TOKEN_ENDPOINT",
29+
"http://localhost:8888/auth/realms/opentdf/protocol/openid-connect/token",
30+
),
31+
KasUrl=environ.get("OPENTDF_KAS_URL", f"http://{platformEndpoint}/kas"),
3032
# FIXME: Be careful with binding the 'DataAttributes' field on this struct.
3133
#
3234
# In golang, this is initialized as []string , but passing
@@ -77,6 +79,9 @@ def verify_encrypt_file() -> None:
7779
"The output path should not exist before calling 'EncryptFile()'."
7880
)
7981

82+
SOME_PLAINTEXT_FILE = Path(tmpDir) / "new-file.txt"
83+
SOME_PLAINTEXT_FILE.write_text("Hello world")
84+
8085
outputFilePath = EncryptFile(
8186
inputFilePath=str(SOME_PLAINTEXT_FILE),
8287
outputFilePath=str(SOME_ENCRYPTED_FILE),
@@ -87,10 +92,10 @@ def verify_encrypt_file() -> None:
8792
if not SOME_ENCRYPTED_FILE.exists():
8893
raise ValueError("The output file does not exist!")
8994

90-
if not (
91-
SOME_ENCRYPTED_FILE.stat().st_size > 2500
92-
and is_zipfile(SOME_ENCRYPTED_FILE)
93-
):
95+
encrypted_file_size = SOME_ENCRYPTED_FILE.stat().st_size
96+
print(f"The encrypted file size is {encrypted_file_size}")
97+
98+
if not (encrypted_file_size > 1500 and is_zipfile(SOME_ENCRYPTED_FILE)):
9499
raise ValueError("The output file has unexpected content!")
95100

96101
# breakpoint()

0 commit comments

Comments
 (0)