Skip to content

Commit 8be08fb

Browse files
committed
Add init function for exposing items and secrets APIs
1 parent b8c5e74 commit 8be08fb

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

example/example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import os
3-
from onepassword.client import Client
4-
from onepassword.types import Item, ItemField, ItemSection
3+
from onepassword import Client, Item, ItemField, ItemSection
54

65

76
async def main():

src/onepassword/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
from .defaults import DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION
33
from .secrets import Secrets
44
from .items import Items
5+
from .types import Item, ItemField, ItemSection
6+
57

68

79
__all__ = [
810
"Client",
911
"Secrets",
1012
"Items",
13+
"Item",
14+
"ItemField",
15+
"ItemSection",
1116
"DEFAULT_INTEGRATION_NAME",
1217
"DEFAULT_INTEGRATION_VERSION",
1318
]

src/onepassword/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66

77

88
class Client:
9+
def __init__(self, client_id):
10+
self.secrets = Secrets(client_id)
11+
self.items = Items(client_id)
12+
913
@classmethod
1014
async def authenticate(cls, auth, integration_name, integration_version):
11-
self = cls()
12-
13-
self.config = new_default_config(
15+
config = new_default_config(
1416
auth=auth,
1517
integration_name=integration_name,
1618
integration_version=integration_version,
1719
)
18-
client_id = int(await _init_client(self.config))
19-
20-
self.secrets = Secrets(client_id)
21-
self.items = Items(client_id)
20+
client_id = int(await _init_client(config))
21+
self = cls(client_id)
22+
self._config = config
2223
self._finalizer = weakref.finalize(self, _release_client, client_id)
2324

2425
return self

src/onepassword/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ async def test_good_client_construction():
4949
integration_name=onepassword_defaults.DEFAULT_INTEGRATION_NAME,
5050
integration_version=onepassword_defaults.DEFAULT_INTEGRATION_VERSION,
5151
)
52-
assert client.config["serviceAccountToken"] == TOKEN
52+
assert client._config["serviceAccountToken"] == TOKEN
5353
assert (
54-
client.config["integrationName"]
54+
client._config["integrationName"]
5555
== onepassword_defaults.DEFAULT_INTEGRATION_NAME
5656
)
5757
assert (
58-
client.config["integrationVersion"]
58+
client._config["integrationVersion"]
5959
== onepassword_defaults.DEFAULT_INTEGRATION_VERSION
6060
)
6161

0 commit comments

Comments
 (0)