-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset_organization.sh
executable file
·65 lines (43 loc) · 1.35 KB
/
set_organization.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# shellcheck disable=2154,2317
. lib/env.sh
log "set_organization ${objectId} ${organizationId}"
URL="${API}"/object/item
FIELDS="type, name, organizationId, login, notes, favorite, fields, reprompt"
# Get existing item
ITEM=$(curl -s "${URL}/${objectId}" | jq -j '.data | { '"${FIELDS}"' }')
oldId=$(jq -j '.organizationId // ""' <<< "${ITEM}")
if [ "${oldId}" == "${organizationId}" ]; then
echo -n "Cannot move item to same vault"
exit
fi
# Add new item
if [ "${organizationId}" == "" ]; then
PAYLOAD=$(jq -j '.ogranizationId |= null' <<< "${ITEM}")
else
PAYLOAD=$(jq -j '.organizationId |= "'"${organizationId}"'"' <<< "${ITEM}")
fi
log "${PAYLOAD}"
ITEM=$(curl -s -H 'Content-Type: application/json' -d "${PAYLOAD}" "${URL}")
S=$(jq -j '.success' <<< "${ITEM}")
if [ "${S}" != "true" ]; then
echo -n "Failed to copy ${name}"
exit
fi
echo -n "Success: ${S}"
saveSync
exit
# Replace ".collectionIds: null" with ".collectionIds: []"
newId=$(jq -j '.data.id' <<< "${ITEM}")
S=$(curl -s "${URL}/${newId}" \
| jq '.data | . + { .collectionIds: [] }' \
| curl -s -H 'Content-Type: application/json' -T - "${URL}/${newId}")
S=$(jq -j '.success' <<< "${ITEM}")
if [ "${S}" != "true" ]; then
echo -n "Failed to set collections for ${name}"
exit
fi
sleep 5
# Delete original
# curl -s -X DELETE "${URL}/${objectId}"
saveSync