summaryrefslogtreecommitdiff
path: root/integration-cli/fixtures/auth/docker-credential-shell-test
blob: 5acab521795ee93a6caff241e03e2e6ec272f018 (plain)
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
#!/usr/bin/env bash

set -e

listFile=shell_test_list.json

case $1 in
	"store")
		in=$(< /dev/stdin)
		server=$(echo "$in" | jq --raw-output ".ServerURL")
		serverHash=$(echo "$server" | sha1sum - | awk '{print $1}')

		username=$(echo "$in" | jq --raw-output ".Username")
		password=$(echo "$in" | jq --raw-output ".Secret")
		echo "{ \"Username\": \"${username}\", \"Secret\": \"${password}\" }" > $TEMP/$serverHash
		# add the server to the list file
		if [[ ! -f $TEMP/$listFile ]]; then
			echo "{ \"${server}\": \"${username}\" }" > $TEMP/$listFile
		else
			list=$(< $TEMP/$listFile)
			echo "$list" | jq ". + {\"${server}\": \"${username}\"}" > $TEMP/$listFile
		fi
		;;
	"get")
		in=$(< /dev/stdin)
		serverHash=$(echo "$in" | sha1sum - | awk '{print $1}')
		if [[ ! -f $TEMP/$serverHash ]]; then
			echo "credentials not found in native keychain"
			exit 1
		fi
		payload=$(< $TEMP/$serverHash)
		echo "$payload"
		;;
	"erase")
		in=$(< /dev/stdin)
		serverHash=$(echo "$in" | sha1sum - | awk '{print $1}')
		rm -f $TEMP/$serverHash

		# Remove the server from the list
		list=$(< $TEMP/$listFile)
		echo "$list" | jq "del(.[\"${in}\"])" > $TEMP/$listFile
		;;
	"list")
		if [[ ! -f $TEMP/$listFile ]]; then
			echo "{}"
		else
			payload=$(< $TEMP/$listFile)
			echo "$payload"
		fi
		;;
	*)
		echo "unknown credential option"
		exit 1
		;;
esac