Skip to content

Commit a4033e7

Browse files
1PasswordSDKBotedif2008
authored andcommitted
Add vault permission operations for groups
1 parent 2588608 commit a4033e7

File tree

8 files changed

+116
-3
lines changed

8 files changed

+116
-3
lines changed
14.5 KB
Binary file not shown.
-4.37 KB
Binary file not shown.
-2.18 KB
Binary file not shown.
-4.88 KB
Binary file not shown.
-7 KB
Binary file not shown.

src/onepassword/secrets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class Secrets:
1010
"""
1111
The Secrets API includes all operations the SDK client can perform on secrets.
12-
Use secret reference URIs to securely load secrets from 1Password: op://<vault-name>/<item-name>[/<section-name>]/<field-name>
12+
Use secret reference URIs to securely load secrets from 1Password: `op://<vault-name>/<item-name>[/<section-name>]/<field-name>`
1313
"""
1414

1515
def __init__(self, client_id, core: Core):

src/onepassword/types.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,47 @@ class Group(BaseModel):
242242
vault_access: Optional[List[VaultAccess]] = Field(alias="vaultAccess", default=None)
243243

244244

245+
class GroupAccess(BaseModel):
246+
"""
247+
Represents a group's access to a 1Password vault.
248+
This is used for granting permissions
249+
"""
250+
251+
group_id: str
252+
"""
253+
The group's ID
254+
"""
255+
permissions: int
256+
"""
257+
The group's set of permissions for the vault
258+
"""
259+
260+
245261
class GroupGetParams(BaseModel):
246262
model_config = ConfigDict(populate_by_name=True)
247263

248264
vault_permissions: Optional[bool] = Field(alias="vaultPermissions", default=None)
249265

250266

267+
class GroupVaultAccess(BaseModel):
268+
"""
269+
Represents a group's access to a 1Password vault.
270+
"""
271+
272+
vault_id: str
273+
"""
274+
The vault's ID
275+
"""
276+
group_id: str
277+
"""
278+
The group's ID
279+
"""
280+
permissions: int
281+
"""
282+
The group's set of permissions for the vault
283+
"""
284+
285+
251286
class ItemCategory(str, Enum):
252287
LOGIN = "Login"
253288
SECURENOTE = "SecureNote"
@@ -385,7 +420,7 @@ class AutofillBehavior(str, Enum):
385420
Controls the auto-fill behavior of a website.
386421
387422
388-
For more information, visit https://support.1password.com/autofill-behavior/
423+
For more information, visit <https://support.1password.com/autofill-behavior/>
389424
"""
390425

391426
ANYWHEREONWEBSITE = "AnywhereOnWebsite"
@@ -417,7 +452,7 @@ class Website(BaseModel):
417452
"""
418453
The auto-fill behavior of the website
419454
420-
For more information, visit https://support.1password.com/autofill-behavior/
455+
For more information, visit <https://support.1password.com/autofill-behavior/>
421456
"""
422457

423458

@@ -1493,3 +1528,19 @@ class WordListType(str, Enum):
14931528
"""
14941529
Three (random) letter "words"
14951530
"""
1531+
1532+
1533+
ARCHIVE_ITEMS: int = 256
1534+
CREATE_ITEMS: int = 128
1535+
DELETE_ITEMS: int = 512
1536+
EXPORT_ITEMS: int = 4194304
1537+
IMPORT_ITEMS: int = 2097152
1538+
MANAGE_VAULT: int = 2
1539+
NO_ACCESS: int = 0
1540+
PRINT_ITEMS: int = 8388608
1541+
READ_ITEMS: int = 32
1542+
RECOVER_VAULT: int = 1
1543+
REVEAL_ITEM_PASSWORD: int = 16
1544+
SEND_ITEMS: int = 1048576
1545+
UPDATE_ITEMS: int = 64
1546+
UPDATE_ITEM_HISTORY: int = 1024

src/onepassword/vaults.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from typing import Optional, List
55
from pydantic import TypeAdapter
66
from .types import (
7+
GroupAccess,
8+
GroupVaultAccess,
79
Vault,
810
VaultGetParams,
911
VaultListParams,
@@ -73,3 +75,63 @@ async def get(self, vault_uuid: str, vault_params: VaultGetParams) -> Vault:
7375

7476
response = TypeAdapter(Vault).validate_json(response)
7577
return response
78+
79+
async def grant_group_permissions(
80+
self, vault_id: str, group_permissions_list: List[GroupAccess]
81+
) -> None:
82+
response = await self.core.invoke(
83+
{
84+
"invocation": {
85+
"clientId": self.client_id,
86+
"parameters": {
87+
"name": "VaultsGrantGroupPermissions",
88+
"parameters": {
89+
"vault_id": vault_id,
90+
"group_permissions_list": [
91+
o.model_dump(by_alias=True)
92+
for o in group_permissions_list
93+
],
94+
},
95+
},
96+
}
97+
}
98+
)
99+
100+
return None
101+
102+
async def update_group_permissions(
103+
self, group_permissions_list: List[GroupVaultAccess]
104+
) -> None:
105+
response = await self.core.invoke(
106+
{
107+
"invocation": {
108+
"clientId": self.client_id,
109+
"parameters": {
110+
"name": "VaultsUpdateGroupPermissions",
111+
"parameters": {
112+
"group_permissions_list": [
113+
o.model_dump(by_alias=True)
114+
for o in group_permissions_list
115+
]
116+
},
117+
},
118+
}
119+
}
120+
)
121+
122+
return None
123+
124+
async def revoke_group_permissions(self, vault_id: str, group_id: str) -> None:
125+
response = await self.core.invoke(
126+
{
127+
"invocation": {
128+
"clientId": self.client_id,
129+
"parameters": {
130+
"name": "VaultsRevokeGroupPermissions",
131+
"parameters": {"vault_id": vault_id, "group_id": group_id},
132+
},
133+
}
134+
}
135+
)
136+
137+
return None

0 commit comments

Comments
 (0)