diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/client.py b/client.py deleted file mode 100644 index f647bcd..0000000 --- a/client.py +++ /dev/null @@ -1,38 +0,0 @@ -import sys -import platform -from core import * -from secrets_api import SecretsSource - -sdk_version = "0010001" # v0.1.0 -default_integration_name = "Unknown" -default_integration_version = "Unknown" -sdk_language = "Python" -default_request_library = "net/http" -default_os_version = "0.0.0" - - -class Client: - def __init__(self, auth="", integration_name="", integration_version=""): - self.auth = auth # onepassword.ServiceAccountCredentials("ops_..."), - self.integration_name = integration_name, - self.integration_version = integration_version, - - # one possible way of passing the client ID - self.config = NewDefaultConfig(), - self.secrets = SecretsSource(clientID=InitClient(self.config)), - - -def NewDefaultConfig(): - client_config_dict = { - "SAToken": "", - "Language": sdk_language, - "SDKVersion": sdk_version, - "IntegrationName": "", - "IntegrationVersion": "", - "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, - } - return client_config_dict diff --git a/core.py b/core.py deleted file mode 100644 index 65748b7..0000000 --- a/core.py +++ /dev/null @@ -1,18 +0,0 @@ -import op_sdk_core_py -import json - - -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 - - -def ReleaseClient(clientID): - op_sdk_core_py.release_client(clientID) diff --git a/examples/example.py b/examples/example.py new file mode 100644 index 0000000..cc198a2 --- /dev/null +++ b/examples/example.py @@ -0,0 +1,16 @@ +from src.sdk import client as onepassword # temporary example syntax, must be changed before release +import os + +def main(): + # your 1Password service account token + token = os.environ['OP_SERVICE_ACCOUNT_TOKEN'] + + # initialize Client to connect to 1Password + client = onepassword.Client(token, onepassword.DEFAULT_INTEGRATION_NAME, onepassword.DEFAULT_INTEGRATION_VERSION) + + # resolve secret reference + result = client.secrets.resolve(reference="") + print(result) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/op_sdk_core_py.so b/op_sdk_core_py.so deleted file mode 100644 index 4d32f34..0000000 Binary files a/op_sdk_core_py.so and /dev/null differ diff --git a/secrets_api.py b/secrets_api.py deleted file mode 100644 index 5fa5013..0000000 --- a/secrets_api.py +++ /dev/null @@ -1,23 +0,0 @@ -from core import Invoke -import os - -token = os.environ['OP_SERVICE_ACCOUNT_TOKEN'] - - -# SecretsAPI represents all operations the SDK client can perform on 1Password secrets. -class SecretsApi: - def Resolve(self, reference): - response = Invoke({ - "clientId": self.client_id, - "invocation": { - "name": "Resolve", - "parameters": reference, - } - }) - return response - - -class SecretsSource: - def __init__(self, client_id, core): - self.clientID = client_id - self.core = core diff --git a/src/sdk/client.py b/src/sdk/client.py index eef6853..7b7cd5f 100644 --- a/src/sdk/client.py +++ b/src/sdk/client.py @@ -12,12 +12,12 @@ class Client: - def __init__(self, auth="", integration_name="", integration_version=""): - self.config = NewDefaultConfig(auth=auth, integration_name=integration_name, integration_version=integration_version), + def __init__(self, auth, integration_name, integration_version): + self.config = new_default_config(auth=auth, integration_name=integration_name, integration_version=integration_version), self.secrets = Secrets(client_id=InitClient(self.config)), -def NewDefaultConfig(auth, integration_name, integration_version): +def new_default_config(auth, integration_name, integration_version): client_config_dict = { "SAToken": auth, "Language": SDK_LANGUAGE, @@ -27,7 +27,7 @@ def NewDefaultConfig(auth, integration_name, 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, + "SystemOSVersion": DEFAULT_OS_VERSION, + "SystemArch": platform.architecture()[0], } return client_config_dict diff --git a/src/tests/test_client.py b/src/tests/test_client.py new file mode 100644 index 0000000..ea94a91 --- /dev/null +++ b/src/tests/test_client.py @@ -0,0 +1,70 @@ +import unittest +from sdk import client as onepassword +import os + +TOKEN = os.environ['OP_SERVICE_ACCOUNT_TOKEN'] + +class TestPythonSDKClient(unittest.TestCase): + ## test resolve function + + # valid + def test_valid_resolve(self): + client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + result = client.secrets.resolve(reference="test_username") + self.assertEqual(result, "password") # "password" is a temporary placeholder, replace with actual secret value + + # invalid + def test_invalid_resolve(self): + client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + result = client.secrets.resolve(reference="invalid_reference") + + ## test client constructor + + # valid + def test_good_client_construction(self): + client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + + # invalid + def test_client_construction_no_auth(self): + client = onepassword.Client(auth=TOKEN, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + + # invalid + def test_client_construction_no_name(self): + client = onepassword.Client(integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + + # invalid + def test_client_construction_no_version(self): + client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME) + + ## test config function + + # valid + def test_good_new_default_config(self): + config = onepassword.new_default_config(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + + # the commented out assertions may be untestable as they are device-specific + self.assertEqual(config["SAToken"], TOKEN) + self.assertEqual(config["Language"], onepassword.SDK_LANGUAGE) + self.assertEqual(config["SDKVersion"], onepassword.SDK_VERSION) + self.assertEqual(config["IntegrationName"], onepassword.DEFAULT_INTEGRATION_NAME) + self.assertEqual(config["IntegrationVersion"], onepassword.DEFAULT_INTEGRATION_VERSION) + self.assertEqual(config["RequestLibraryName"], onepassword.DEFAULT_REQUEST_LIBRARY) + # self.assertEqual(config["RequestLibraryVersion"], ) + # self.assertEqual(config["SystemOS"],) + self.assertEqual(config["SystemOSVersion"], onepassword.DEFAULT_OS_VERSION) + # self.assertEqual(config["SystemArch"], ) + + # invalid + def test_new_default_config_no_auth(self): + config = onepassword.new_default_config(integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + + # invalid + def test_new_default_config_no_name(self): + config = onepassword.new_default_config(auth=TOKEN, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION) + + # invalid + def test_new_default_config_no_version(self): + config = onepassword.new_default_config(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file