Skip to content

Commit 797521b

Browse files
Merge pull request #4556 from communitybridge/unicron-cla-authorization
Added utils/investigation scripts
2 parents feae44e + 04626fe commit 797521b

File tree

8 files changed

+259
-0
lines changed

8 files changed

+259
-0
lines changed

utils/check_unique.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# PROD=1
3+
# LIM=10
4+
# DEBUG=1
5+
if [ -z "$LIM" ]
6+
then
7+
lim=1
8+
else
9+
lim=$LIM
10+
fi
11+
if [ -z "$PROD" ]
12+
then
13+
schema='dynamodb_product_us_east1_dev'
14+
prefix='cla_dev_'
15+
else
16+
schema='dynamodb_product_us_east_1'
17+
prefix='cla_prod_'
18+
fi
19+
if [ -z "$1" ]
20+
then
21+
echo "you need to specify table to query as a 1st parameter, for example 'signatures'"
22+
echo "possible tables include: approvals, ccla_whitelist_requests, cla_manager_requests, companies, company_invites, events, gerrit_instances, github_orgs, gitlab_orgs, metrics, projects, projects_cla_groups, repositories, session_store, signatures, store, user_permissions, users"
23+
exit 1
24+
fi
25+
if [ -z "$2" ]
26+
then
27+
echo "$0: required argument - list of columns to check for uniqueness on $1, example: 'lf_username user_company_id'"
28+
exit 2
29+
fi
30+
query="select"
31+
ary=($2)
32+
n=0
33+
for c in "${ary[@]}"
34+
do
35+
if [ -z "${cols}" ]
36+
then
37+
cols="data:${c}"
38+
cond="where ${cols} is not null"
39+
else
40+
cols="${cols}, data:${c}"
41+
cond="${cond} and data:${c} is not null"
42+
fi
43+
done
44+
query="${query} ${cols}, count(*) as cnt from fivetran_ingest.${schema}.${prefix}${1} ${cond} group by all"
45+
query="select i.* from (${query}) i where i.cnt > 1 order by i.cnt desc limit ${lim}"
46+
if [ ! -z "$DEBUG" ]
47+
then
48+
echo "query: ${query}"
49+
fi
50+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=true -o timing=false -o output_format=plain -q "${query}"

utils/cla_authorization.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# API_URL=https://[xyz].ngrok-free.app (defaults to localhost:5000)
3+
# cla_group='b71c469a-55e7-492c-9235-fd30b31da2aa' (ONAP)
4+
# lfid='lflgryglicki'
5+
# TOKEN='...' - Auth0 JWT bearer token
6+
# XACL='...' - X-ACL
7+
# API_URL='https://api-gw.platform.linuxfoundation.org/cla-service/v4/cla-service/v4/'
8+
# DEBUG=1 ./utils/cla_group_corporate_contributors.sh b71c469a-55e7-492c-9235-fd30b31da2aa andreasgeissler
9+
10+
if [ -z "$TOKEN" ]
11+
then
12+
# source ./auth0_token.secret
13+
TOKEN="$(cat ./auth0.token.secret)"
14+
fi
15+
16+
if [ -z "$TOKEN" ]
17+
then
18+
echo "$0: TOKEN not specified and unable to obtain one"
19+
exit 1
20+
fi
21+
22+
if [ -z "$XACL" ]
23+
then
24+
XACL="$(cat ./x-acl.secret)"
25+
fi
26+
27+
if [ -z "$XACL" ]
28+
then
29+
echo "$0: XACL not specified and unable to obtain one"
30+
exit 2
31+
fi
32+
33+
if [ -z "$1" ]
34+
then
35+
echo "$0: you need to specify cla_group UUID as a 1st parameter, example: 'b71c469a-55e7-492c-9235-fd30b31da2aa', '01af041c-fa69-4052-a23c-fb8c1d3bef24'"
36+
exit 3
37+
fi
38+
export cla_group="$1"
39+
40+
if [ -z "$2" ]
41+
then
42+
echo "$0: you need to specify lfid as a 2nd parameter, example: 'andreasgeissler'"
43+
exit 4
44+
fi
45+
export lfid="$2"
46+
47+
if [ -z "$API_URL" ]
48+
then
49+
export API_URL="http://localhost:5000"
50+
fi
51+
52+
if [ ! -z "$DEBUG" ]
53+
then
54+
echo "curl -s -XGET -H 'X-ACL: ${XACL}' -H 'Authorization: Bearer ${TOKEN}' -H 'Content-Type: application/json' '${API_URL}/v4/cla-services/cla/authorization?lfid=${lfid}&claGroupId=${cla_group}'"
55+
fi
56+
curl -s -XGET -H "X-ACL: ${XACL}" -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" "${API_URL}/v4/cla/authorization?lfid=${lfid}&claGroupId=${cla_group}"

