Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-facing test cases and example code #3

Merged
merged 33 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4d1291e
updated core files, and started on core bindings
sam-1pass Feb 21, 2024
e438d0c
buggy python core
sam-1pass Feb 21, 2024
6592676
push for debugging 403
sam-1pass Feb 22, 2024
ca1052d
init and invoke functions implemented
sam-1pass Feb 26, 2024
7c95186
implemented release client on object destruction
sam-1pass Feb 26, 2024
7503f15
added comments for documentation
sam-1pass Feb 26, 2024
9cc3ca1
starting point for test cases and examples
sam-1pass Feb 15, 2024
0f5fc34
added bad weather test case checks
sam-1pass Feb 20, 2024
c6d1d9e
add example with environmental variable SAToken and comments
sam-1pass Feb 28, 2024
7df081e
add unittest to pipeline
sam-1pass Feb 29, 2024
2fa22fd
move test_client from /test to /onepassword to implement unittest cap…
sam-1pass Mar 1, 2024
38833de
update filepath for test_client in validate.yml
sam-1pass Mar 1, 2024
da357f6
add bad .so file
sam-1pass Mar 1, 2024
b5480cd
add token to debugging pipeline
sam-1pass Mar 1, 2024
051294f
add .so file for linux pipeline
sam-1pass Mar 1, 2024
6ee4462
list files in pipeline
sam-1pass Mar 1, 2024
12b5cb9
make .so file executable
sam-1pass Mar 1, 2024
ee63d13
print architecture
sam-1pass Mar 4, 2024
dcc3f27
update .so file
sam-1pass Mar 4, 2024
8df3ccc
add authenticate method to test cases
sam-1pass Mar 4, 2024
1884ee7
implement async pytest structure instead of unittest
sam-1pass Mar 5, 2024
93dddf5
update validate.yml to run pytest
sam-1pass Mar 5, 2024
264e31c
update actions pytest command
sam-1pass Mar 5, 2024
36ff10f
install pytest-asyncio in pipeline
sam-1pass Mar 5, 2024
62f97ff
update pytest exceptions
sam-1pass Mar 5, 2024
3c4cb2e
removed unneccessary files
sam-1pass Mar 6, 2024
95398a1
remove unused imports
sam-1pass Mar 6, 2024
d94bbd2
finishing touches for sam/test merge
sam-1pass Mar 12, 2024
c5e85b3
remove faulty imports
sam-1pass Mar 12, 2024
f96b5f1
fix pipeline tests
sam-1pass Mar 12, 2024
0a514a5
clean up code comments
sam-1pass Mar 12, 2024
01e117d
change verb conjugation in example code comments
sam-1pass Mar 12, 2024
86f985b
improve wording of SAToken variable comment
sam-1pass Mar 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will build, test and check linting for the 1Password Python SDK.
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
name: Validate

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'

jobs:

validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Test with pytest
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.TEST_SERVICE_ACCOUNT_TOKEN }}
run: |
pip install pytest &&
pip install pytest-asyncio &&
python -m pytest src/onepassword/*.py

- name: Lint with Ruff
run: |
pip install ruff
ruff --output-format=github .
continue-on-error: true
36 changes: 22 additions & 14 deletions src/onepassword/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import platform
from core import *
import weakref
from core import InitClient, ReleaseClient
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
from secrets_api import Secrets

SDK_LANGUAGE = "Python"
Expand All @@ -12,22 +12,30 @@


class Client:
def __init__(self, auth, integration_name, integration_version):

"""authenticate verifies the user's permissions and allows them to access their secrets."""
@classmethod
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
async def authenticate(cls, auth, integration_name, integration_version):
self = cls()
self.config = new_default_config(auth=auth, integration_name=integration_name, integration_version=integration_version)
self.secrets = Secrets(client_id=InitClient(self.config))
self.client_id = int(await InitClient(self.config))
self.secrets = Secrets(client_id=self.client_id)
self._finalizer = weakref.finalize(self, ReleaseClient, self.client_id)

return self

# Generates a configuration dictionary with the user's parameters
def new_default_config(auth, integration_name, integration_version):
client_config_dict = {
"SAToken": auth,
"Language": SDK_LANGUAGE,
"SDKVersion": SDK_VERSION,
"IntegrationName": integration_name,
"IntegrationVersion": integration_version,
"RequestLibraryName": DEFAULT_REQUEST_LIBRARY,
"RequestLibraryVersion": sys.version_info[0] + "." + sys.version_info[1] + "." + sys.version_info[2],
"SystemOS": platform.system(),
"SystemOSVersion": platform.architecture()[0],
"SystemArch": DEFAULT_OS_VERSION,
"serviceAccountToken": auth,
"programmingLanguage": SDK_LANGUAGE,
"sdkVersion": SDK_VERSION,
"integrationName": integration_name,
"integrationVersion": integration_version,
"requestLibraryName": DEFAULT_REQUEST_LIBRARY,
"requestLibraryVersion": platform.python_version(),
"os": platform.system().lower(),
"osVersion": DEFAULT_OS_VERSION,
"architecture": platform.machine(),
}
return client_config_dict
26 changes: 9 additions & 17 deletions src/onepassword/core.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# omitting op_sdk_core_py.so import and shared library calls for the time being
# should be added back when we start work on the core

#import op_sdk_core_py
import json
import op_uniffi_core as op_uniffi_core

# InitClient creates a client instance in the current core module and returns its unique ID.
async def InitClient(client_config):
return await op_uniffi_core.init_client(json.dumps(client_config))

def Invoke(invoke_config):
serialized_config = json.dump(invoke_config)
#secret = op_sdk_core_py.invoke(serialized_config)
#return secret


def InitClient(client_config):
serialized_config = json.dump(client_config)
#client_id = op_sdk_core_py.init_client(serialized_config)
#return client_id

# Invoke calls specified business logic from core.
async def Invoke(invoke_config):
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
return await op_uniffi_core.invoke(json.dumps(invoke_config))

# ReleaseClient releases memory in the core associated with the given client ID.
def ReleaseClient(client_id):
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
#op_sdk_core_py.release_client(client_id)
pass
return op_uniffi_core.release_client(json.dumps(client_id))
17 changes: 17 additions & 0 deletions src/onepassword/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio
import os
from onepassword.client import Client, DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION

async def main():
# Your service account token here
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
token = os.environ("OP_SERVICE_ACCOUNT_TOKEN")

# Connect to 1Password
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
client = await Client.authenticate(auth=token, integration_name=DEFAULT_INTEGRATION_NAME, integration_version=DEFAULT_INTEGRATION_VERSION)

# Retrieve secret from 1Password
sam-1pass marked this conversation as resolved.
Show resolved Hide resolved
value = await client.secrets.resolve("op://xw33qlvug6moegr3wkk5zkenoa/bckakdku7bgbnyxvqbkpehifki/foobar")
print(value)

if __name__ == '__main__':
asyncio.run(main())
Binary file added src/onepassword/libop_uniffi_core.dylib
Binary file not shown.
Binary file added src/onepassword/libop_uniffi_core.so
Binary file not shown.
Loading
Loading