Skip to content

Commit 65475d9

Browse files
committed
updating syntax to use permissions options
1 parent f8f7bcf commit 65475d9

File tree

6 files changed

+228
-102
lines changed

6 files changed

+228
-102
lines changed

migration/cleanup-scripts/move_items_to_tracked_vault.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def getVaults():
3737
vaults = []
3838
try:
3939
getVaultsCommand = subprocess.run(
40-
["op", "vault", "list", "--group=Owners", "--format=json"],
40+
["op", "vault", "list", "--permission=manage_vault", "--format=json"],
4141
check=True,
4242
capture_output=True,
4343
)

migration/cleanup-scripts/remove_imported_prefix.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,38 @@
44

55
def getVaults():
66
try:
7-
return subprocess.run("op vault list --group=Owners --format=json", shell=True, check=True, capture_output=True).stdout
8-
except (Exception) as err:
9-
print(f"Encountered an error getting the list of vaults you have access to: ", err)
7+
return subprocess.run(
8+
["op", "vault", "list", "--permission=manage_vault", "--format=json"],
9+
check=True,
10+
capture_output=True,
11+
).stdout
12+
except Exception as err:
13+
print(
14+
f"Encountered an error getting the list of vaults you have access to: ", err
15+
)
1016
return
1117

18+
1219
def main():
1320
vaultList = json.loads(getVaults())
14-
print("Removing 'Imported' prefix from all imported vaults in your 1Password account.\n\n")
21+
print(
22+
"Removing 'Imported' prefix from all imported vaults in your 1Password account.\n\n"
23+
)
1524
for vault in vaultList:
1625
vaultID = vault["id"]
1726
vaultName = vault["name"]
18-
if (vaultName.startswith("Imported ")):
27+
if vaultName.startswith("Imported "):
1928
trimmedName = vaultName.removeprefix("Imported ")
2029
try:
21-
subprocess.run(["op", "vault", "edit", vaultID, f"--name={trimmedName}"], check=True, capture_output=True)
22-
print(f"\t Changed \"{vaultName}\" => \"{trimmedName}\"")
23-
except (Exception) as err:
30+
subprocess.run(
31+
["op", "vault", "edit", vaultID, f"--name={trimmedName}"],
32+
check=True,
33+
capture_output=True,
34+
)
35+
print(f'\t Changed "{vaultName}" => "{trimmedName}"')
36+
except Exception as err:
2437
print(f"Encountered an error renaming {vaultName}: ", err)
2538
continue
2639

27-
main()
40+
41+
main()
Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###
2-
# A script that will produce a csv-like report to assist with de-duplication.
2+
# A script that will produce a csv-like report to assist with de-duplication.
33
# Outputs vaultName, vaultUUID, itemCount, vault creation date, vault updated, number of users
44
###
55
import os
@@ -11,42 +11,72 @@
1111
scriptPath = os.path.dirname(__file__)
1212
outputPath = scriptPath # Optionally choose an alternative output path here.
1313

14+
1415
# Get a list of vaults the logged-in user has access to
1516
def getVaults():
1617
try:
17-
return subprocess.run("op vault list --group=Owners --format=json", shell=True, check=True, capture_output=True).stdout
18-
except (Exception) as err:
19-
print(f"Encountered an error getting the list of vaults you have access to: ", err)
18+
return subprocess.run(
19+
["op", "vault", "list", "--permission=manage_vault", "--format=json"],
20+
check=True,
21+
capture_output=True,
22+
).stdout
23+
except Exception as err:
24+
print(
25+
f"Encountered an error getting the list of vaults you have access to: ", err
26+
)
2027
return
21-
28+
29+
2230
# Get a list of users and their permissions for a vault
2331
def getVaultUserList(vaultID):
2432
try:
25-
return subprocess.run(f"op vault user list {vaultID} --format=json", shell=True, check=True, capture_output=True).stdout
26-
except (Exception) as err:
27-
print(f"Encountered an error getting the list of users for vault {vaultID}: ", err)
33+
return subprocess.run(
34+
f"op vault user list {vaultID} --format=json",
35+
shell=True,
36+
check=True,
37+
capture_output=True,
38+
).stdout
39+
except Exception as err:
40+
print(
41+
f"Encountered an error getting the list of users for vault {vaultID}: ", err
42+
)
2843
return
2944

45+
3046
# Get the details of a vault
3147
def getVaultDetails(vaultID):
3248
try:
33-
return subprocess.run(f"op vault get {vaultID} --format=json", shell=True, check=True, capture_output=True).stdout
34-
except (Exception) as err:
49+
return subprocess.run(
50+
f"op vault get {vaultID} --format=json",
51+
shell=True,
52+
check=True,
53+
capture_output=True,
54+
).stdout
55+
except Exception as err:
3556
print(f"Encountered an error getting details for vault {vaultID}: ", err)
3657
return
3758

59+
3860
# Make dates returned from the CLI a bit nicer
3961
def formatDate(date):
4062
isoDate = datetime.fromisoformat(date)
4163
return f"{isoDate.year}-{isoDate.month}-{isoDate.day} {isoDate.hour}:{isoDate.minute}:{isoDate.second}"
4264

65+
4366
def main():
4467
vaultList = json.loads(getVaults())
4568
with open(f"{outputPath}/vaultreport.csv", "w", newline="") as outputFile:
4669
csvWriter = csv.writer(outputFile)
47-
fields = ["vaultName", "vaultUUD", "itemCount", "vaultCreated", "vaultUpdated", "userCount"]
70+
fields = [
71+
"vaultName",
72+
"vaultUUD",
73+
"itemCount",
74+
"vaultCreated",
75+
"vaultUpdated",
76+
"userCount",
77+
]
4878
csvWriter.writerow(fields)
49-
79+
5080
for vault in vaultList:
5181
if vault["name"] == "Private":
5282
continue
@@ -56,19 +86,25 @@ def main():
5686
dateCreated = formatDate(vaultDetails["created_at"])
5787
dateUpdated = formatDate(vaultDetails["updated_at"])
5888

59-
csvWriter.writerow([
89+
csvWriter.writerow(
90+
[
91+
vault["name"],
92+
vault["id"],
93+
vaultDetails["items"],
94+
dateCreated,
95+
dateUpdated,
96+
userCount,
97+
]
98+
)
99+
100+
print(
60101
vault["name"],
61102
vault["id"],
62103
vaultDetails["items"],
63104
dateCreated,
64105
dateUpdated,
65-
userCount
66-
])
67-
68-
print(vault["name"],
69-
vault["id"],
70-
vaultDetails["items"],
71-
dateCreated,
72-
dateUpdated,
73-
userCount)
74-
main()
106+
userCount,
107+
)
108+
109+
110+
main()

0 commit comments

Comments
 (0)