#382 ODCS client: accept OpenIDC token stored in file.
Merged 3 years ago by lsedlar. Opened 3 years ago by jkaluza.
jkaluza/odcs client  into  master

file modified
+33 -23
@@ -1,6 +1,7 @@ 

  #!/usr/bin/env python

  from __future__ import print_function

  

+ import os

  import argparse

  import sys

  
@@ -61,6 +62,8 @@ 

  parser.add_argument(

      '--server', default=None, help="Use custom ODCS server.")

  parser.add_argument(

+     '--token', default=None, help="OpenIDC token to use or path to token file")

+ parser.add_argument(

      '--no-wait', action='store_true',

      help='When used, odcs client will not wait for the action to finish.')

  parser.add_argument(
@@ -258,30 +261,37 @@ 

      odcs_url = args.server

  

  if args.infra == 'fedora':

-     id_provider = id_provider_config[args.env]

- 

-     # Get the auth token using the OpenID client.

-     oidc = openidc_client.OpenIDCClient(

-         'odcs',

-         id_provider,

-         {'Token': 'Token', 'Authorization': 'Authorization'},

-         'odcs-authorizer',

-         'notsecret',

-     )

+     if args.token:

+         if os.path.exists(args.token):

+             with open(args.token, "r") as token_file:

+                 token = token_file.readline().strip()

+         else:

+             token = args.token

+     else:

+         id_provider = id_provider_config[args.env]

+ 

+         # Get the auth token using the OpenID client.

+         oidc = openidc_client.OpenIDCClient(

+             'odcs',

+             id_provider,

+             {'Token': 'Token', 'Authorization': 'Authorization'},

+             'odcs-authorizer',

+             'notsecret',

+         )

  

-     scopes = [

-         'openid',

-         'https://id.fedoraproject.org/scope/groups',

-         'https://pagure.io/odcs/new-compose',

-         'https://pagure.io/odcs/renew-compose',

-         'https://pagure.io/odcs/delete-compose',

-     ]

-     try:

-         token = oidc.get_token(scopes, new_token=True)

-         token = oidc.report_token_issue()

-     except requests.exceptions.HTTPError as e:

-         print(e.response.text)

-         raise

+         scopes = [

+             'openid',

+             'https://id.fedoraproject.org/scope/groups',

+             'https://pagure.io/odcs/new-compose',

+             'https://pagure.io/odcs/renew-compose',

+             'https://pagure.io/odcs/delete-compose',

+         ]

+         try:

+             token = oidc.get_token(scopes, new_token=True)

+             token = oidc.report_token_issue()

+         except requests.exceptions.HTTPError as e:

+             print(e.response.text)

+             raise

  

      client = odcs.client.odcs.ODCS(

          odcs_url,

This is needed in Fedora infrastructure to run nightly ODCS composes.

Looks good to me.

Passing a path to a file with token is nice. Using the token directly as argument is not great as it will make it visible to all users on the system.

Pull-Request has been merged by lsedlar

3 years ago

Makes sense, I've removed the way to pass token directly as string.