Skip to content

Commit c503b37

Browse files
authored
Merge pull request #61 from 1Password/scottisloud/issue58
updating syntax to use permissions options
2 parents f8f7bcf + 732bd88 commit c503b37

File tree

9 files changed

+301
-107
lines changed

9 files changed

+301
-107
lines changed

account-management/remove-export-all-groups-and-vault.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
# This script requires `jq` is installed on your system. See: https://stedolan.github.io/jq/ for installation instructions.
1414

15-
vault_IDs=($(op vault list --format=json | jq --raw-output '.[] .id'))
15+
vault_IDs=($(op vault list --permission=manage_vault --format=json | jq --raw-output '.[] .id'))
1616

1717
for vault in $vault_IDs
1818
do

migration/cleanup-scripts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
This is a collection of scripts that can help you clean up your 1Password account after performing a migration from LastPass.
44

5-
> ⚠️ **Warning**
6-
> Currently, you must use version 2.21 or older of the 1Password CLI when running these scripts. Version 2.22 and newer introduced changes that prevent these scripts from performing as-expected. Download version 2.21 the 1Password website [here](https://app-updates.agilebits.com/product_history/CLI2#v2210002).
5+
> 💡 **NOTE**
6+
> Many of these scripts require version 2.25 or newer of the 1Password CLI. Download the latest version [here](https://developer.1password.com/docs/cli/get-started).
77
88
## Contents
99

migration/cleanup-scripts/move_items_to_tracked_vault.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ def __init__(self, name, uuid, itemCount, created, updated):
1717
self.updated = updated
1818

1919

20+
# Check CLI version
21+
def checkCLIVersion():
22+
r = subprocess.run(["op", "--version", "--format=json"], capture_output=True)
23+
major, minor = r.stdout.decode("utf-8").rstrip().split(".", 2)[:2]
24+
if not major == 2 and not int(minor) >= 25:
25+
sys.exit(
26+
"❌ You must be using version 2.25 or greater of the 1Password CLI. Please visit https://developer.1password.com/docs/cli/get-started to download the lastest version."
27+
)
28+
29+
2030
# Get a list of vaults the logged-in user has access to
2131
# Skips any Private vaults and the Metadata vault.
2232
# Fetches all vault details and returns them as a Python object
@@ -37,7 +47,7 @@ def getVaults():
3747
vaults = []
3848
try:
3949
getVaultsCommand = subprocess.run(
40-
["op", "vault", "list", "--group=Owners", "--format=json"],
50+
["op", "vault", "list", "--permission=manage_vault", "--format=json"],
4151
check=True,
4252
capture_output=True,
4353
)
@@ -294,6 +304,7 @@ def revokeUntrackedVaultPermissions(untrackedVaults):
294304

295305

296306
def main():
307+
checkCLIVersion()
297308
vaults = []
298309
vaultGroups = {}
299310
vaultDetails = getVaults()
Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,53 @@
11
import subprocess
22
import json
3+
import sys
4+
5+
6+
# Check CLI version
7+
def checkCLIVersion():
8+
r = subprocess.run(["op", "--version", "--format=json"], capture_output=True)
9+
major, minor = r.stdout.decode("utf-8").rstrip().split(".", 2)[:2]
10+
if not major == 2 and not int(minor) >= 25:
11+
sys.exit(
12+
"❌ You must be using version 2.25 or greater of the 1Password CLI. Please visit https://developer.1password.com/docs/cli/get-started to download the lastest version."
13+
)
314

415

516
def getVaults():
617
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)
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+
)
1027
return
1128

29+
1230
def main():
31+
checkCLIVersion()
1332
vaultList = json.loads(getVaults())
14-
print("Removing 'Imported' prefix from all imported vaults in your 1Password account.\n\n")
33+
print(
34+
"Removing 'Imported' prefix from all imported vaults in your 1Password account.\n\n"
35+
)
1536
for vault in vaultList:
1637
vaultID = vault["id"]
1738
vaultName = vault["name"]
18-
if (vaultName.startswith("Imported ")):
39+
if vaultName.startswith("Imported "):
1940
trimmedName = vaultName.removeprefix("Imported ")
2041
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:
42+
subprocess.run(
43+
["op", "vault", "edit", vaultID, f"--name={trimmedName}"],
44+
check=True,
45+
capture_output=True,
46+
)
47+
print(f'\t Changed "{vaultName}" => "{trimmedName}"')
48+
except Exception as err:
2449
print(f"Encountered an error renaming {vaultName}: ", err)
2550
continue
2651

27-
main()
52+
53+
main()
Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,94 @@
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
66
import subprocess
77
import csv
88
import json
99
from datetime import datetime
10+
import sys
1011