utils/lookup_cla_group_sf.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
if [ -z "$1" ]
3+
then
4+
echo "$0: you need to specify which column as a 1st parameter, for example: 'cla_group_name'"
5+
echo "possible columns include: project_sfid, cla_group_id, cla_group_name, date_created, date_modified, foundation_name, foundation_sfid, note, project_external_id, project_name, repositories_count, version"
6+
exit 1
7+
fi
8+
if [ -z "$2" ]
9+
then
10+
echo "$0: you need to specify '${1}' value as a 2nd parameter, for example: 'onap'"
11+
exit 2
12+
fi
13+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=false -o timing=false -o output_format=plain -q "select object_construct('project_sfid', project_sfid, 'data', data) from fivetran_ingest.DYNAMODB_PRODUCT_US_EAST_1.CLA_PROD_PROJECTS_CLA_GROUPS where lower(data:${1}) = lower('${2}')" | jq -r '.'

utils/lookup_examples.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
./utils/lookup_sf.sh gerrit_instances gerrit_id project_sfid "'a09P000000DsCE5IAN'"
3+
./utils/lookup_sf.sh projects_cla_groups project_sfid project_sfid "'a09P000000DsCE5IAN'"
4+
OP=in ./utils/lookup_sf.sh user_permissions username projects "'a09P000000DsCE5IAN'"
5+
./utils/lookup_sf.sh signatures signature_id signature_type "'ecla'"
6+
./utils/lookup_sf.sh signatures signature_id project_id "'01af041c-fa69-4052-a23c-fb8c1d3bef24'"
7+
./utils/cla_authorization.sh 01af041c-fa69-4052-a23c-fb8c1d3bef24 poojapanjwani
8+
./utils/lookup_sf.sh projects_cla_groups project_sfid cla_group_id "'01af041c-fa69-4052-a23c-fb8c1d3bef24'"
9+
./utils/lookup_sf.sh companies company_id company_id "'f7c7ac9c-4dbf-4104-ab3f-6b38a26d82dc'"
10+
OUT='project_name' ./utils/lookup_sf.sh projects project_id project_id "'01af041c-fa69-4052-a23c-fb8c1d3bef24'"
11+
OUT='project_sfid project_name foundation_sfid' ./utils/lookup_sf.sh projects_cla_groups project_sfid foundation_sfid "'a09P000000DsCE5IAN'"
12+
# ICLA
13+
COND="data:signature_project_id = '01af041c-fa69-4052-a23c-fb8c1d3bef24' and data:signature_reference_id = '1527f0ec-3272-11ec-a3ed-0e7521e28b4e' and data:signature_type = 'cla' and data:signature_reference_type = 'user' and data:signature_user_ccla_company_id is null and data:signature_signed and data:signature_approved" ./utils/lookup_sf.sh signatures signature_id
14+
# ECLA
15+
COND="data:signature_reference_id = '1527f0ec-3272-11ec-a3ed-0e7521e28b4e' and data:signature_user_ccla_company_id = 'f7c7ac9c-4dbf-4104-ab3f-6b38a26d82dc' and data:signature_project_id = '01af041c-fa69-4052-a23c-fb8c1d3bef24'" ./utils/lookup_sf.sh signatures signature_id
16+
# CCLA
17+
COND="data:signature_project_id = '01af041c-fa69-4052-a23c-fb8c1d3bef24' and data:signature_reference_id = 'f7c7ac9c-4dbf-4104-ab3f-6b38a26d82dc' and data:signature_type = 'ccla' and data:signature_reference_type = 'company' and data:signature_user_ccla_company_id is null and data:signature_approved and data:signature_signed" ./utils/lookup_sf.sh signatures signature_id

