Skip to content

Commit

Permalink
Merge pull request #3 from 1Password/friendly-naming
Browse files Browse the repository at this point in the history
Converting models to use more user friendly names
  • Loading branch information
jillianwilson authored Apr 12, 2021
2 parents 68907ba + 28c5440 commit f96c474
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 212 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ Create an item in the specified vault.

```python
# Example item creation. Create an item with your desired arguments.
item = onepasswordconnectsdk.models.FullItem(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
item = onepasswordconnectsdk.models.Item(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
id="kp2td65r4wbuhocwhhijpdbfqq",
title="newtitle",
category="LOGIN",
tags=["1password-connect"],
fields=[FullItemAllOfFields(value="new_user",
fields=[Field(value="new_user",
purpose="USERNAME")],
)
client.create_item("{vault_id}", item)
Expand All @@ -108,12 +108,12 @@ Item the item with the specified item and vault ids. The existing item will be o

```python
# Example item creation. Create an item with your desired arguments.
item = onepasswordconnectsdk.models.FullItem(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
item = onepasswordconnectsdk.models.Item(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
id="kp2td65r4wbuhocwhhijpdbfqq",
title="newtitle",
category="LOGIN",
tags=["1password-connect"],
fields=[FullItemAllOfFields(value="new_user",
fields=[Field(value="new_user",
purpose="USERNAME")],
)
client.update_item("{item_id}", "{vault_id}", item)
Expand Down
26 changes: 13 additions & 13 deletions src/onepasswordconnectsdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import datetime
from requests.exceptions import HTTPError
import onepasswordconnectsdk
from onepasswordconnectsdk.models import FullItem, ItemVault
from onepasswordconnectsdk.models import Item, ItemVault


ENV_SERVICE_ACCOUNT_JWT_VARIABLE = "OP_CONNECT_TOKEN"
Expand Down Expand Up @@ -73,7 +73,7 @@ def get_item(self, item_id: str, vault_id: str):
f"Unable to retrieve item. Received {response.status_code}\
for {url} with message: {response.json().get('message')}"
)
return self.deserialize(response.content, "FullItem")
return self.deserialize(response.content, "Item")

def get_item_by_title(self, title: str, vault_id: str):
"""Get a specific item by title
Expand Down Expand Up @@ -102,7 +102,7 @@ def get_item_by_title(self, title: str, vault_id: str):
title {title}"
)

return self.deserialize(response.content, "list[Item]")[0]
return self.deserialize(response.content, "list[SummaryItem]")[0]

def get_items(self, vault_id: str):
"""Returns a list of item summaries for the specified vault
Expand All @@ -115,7 +115,7 @@ def get_items(self, vault_id: str):
from the 1Password Connect API
Returns:
List[Item]: A list of summarized items
List[SummaryItem]: A list of summarized items
"""
url = f"/v1/vaults/{vault_id}/items"

Expand All @@ -128,7 +128,7 @@ def get_items(self, vault_id: str):
for {url} with message: {response.json().get('message')}"
)

return self.deserialize(response.content, "list[Item]")
return self.deserialize(response.content, "list[SummaryItem]")

def delete_item(self, item_id: str, vault_id: str):
"""Deletes a specified item from a specified vault
Expand All @@ -153,19 +153,19 @@ def delete_item(self, item_id: str, vault_id: str):
for {url} with message: {response.json().get('message')}"
)

def create_item(self, vault_id: str, item: FullItem):
def create_item(self, vault_id: str, item: Item):
"""Creates an item at the specified vault
Args:
vault_id (str): The id of the vault in which add the item to
item (FullItem): The item to create
item (Item): The item to create
Raises:
FailedToRetrieveItemException: Thrown when a HTTP error is returned
from the 1Password Connect API
Returns:
FullItem: The created item
Item: The created item
"""

url = f"/v1/vaults/{vault_id}/items"
Expand All @@ -178,22 +178,22 @@ def create_item(self, vault_id: str, item: FullItem):
f"Unable to post item. Received {response.status_code}\
for {url} with message: {response.json().get('message')}"
)
return self.deserialize(response.content, "FullItem")
return self.deserialize(response.content, "Item")

def update_item(self, item_uuid: str, vault_id: str, item: FullItem):
def update_item(self, item_uuid: str, vault_id: str, item: Item):
"""Update the specified item at the specified vault.
Args:
item_uuid (str): The id of the item in which to update
vault_id (str): The id of the vault in which to update the item
item (FullItem): The updated item
item (Item): The updated item
Raises:
FailedToRetrieveItemException: Thrown when a HTTP error is returned
from the 1Password Connect API
Returns:
FullItem: The updated item
Item: The updated item
"""
url = f"/v1/vaults/{vault_id}/items/{item_uuid}"
item.id = item_uuid
Expand All @@ -207,7 +207,7 @@ def update_item(self, item_uuid: str, vault_id: str, item: FullItem):
f"Unable to post item. Received {response.status_code}\
for {url} with message: {response.json().get('message')}"
)
return self.deserialize(response.content, "FullItem")
return self.deserialize(response.content, "Item")

def get_vault(self, vault_id: str):
"""Returns the vault with the given vault_id
Expand Down
8 changes: 4 additions & 4 deletions src/onepasswordconnectsdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from typing import List, Dict
from onepasswordconnectsdk.client import Client
from onepasswordconnectsdk.models import (
SummaryItem,
Item,
FullItem,
ParsedField,
ParsedItem,
FullItemAllOfSections,
Section,
)
from onepasswordconnectsdk.models.constants import (
ITEM_TAG,
Expand Down Expand Up @@ -173,7 +173,7 @@ def _set_values_for_item(
parsed_item.item_title, parsed_item.vault_uuid
)
# Fetching the full item
item: FullItem = client.get_item(summary_item.id, parsed_item.vault_uuid)
item: Item = client.get_item(summary_item.id, parsed_item.vault_uuid)

sections = _convert_sections_to_dict(item.sections)

Expand Down Expand Up @@ -215,7 +215,7 @@ def _set_values_for_item(
)


def _convert_sections_to_dict(sections: List[FullItemAllOfSections]):
def _convert_sections_to_dict(sections: List[Section]):
if not sections:
return {}
section_dict = {section.label: section.id for section in sections}
Expand Down
10 changes: 5 additions & 5 deletions src/onepasswordconnectsdk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

# import models into model package
from onepasswordconnectsdk.models.error import Error
from onepasswordconnectsdk.models.full_item import FullItem
from onepasswordconnectsdk.models.full_item_all_of import FullItemAllOf
from onepasswordconnectsdk.models.full_item_all_of_fields import FullItemAllOfFields
from onepasswordconnectsdk.models.full_item_all_of_section import FullItemAllOfSection
from onepasswordconnectsdk.models.full_item_all_of_sections import FullItemAllOfSections
from onepasswordconnectsdk.models.item import Item
from onepasswordconnectsdk.models.item_details import ItemDetails
from onepasswordconnectsdk.models.field import Field
from onepasswordconnectsdk.models.field_section import FieldSection
from onepasswordconnectsdk.models.section import Section
from onepasswordconnectsdk.models.summary_item import SummaryItem
from onepasswordconnectsdk.models.item_urls import ItemUrls
from onepasswordconnectsdk.models.item_vault import ItemVault
from onepasswordconnectsdk.models.parsed_field import ParsedField
Expand Down
Loading

0 comments on commit f96c474

Please sign in to comment.