Skip to content

Commit 732bd88

Browse files
committed
Adding version check function where 2.25 or greater is requied
1 parent daee44f commit 732bd88

File tree

7 files changed

+69
-1
lines changed

7 files changed

+69
-1
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/move_items_to_tracked_vault.py

Lines changed: 11 additions & 0 deletions
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
@@ -294,6 +304,7 @@ def revokeUntrackedVaultPermissions(untrackedVaults):
294304

295305

296306
def main():
307+
checkCLIVersion()
297308
vaults = []
298309
vaultGroups = {}
299310
vaultDetails = getVaults()

migration/cleanup-scripts/remove_imported_prefix.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
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():
@@ -17,6 +28,7 @@ def getVaults():
1728

1829

1930
def main():
31+
checkCLIVersion()
2032
vaultList = json.loads(getVaults())
2133
print(
2234
"Removing 'Imported' prefix from all imported vaults in your 1Password account.\n\n"

migration/cleanup-scripts/vault_dedupe_helper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
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

1415

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+
1526
# Get a list of vaults the logged-in user has access to
1627
def getVaults():
1728
try:
@@ -64,6 +75,7 @@ def formatDate(date):
6475

6576

6677
def main():
78+
checkCLIVersion()
6779
vaultList = json.loads(getVaults())
6880
with open(f"{outputPath}/vaultreport.csv", "w", newline="") as outputFile:
6981
csvWriter = csv.writer(outputFile)

reporting/user-and-item-list.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
outputPath = scriptPath # Optionally choose an alternative output path here.
2424

2525

26+
# Check CLI version
27+
def checkCLIVersion():
28+
r = subprocess.run(["op", "--version", "--format=json"], capture_output=True)
29+
major, minor = r.stdout.decode("utf-8").rstrip().split(".", 2)[:2]
30+
if not major == 2 and not int(minor) >= 25:
31+
sys.exit(
32+
"❌ 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."
33+
)
34+
35+
2636
# get the UUID of the user running the CLI script for use elsewhere in the script.
2737
def getMyUUID():
2838
subprocess.run(["op signin"], shell=True, check=True)
@@ -146,6 +156,7 @@ def removeViewPermissions(vaultUserData, vaultUUID):
146156

147157

148158
def main():
159+
checkCLIVersion()
149160
if inputFilePath is None:
150161
try:
151162
vaultList = json.loads(getAllOwnerVaults())

reporting/vault-user-access-report.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
outputPath = scriptPath # Optionally choose an alternative output path here.
2424

2525

26+
# Check CLI version
27+
def checkCLIVersion():
28+
r = subprocess.run(["op", "--version", "--format=json"], capture_output=True)
29+
major, minor = r.stdout.decode("utf-8").rstrip().split(".", 2)[:2]
30+
if not major == 2 and not int(minor) >= 25:
31+
sys.exit(
32+
"❌ 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."
33+
)
34+
35+
2636
# get a list of vaults the logged-in user has access to
2737
def getAllOwnerVaults():
2838
vaultList = subprocess.run(
@@ -72,6 +82,7 @@ def getVaultGroupList(vaultID):
7282
# Given a list of vaults, for each vault, list the users that have access along with their permissions.
7383
# Write the results to a csv file with columns: "vaultName", "vaultUUID", "name","email", "userUUID", "permissions"
7484
def main():
85+
checkCLIVersion()
7586
if inputFilePath is None:
7687
try:
7788
vaultList = json.loads(getAllOwnerVaults())

reporting/vault-user-group-access-report.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ def getByID(cls, vaultID):
5959
return vault
6060

6161

62+
# Check CLI version
63+
def checkCLIVersion():
64+
r = subprocess.run(["op", "--version", "--format=json"], capture_output=True)
65+
major, minor = r.stdout.decode("utf-8").rstrip().split(".", 2)[:2]
66+
if not major == 2 and not int(minor) >= 25:
67+
sys.exit(
68+
"❌ 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."
69+
)
70+
71+
6272
def getAllOwnerVaults():
6373
vaultList = subprocess.run(
6474
["op", "vault", "list", "--permission=manage_vault", "--format=json"],
@@ -157,6 +167,7 @@ def writeReport(vaults: Vault):
157167

158168

159169
def main():
170+
checkCLIVersion()
160171
counter = 1
161172
# Populate initial data
162173
try:

0 commit comments

Comments
 (0)