-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_key.sh
49 lines (43 loc) · 1.63 KB
/
api_key.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
#!/bin/bash
#######################################
# Create an Ingestion API key for SUSE Observability
# Output:
# The ingestion API key
# Arguments:
# url (SUSE Observability)
# service_token (SUSE Observability)
# cluster_name
# Examples:
# observability_create_ingestion_api_key https://obs.suse.com/ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx demo
#######################################
observability_create_ingestion_api_key() {
local url=$1
local service_token=$2
local cluster_name=$3
local resp
resp=$(/usr/local/bin/sts ingestion-api-key create --name $cluster_name -o json --url $url --service-token $service_token)
echo $resp | jq -r '."ingestion-api-key".apiKey'
}
#######################################
# Delete an Ingestion API key for SUSE Observability
# Arguments:
# url (SUSE Observability)
# service_token (SUSE Observability)
# cluster_name
# Examples:
# observability_delete_ingestion_api_key https://obs.suse.com/ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx demo
#######################################
observability_delete_ingestion_api_key() {
local url=$1
local service_token=$2
local cluster_name=$3
local keys key_id
keys=$(/usr/local/bin/sts ingestion-api-key list -o json --url $url --service-token $service_token)
key_id=$(echo $keys | jq -r '."ingestion-api-keys"[] | select(.name == "'$cluster_name'") | .id')
if [ -n "$key_id" ]; then
/usr/local/bin/sts ingestion-api-key delete --id $key_id --url $url --service-token $service_token
echo ">>> Ingestion API key for cluster '${cluster_name}' deleted"
else
echo ">>> Ingestion API key for cluster '${cluster_name}' not found"
fi
}