| |
@@ -25,7 +25,7 @@
|
| |
import pkg_resources
|
| |
import six
|
| |
from six.moves import configparser
|
| |
- from six.moves.configparser import NoOptionError, NoSectionError
|
| |
+ from six.moves.configparser import NoOptionError, NoSectionError, ConfigParser
|
| |
from six.moves.urllib_parse import urlparse
|
| |
|
| |
from fedpkg.bugzilla import BugzillaClient
|
| |
@@ -122,6 +122,8 @@
|
| |
self.register_request_branch()
|
| |
self.register_do_fork()
|
| |
self.register_override()
|
| |
+ self.register_set_distgit_token()
|
| |
+ self.register_set_pagure_token()
|
| |
|
| |
# Target registry goes here
|
| |
def register_update(self):
|
| |
@@ -261,16 +263,20 @@
|
| |
pagure_section = '{0}.pagure'.format(self.name)
|
| |
pagure_url = config_get_safely(self.config, pagure_section, 'url')
|
| |
pagure_url_parsed = urlparse(pagure_url).netloc
|
| |
+
|
| |
description = textwrap.dedent('''
|
| |
Request a new dist-git repository
|
| |
|
| |
Before the operation, you need to generate a pagure.io API token at:
|
| |
https://{1}/settings/token/new
|
| |
|
| |
- ACL required:
|
| |
- "Create a new ticket"
|
| |
+ ACL required:
|
| |
+ "Create a new ticket"
|
| |
+
|
| |
+ Update your token with the following command:
|
| |
+ fedpkg set-pagure-token <api_key_here>
|
| |
|
| |
- Save the API token to local user configuration located at:
|
| |
+ Command saves token to fedpkg config file:
|
| |
~/.config/rpkg/{0}.conf
|
| |
|
| |
For example:
|
| |
@@ -450,6 +456,7 @@
|
| |
help_msg = 'Create a new fork of the current repository'
|
| |
distgit_section = '{0}.distgit'.format(self.name)
|
| |
distgit_api_base_url = config_get_safely(self.config, distgit_section, "apibaseurl")
|
| |
+
|
| |
description = textwrap.dedent('''
|
| |
Create a new fork of the current repository
|
| |
|
| |
@@ -459,7 +466,10 @@
|
| |
ACL required:
|
| |
"Fork a project"
|
| |
|
| |
- Save the API token to local user configuration located at:
|
| |
+ Update your token with the following command:
|
| |
+ fedpkg set-distgit-token <api_key_here>
|
| |
+
|
| |
+ Command saves token to fedpkg config file:
|
| |
~/.config/rpkg/{0}.conf
|
| |
|
| |
For example:
|
| |
@@ -508,6 +518,38 @@
|
| |
|
| |
parser.set_defaults(command=self.show_releases_info)
|
| |
|
| |
+ def register_set_distgit_token(self):
|
| |
+ help_msg = \
|
| |
+ 'Updates the fedpkg.distgit API token in ~/.config/rpkg/{0}.conf file.\n\n\
|
| |
+ Tokens are of length 64 and contain only uppercase and numerical values.'\
|
| |
+ .format(self.name)
|
| |
+
|
| |
+ parser = self.subparsers.add_parser(
|
| |
+ 'set-distgit-token',
|
| |
+ help=help_msg,
|
| |
+ description=help_msg)
|
| |
+ parser.add_argument(
|
| |
+ 'token',
|
| |
+ help='The new API token.')
|
| |
+
|
| |
+ parser.set_defaults(command=self.set_distgit_token)
|
| |
+
|
| |
+ def register_set_pagure_token(self):
|
| |
+ help_msg = \
|
| |
+ 'Updates the fedpkg.pagure API token in ~/.config/rpkg/{0}.conf file.\n\n\
|
| |
+ Tokens are of length 64 and contain only uppercase and numerical values.'\
|
| |
+ .format(self.name)
|
| |
+
|
| |
+ parser = self.subparsers.add_parser(
|
| |
+ 'set-pagure-token',
|
| |
+ help=help_msg,
|
| |
+ description=help_msg)
|
| |
+ parser.add_argument(
|
| |
+ 'token',
|
| |
+ help='The new API token.')
|
| |
+
|
| |
+ parser.set_defaults(command=self.set_pagure_token)
|
| |
+
|
| |
def register_override(self):
|
| |
"""Register command line parser for subcommand override
|
| |
|
| |
@@ -1318,6 +1360,73 @@
|
| |
print('Fedora: {0}'.format(_join(releases['fedora'])))
|
| |
print('EPEL: {0}'.format(_join(releases['epel'])))
|
| |
|
| |
+ def _check_token(self, token, token_type):
|
| |
+
|
| |
+ if token is None:
|
| |
+ self.log.error("ERROR: No input.")
|
| |
+ return False
|
| |
+
|
| |
+ match = re.search(r'^\s*[A-Z0-9]{64}\s*$', token)
|
| |
+ if match is None:
|
| |
+ self.log.error("ERROR: Token is not properly formatted.")
|
| |
+ return False
|
| |
+ else:
|
| |
+ return True
|
| |
+
|
| |
+ def _set_token(self, token_type):
|
| |
+
|
| |
+ # Pop token off of the parse stack
|
| |
+ TOKEN = self.args.token
|
| |
+
|
| |
+ # Get the path to the fedpkg config file.
|
| |
+ PATH = os.path.join(os.path.expanduser('~'),
|
| |
+ '.config',
|
| |
+ 'rpkg',
|
| |
+ '{0}.conf'.format(self.name))
|
| |
+
|
| |
+ # load new config parser
|
| |
+ local_config = ConfigParser()
|
| |
+ local_config.read(PATH)
|
| |
+
|
| |
+ # Ensure that user config file exists.
|
| |
+ if not os.path.isfile(PATH):
|
| |
+ self.log.error("ERROR: User config file not found at: {0}\n".format(PATH))
|
| |
+ return
|
| |
+
|
| |
+ # Check that the user passed a valid token
|
| |
+ if self._check_token(TOKEN, token_type):
|
| |
+
|
| |
+ print("updating config")
|
| |
+
|
| |
+ # Update the token in the config object.
|
| |
+ section = "{0}.{1}".format(self.name, token_type)
|
| |
+
|
| |
+ # add the section if it doesn't already exist
|
| |
+ if section not in local_config:
|
| |
+ local_config.add_section(section)
|
| |
+
|
| |
+ # set the distgit / pagure urls as needed (might already be set)
|
| |
+ if(token_type == "pagure"):
|
| |
+ local_config.set(section, "url", "https://pagure.io/")
|
| |
+ else:
|
| |
+ local_config.set(section, "apibaseurl", "https://src.fedoraproject.org")
|
| |
+
|
| |
+ # update the token
|
| |
+ local_config.set(section, "token", TOKEN)
|
| |
+
|
| |
+ # Write the config to the user's config file.
|
| |
+ with open(PATH, "w") as fp:
|
| |
+ try:
|
| |
+ local_config.write(fp)
|
| |
+ except configparser.Error:
|
| |
+ self.log.error("ERROR: Could not write to user config file.")
|
| |
+
|
| |
+ def set_pagure_token(self):
|
| |
+ self._set_token("pagure")
|
| |
+
|
| |
+ def set_distgit_token(self):
|
| |
+ self._set_token("distgit")
|
| |
+
|
| |
def retire(self):
|
| |
"""
|
| |
Runs the rpkg retire command after check. Check includes reading the state
|
| |
Added an interface that allows a user to update relevant expired
API keys via the command line interface.
Files:
cli.py: register_set_pagure_token
cli.py: register_set_distgit_token
cli.py: set_pagure_token
cli.py: set_distgit_token
cli.py: _set_token
cli.py: _check_token
Tests:
test_cli.py: TestSetToken (class)
test_cli.py: get_cli
test_cli.py: test_token_input_mixed_lowercase_numerical
test_cli.py: test_token_input_none
test_cli.py: test_token_input_lowercase
test_cli.py: test_token_input_too_short
test_cli.py: test_token_input_too_long
Fixes #192
Jira: RHELCMP-58
Signed-off-by: James Kunstle jkunstle@redhat.com