utils/lookup_sf.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
# PROD=1
3+
# DEBUG=1
4+
# FUNC=lower
5+
# OP=in
6+
# COND='complex expression'
7+
# OUT='col1 col 2 col3'
8+
# example:
9+
# DEBUG=1 PROD=1 FUNC=lower ./utils/lookup_sf.sh projects_cla_groups project_sfid cla_group_name "lower('onap')"
10+
# OUT='project_sfid project_name foundation_sfid' ./utils/lookup_sf.sh projects_cla_groups project_sfid foundation_sfid "'a09P000000DsCE5IAN'"
11+
12+
if [ -z "$PROD" ]
13+
then
14+
schema='dynamodb_product_us_east1_dev'
15+
prefix='cla_dev_'
16+
else
17+
schema='dynamodb_product_us_east_1'
18+
prefix='cla_prod_'
19+
fi
20+
if [ -z "$1" ]
21+
then
22+
echo "you need to specify table to query as a 1st parameter, for example 'signatures'"
23+
echo "possible tables include: approvals, ccla_whitelist_requests, cla_manager_requests, companies, company_invites, events, gerrit_instances, github_orgs, gitlab_orgs, metrics, projects, projects_cla_groups, repositories, session_store, signatures, store, user_permissions, users"
24+
exit 1
25+
fi
26+
if [ -z "$2" ]
27+
then
28+
echo "you need to specify table's primary key column name as a 2nd parameter, see example row from the table to determine one:"
29+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=true -o timing=false -o output_format=plain -q "select * from fivetran_ingest.${schema}.${prefix}${1} limit 1"
30+
exit 2
31+
fi
32+
if [ -z "$COND" ]
33+
then
34+
if [ -z "$3" ]
35+
then
36+
echo "$0: you need to specify $1 column as a 3rd parameter, see available columns to choose one:"
37+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=false -o timing=false -o output_format=plain -q "select object_construct('${2}', ${2}, 'data', data) from fivetran_ingest.${schema}.${prefix}${1} limit 1"
38+
exit 3
39+
fi
40+
if [ -z "$4" ]
41+
then
42+
echo "$0: you need to specify ${1} ${3} value as a 4th parameter"
43+
echo "$0: if that column is strinf then you need to specify like this: \"'value'\""
44+
exit 4
45+
fi
46+
if [ "$3" = "$2" ]
47+
then
48+
col="$2"
49+
else
50+
col="data:${3}"
51+
fi
52+
if [ ! -z "$FUNC" ]
53+
then
54+
col="${FUNC}(${col})"
55+
fi
56+
if [ "$OP" = "in" ]
57+
then
58+
cond="array_contains(${4}::variant, ${col})"
59+
else
60+
cond="${col} = ${4}"
61+
fi
62+
else
63+
cond="${COND}"
64+
fi
65+
if [ ! -z "$DEBUG" ]
66+
then
67+
echo "snowsql $(cat ./snowflake.secret) -o friendly=false -o header=false -o timing=false -o output_format=plain -q \"select object_construct('${2}', ${2}, 'data', data) from fivetran_ingest.${schema}.${prefix}${1} where ${cond}\""
68+
fi
69+
if [ ! -z "$OUT" ]
70+
then
71+
cols=($OUT)
72+
n=0
73+
for c in "${cols[@]}"
74+
do
75+
if [ "$c" = "$2" ]
76+
then
77+
cc=".${c}"
78+
else
79+
cc=".data.${c}"
80+
fi
81+
if [ -z "${jqq}" ]
82+
then
83+
jqq="${cc}"
84+
else
85+
jqq="${jqq},${cc}"
86+
fi
87+
n=$((n + 1))
88+
done
89+
if [[ $n -gt 1 ]]
90+
then
91+
jqq="[${jqq}]"
92+
fi
93+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=false -o timing=false -o output_format=plain -q "select object_construct('${2}', ${2}, 'data', data) from fivetran_ingest.${schema}.${prefix}${1} where ${cond}" | jq -r "${jqq}"
94+
else
95+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=false -o timing=false -o output_format=plain -q "select object_construct('${2}', ${2}, 'data', data) from fivetran_ingest.${schema}.${prefix}${1} where ${cond}" | jq -r '.'
96+
fi

utils/lookup_user_by_lfid.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
if [ -z "$1" ]
3+
then
4+
echo "$0: you need to specify lfid as a 1st parameter, for example: 'lgryglicki'"
5+
exit 1
6+
fi
7+
aws --profile lfproduct-prod dynamodb query --table-name cla-prod-users --index-name lf-username-index --key-condition-expression "lf_username = :name" --expression-attribute-values "{\":name\":{\"S\":\"${1}\"}}" | jq -r '.'

utils/lookup_user_by_lfid_sf.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
if [ -z "$1" ]
3+
then
4+
echo "$0: you need to specify lfid as a 1st parameter, for example: 'lgryglicki'"
5+
exit 1
6+
fi
7+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=false -o timing=false -o output_format=plain -q "select object_construct('user_id', user_id, 'data', data) from fivetran_ingest.DYNAMODB_PRODUCT_US_EAST_1.CLA_PROD_USERS where lower(data:lf_username) = lower('${1}')" | jq -r '.'

utils/lookup_user_sf.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
if [ -z "$1" ]
3+
then
4+
echo "$0: you need to specify which column as a 1st parameter, for example: 'lf_username'"
5+
echo "possible columns include: user_id, admin, date_created, date_modified, lf_email, lf_username, note, user_company_id, user_emails, user_external_id, user_github_id, user_github_username, user_name, version"
6+
exit 1
7+
fi
8+
if [ -z "$2" ]
9+
then
10+
echo "$0: you need to specify '${1}' value as a 2nd parameter, for example: 'lgryglicki'"
11+
exit 2
12+
fi
13+
snowsql $(cat ./snowflake.secret) -o friendly=false -o header=false -o timing=false -o output_format=plain -q "select object_construct('user_id', user_id, 'data', data) from fivetran_ingest.dynamodb_product_us_east_1.cla_prod_users where lower(data:${1}) = lower('${2}')" | jq -r '.'

0 commit comments

Comments
 (0)