1112
scriptPath = os.path.dirname(__file__)
1213
outputPath = scriptPath # Optionally choose an alternative output path here.
1314

15+
16+
# Check CLI version
17+
def checkCLIVersion():
18+
r = subprocess.run(["op", "--version", "--format=json"], capture_output=True)
19+
major, minor = r.stdout.decode("utf-8").rstrip().split(".", 2)[:2]
20+
if not major == 2 and not int(minor) >= 25:
21+
sys.exit(
22+
"❌ You must be using version 2.25 or greater of the 1Password CLI. Please visit https://developer.1password.com/docs/cli/get-started to download the lastest version."
23+
)
24+
25+
1426
# Get a list of vaults the logged-in user has access to
1527
def getVaults():
1628
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)
29+
return subprocess.run(
30+
["op", "vault", "list", "--permission=manage_vault", "--format=json"],
31+
check=True,
32+
capture_output=True,
33+
).stdout
34+
except Exception as err:
35+
print(
36+
f"Encountered an error getting the list of vaults you have access to: ", err
37+
)
2038
return
21-
39+
40+
2241
# Get a list of users and their permissions for a vault
2342
def getVaultUserList(vaultID):
2443
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)
44+
return subprocess.run(
45+
f"op vault user list {vaultID} --format=json",
46+
shell=True,
47+
check=True,
48+
capture_output=True,
49+
).stdout
50+
except Exception as err:
51+
print(
52+
f"Encountered an error getting the list of users for vault {vaultID}: ", err
53+
)
2854
return
2955

56+
3057
# Get the details of a vault
3158
def getVaultDetails(vaultID):
3259
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:
60+
return subprocess.run(
61+
f"op vault get {vaultID} --format=json",
62+
shell=True,
63+
check=True,
64+
capture_output=True,
65+
).stdout
66+
except Exception as err:
3567
print(f"Encountered an error getting details for vault {vaultID}: ", err)
3668
return
3769

70+
3871
# Make dates returned from the CLI a bit nicer
3972
def formatDate(date):
4073
isoDate = datetime.fromisoformat(date)
4174
return f"{isoDate.year}-{isoDate.month}-{isoDate.day} {isoDate.hour}:{isoDate.minute}:{isoDate.second}"
4275

76+
4377
def main():
78+
checkCLIVersion()
4479
vaultList = json.loads(getVaults())
4580
with open(f"{outputPath}/vaultreport.csv", "w", newline="") as outputFile:
4681
csvWriter = csv.writer(outputFile)
47-
fields = ["vaultName", "vaultUUD", "itemCount", "vaultCreated", "vaultUpdated", "userCount"]
82+
fields = [
83+
"vaultName",
84+
"vaultUUD",
85+
"itemCount",
86+
"vaultCreated",
87+
"vaultUpdated",
88+
"userCount",
89+
]
4890
csvWriter.writerow(fields)
49-
91+
5092
for vault in vaultList:
5193
if vault["name"] == "Private":
5294
continue
@@ -56,19 +98,25 @@ def main():
5698
dateCreated = formatDate(vaultDetails["created_at"])
5799
dateUpdated = formatDate(vaultDetails["updated_at"])
58100

59-
csvWriter.writerow([
101+
csvWriter.writerow(
102+
[
103+
vault["name"],
104+
vault["id"],
105+
vaultDetails["items"],
106+
dateCreated,
107+
dateUpdated,
108+
userCount,
109+
]
110+
)
111+
112+
print(
60113
vault["name"],
61114
vault["id"],
62115
vaultDetails["items"],
63116
dateCreated,
64117
dateUpdated,
65-
userCount
66-
])
67-
68-
print(vault["name"],
69-
vault["id"],
70-
vaultDetails["items"],
71-
dateCreated,
72-
dateUpdated,
73-
userCount)
74-
main()
118+
userCount,
119+
)
120+
121+
122+
main()

reporting/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
This directory provides a series of scripts demonstrating how to use the CLI to generate summary reports of vault access, contents, and permissions.
44

5-
> ⚠️ **Warning**
6-
> Currently, you must use version 2.21 or older of the 1Password CLI when running these scripts. Version 2.22 and newer introduced changes that prevent these scripts from performing as-expected. Download version 2.21 the 1Password website [here](https://app-updates.agilebits.com/product_history/CLI2#v2210002).
5+
> 💡 **NOTE**
6+
> Many of these scripts require version 2.25 or newer of the 1Password CLI. Download the latest version [here](https://developer.1password.com/docs/cli/get-started).
77
88
## User vault access reports
99
The following scripts provide information about people who are directly granted access to vaults. It does not include groups.

0 commit comments

Comments
 (0)