Skip to content

Instantly share code, notes, and snippets.

@syed
Created October 7, 2024 13:16
Show Gist options
  • Save syed/487bed4249ece44f941d6b08685bfc7c to your computer and use it in GitHub Desktop.
Save syed/487bed4249ece44f941d6b08685bfc7c to your computer and use it in GitHub Desktop.
import argparse
import requests
import logging
#logging.basicConfig(level=logging.DEBUG)
# Instantiate the parser
parser = argparse.ArgumentParser(description='Testing robot federation')
parser.add_argument('action', type=str,
help='action: get create delete ')
parser.add_argument('--orgname', type=str,
help='org name')
parser.add_argument('--robotname', type=str,
help='robot name')
parser.add_argument('--api_token', type=str,
help='token', default='<quay-api-token>')
parser.add_argument('--host', type=str,
help='org name', default='https://quay.io')
parser.add_argument('--issuer', type=str,
help='issuer URL')
parser.add_argument('--subject', type=str,
help='subject name to map')
args = parser.parse_args()
BASE_URL = '/api/v1/organization/%s/robots/%s/federation'
URL = args.host + BASE_URL % (args.orgname, args.robotname)
def get_robot_fed_config():
response = requests.get(URL, headers={'Authorization': f'Bearer {args.api_token}'})
print(response.text)
def create_robot_fed_config(issuer, subject):
data = [{ "issuer" : issuer, "subject": subject }]
response = requests.post(URL, headers={'Authorization': f'Bearer {args.api_token}'}, json=data)
print(response)
print(response.text)
def delete_robot_fed_config():
response = requests.delete(URL, headers={'Authorization': f'Bearer {args.api_token}'})
print(response.text)
def main():
if args.action == 'get':
get_robot_fed_config()
if args.action == 'create':
create_robot_fed_config(args.issuer, args.subject)
if args.action == 'delete':
delete_robot_fed_config()
if __name__ == "__main__":
main()
import requests
import os
TOKEN=os.environ.get('TOKEN')
robot_user = "fed-test+robot1"
def get_quay_robot_token(fed_token):
URL = "http://passwordless-auth.quaydev.org/oauth2/federation/robot/token"
response = requests.get(URL, auth=(robot_user, fed_token))
print(response)
print(response.text)
if __name__ == "__main__":
get_quay_robot_token(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment