Always-Try(정보보안 및 일상)

[jquery] ghcr packages API 쿼리 with curl jq 본문

Unclassified

[jquery] ghcr packages API 쿼리 with curl jq

Always-Try 2023. 3. 2. 23:23
https://docs.github.com/en/rest/packages?apiVersion=2022-11-28
 

1.  전체 패키지 name 출력 후 1개의 배열로 묶어줌

curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer YOUR_PAT_TOKEN_VALUE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/YOUR_ORG_NAME/packages\?package_type\=container | jq -c '[.[] | .name]'

 

2. 첫번째 패키지 name을 $test_nam 변수에 저장

export test_nam=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer YOUR_PAT_TOKEN_VALUE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/YOUR_ORG_NAME/packages\?package_type\=container | jq -c '.[0] | .name') 

3. 2번 변수 값 앞뒤에 " 따옴표 제거

temp="${test_nam%\"}"
temp="${temp#\"}"

 

4. 특정 패키지의 최신 태그 버전 출력(패키지 이름은 변수 사용) 

curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer YOUR_PAT_TOKEN_VALUE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/YOUR_ORG_NAME/packages/container/$temp/versions | jq '.[0] | .metadata | .container | .tags[0]'


5. 버전 정보 변수 저장

test_ver=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer YOUR_PAT_TOKEN_VALUE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/tf-dive/packages/container/$temp/versions | jq '.[0] | .metadata | .container | .tags[0]')

 

echo $test_ver

tamp="${test_ver%\"}"

tamp="${tamp#\"}"

echo $tamp

 
 
 

6. 첫번째 패키지 repo 출력

curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer YOUR_PAT_TOKEN_VALUE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/YOUR_ORG_NAME/packages\?package_type\=container | jq -c '.[0] | .repository | .name'

 

7. 전체 패키지 repo 배열로 저장

curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer YOUR_PAT_TOKEN_VALUE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/YOUR_ORG_NAME/packages\?package_type\=container | jq -c '[.[] | .repository | .name]'

 

8. 패키지 repo 변수 저장 및 따옴표 제거

test_rep=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer YOUR_PAT_TOKEN_VALUE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/YOUR_ORG_NAME/packages\?package_type\=container | jq -c '.[0] | .repository | .name')

 

tomp="${test_rep%\"}"

tomp="${tomp#\"}"

echo $tomp

 

 

이제 필요한 3개가 변수로 저장되었다. 

  • 이미지명은 $temp
  • 태그버전은 $tamp
  • Rep는 $tomp
 

 

Comments