From 8bffc7fddf92e400410e060b7ade975d729da76c Mon Sep 17 00:00:00 2001 From: AndyTitu Date: Wed, 12 Jun 2024 12:36:34 +0300 Subject: [PATCH 1/4] Export types correctly --- example/example.py | 11 +++++------ src/onepassword/__init__.py | 6 ++++-- src/onepassword/types.py | 24 +++++++++++------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/example/example.py b/example/example.py index 4e1c6431..5d9a81ba 100644 --- a/example/example.py +++ b/example/example.py @@ -2,7 +2,6 @@ import os from onepassword import * - async def main(): # Gets your service account token from the OP_SERVICE_ACCOUNT_TOKEN environment variable. token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN") @@ -16,15 +15,15 @@ async def main(): ) # Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points. - value = await client.secrets.resolve("op://vault/item/field") - print(value) + # value = await client.secrets.resolve("op://vault/item/field") + # print(value) # Create an Item and add it to your vault. to_create = Item( id="", title="MyName", category="Login", - vault_id="vault_id", + vault_id="q73bqltug6xoegr3wkk2zkenoq", fields=[ ItemField( id="username", @@ -48,7 +47,7 @@ async def main(): print(dict(created_item)) # Retrieve an item from your vault. - item = await client.items.get("vault_id", created_item.id) + item = await client.items.get(created_item.vault_id, created_item.id) print(dict(item)) @@ -59,7 +58,7 @@ async def main(): print(dict(updated_item)) # Delete a item from your vault. - await client.items.delete("vault_id", updated_item.id) + await client.items.delete(created_item.vault_id, updated_item.id) if __name__ == "__main__": diff --git a/src/onepassword/__init__.py b/src/onepassword/__init__.py index ccc0f59f..1287b5fb 100644 --- a/src/onepassword/__init__.py +++ b/src/onepassword/__init__.py @@ -5,6 +5,7 @@ from .secrets import Secrets from .items import Items +import sys, inspect, typing __all__ = [ "Client", @@ -14,5 +15,6 @@ "DEFAULT_INTEGRATION_VERSION", ] -if hasattr(types, "__all__"): - __all__ += types.__all__ +for name, obj in inspect.getmembers(sys.modules["onepassword.types"]): + if inspect.isclass(obj) or type(eval(name)) == typing._LiteralGenericAlias: + __all__.append(name) diff --git a/src/onepassword/types.py b/src/onepassword/types.py index 68cb92a1..690b0909 100644 --- a/src/onepassword/types.py +++ b/src/onepassword/types.py @@ -2,21 +2,10 @@ Generated by typeshare 1.9.2 """ -from __future__ import annotations - from pydantic import BaseModel from typing import List, Literal, Optional -class Item(BaseModel): - id: str - title: str - category: ItemCategory - vault_id: str - fields: List[ItemField] - sections: List[ItemSection] - - ItemCategory = Literal[ "Login", "SecureNote", @@ -45,6 +34,9 @@ class Item(BaseModel): ] +ItemFieldType = Literal["Text", "Concealed", "Unsupported"] + + class ItemField(BaseModel): id: str title: str @@ -53,9 +45,15 @@ class ItemField(BaseModel): value: str -ItemFieldType = Literal["Text", "Concealed", "Unsupported"] +class ItemSection(BaseModel): + id: str + title: str -class ItemSection(BaseModel): +class Item(BaseModel): id: str title: str + category: ItemCategory + vault_id: str + fields: List[ItemField] + sections: List[ItemSection] From aa81fda05af3ddd18179a57d55991fbe3f9e835f Mon Sep 17 00:00:00 2001 From: AndyTitu Date: Wed, 12 Jun 2024 12:49:39 +0300 Subject: [PATCH 2/4] Exclude example from ruff linting and add extra check in init.py --- .github/workflows/validate.yml | 2 +- example/example.py | 4 ++-- src/onepassword/__init__.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 6ba0c2c9..f1ad4bda 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -47,5 +47,5 @@ jobs: - name: Lint with Ruff run: | pip install ruff - ruff check --output-format=github --exclude=src/onepassword/lib/ . + ruff check --output-format=github --exclude=src/onepassword/lib/,example/ . continue-on-error: true diff --git a/example/example.py b/example/example.py index 5d9a81ba..bb25116e 100644 --- a/example/example.py +++ b/example/example.py @@ -15,8 +15,8 @@ async def main(): ) # Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points. - # value = await client.secrets.resolve("op://vault/item/field") - # print(value) + value = await client.secrets.resolve("op://vault/item/field") + print(value) # Create an Item and add it to your vault. to_create = Item( diff --git a/src/onepassword/__init__.py b/src/onepassword/__init__.py index 1287b5fb..5beacb13 100644 --- a/src/onepassword/__init__.py +++ b/src/onepassword/__init__.py @@ -16,5 +16,6 @@ ] for name, obj in inspect.getmembers(sys.modules["onepassword.types"]): - if inspect.isclass(obj) or type(eval(name)) == typing._LiteralGenericAlias: + # Add all classes and instances of typing.Literal defined in types.py. + if (inspect.isclass(obj) and inspect.getmodule(obj) == sys.modules["onepassword.types"]) or type(eval(name)) == typing._LiteralGenericAlias: __all__.append(name) From 9b36021735fbf3a1bc4653d5ea756f0f498ec713 Mon Sep 17 00:00:00 2001 From: AndyTitu Date: Wed, 12 Jun 2024 15:20:28 +0300 Subject: [PATCH 3/4] Restore types --- src/onepassword/types.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/onepassword/types.py b/src/onepassword/types.py index 690b0909..68cb92a1 100644 --- a/src/onepassword/types.py +++ b/src/onepassword/types.py @@ -2,10 +2,21 @@ Generated by typeshare 1.9.2 """ +from __future__ import annotations + from pydantic import BaseModel from typing import List, Literal, Optional +class Item(BaseModel): + id: str + title: str + category: ItemCategory + vault_id: str + fields: List[ItemField] + sections: List[ItemSection] + + ItemCategory = Literal[ "Login", "SecureNote", @@ -34,9 +45,6 @@ ] -ItemFieldType = Literal["Text", "Concealed", "Unsupported"] - - class ItemField(BaseModel): id: str title: str @@ -45,15 +53,9 @@ class ItemField(BaseModel): value: str -class ItemSection(BaseModel): - id: str - title: str +ItemFieldType = Literal["Text", "Concealed", "Unsupported"] -class Item(BaseModel): +class ItemSection(BaseModel): id: str title: str - category: ItemCategory - vault_id: str - fields: List[ItemField] - sections: List[ItemSection] From b88184f5e34cc5b0da1b6fbec9a7fcc2b602ce8f Mon Sep 17 00:00:00 2001 From: AndyTitu Date: Wed, 12 Jun 2024 15:30:17 +0300 Subject: [PATCH 4/4] Fix linter --- src/onepassword/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/onepassword/__init__.py b/src/onepassword/__init__.py index 5beacb13..47d5167f 100644 --- a/src/onepassword/__init__.py +++ b/src/onepassword/__init__.py @@ -5,7 +5,9 @@ from .secrets import Secrets from .items import Items -import sys, inspect, typing +import sys +import inspect +import typing __all__ = [ "Client",