use plain-text file for launchpad credentials

Authenticating to use launchpad now defaults to an encrypted keyring,
which requires the user to enter a keyring password
interactively. Enable using a plain-text file explicitly or via an
environment variable to bypass this to improve automation.

Change-Id: Ifed22f7c178b1e62e7b5e95d0f8810633ba46fb1
This commit is contained in:
Doug Hellmann 2015-12-02 16:39:51 +00:00
parent 1395314d50
commit cb72d56a7f
4 changed files with 72 additions and 12 deletions

View File

@ -20,18 +20,18 @@
from __future__ import print_function
import argparse
import launchpadlib.launchpad
import lazr.restfulclient.errors
from releasetools import launchpadutils
# Parameters
parser = argparse.ArgumentParser(description="Change Launchpad bugs in bulk")
parser.add_argument('projectname', help='The project to act on')
launchpadutils.add_cli_arguments(parser)
bugsfrom = parser.add_mutually_exclusive_group()
bugsfrom.add_argument('--status', default='Fix Committed',
help='All bugs with that status')
bugsfrom.add_argument('--milestone', help='All open bugs from this milestone')
parser.add_argument("--test", action='store_const', const='staging',
default='production', help='Use LP staging server to test')
parser.add_argument('--settarget',
help='ACTION: set the milestone to specified target')
parser.add_argument('--fixrelease', action='store_true',
@ -42,7 +42,7 @@ args = parser.parse_args()
# Connect to Launchpad
print("Connecting to Launchpad...")
launchpad = launchpadlib.launchpad.Launchpad.login_with('openstack-releasing', args.test)
launchpad = launchpadutils.login(args)
# Retrieve bugs
print("Retrieving project...")

View File

@ -20,9 +20,10 @@
from __future__ import print_function
import argparse
import launchpadlib.launchpad
import lazr.restfulclient.errors
from releasetools import launchpadutils
def main():
# Parameters
@ -31,15 +32,14 @@ def main():
default='Comment added by add_comment')
parser.add_argument('--content', help='The comment content',
default='Comment added by add_comment')
parser.add_argument("--test", action='store_const', const='staging',
default='production', help='Use LP staging server to test')
parser.add_argument('bugs', type=int, nargs='+', help='Bugs to add comment to')
launchpadutils.add_cli_arguments(parser)
parser.add_argument('bugs', type=int, nargs='+',
help='Bugs to add comment to')
args = parser.parse_args()
# Connect to Launchpad
print("Connecting to Launchpad...")
launchpad = launchpadlib.launchpad.Launchpad.login_with(
'openstack-releasing', args.test)
launchpad = launchpadutils.login(args)
# Add comment
for bugid in args.bugs:

View File

@ -19,9 +19,10 @@
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import sys
import launchpadlib.launchpad
from releasetools import launchpadutils
def abort(code, errmsg):
@ -30,9 +31,13 @@ def abort(code, errmsg):
def main():
parser = argparse.ArgumentParser(description="login to launchpad")
launchpadutils.add_cli_arguments(parser)
args = parser.parse_args()
# Connect to LP
print("connecting to launchpad")
try:
launchpadlib.launchpad.Launchpad.login_with('openstack-releasing', 'production')
launchpadutils.login(args)
except Exception as error:
abort(2, 'Could not connect to Launchpad: ' + str(error))

View File

@ -0,0 +1,55 @@
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os.path
import launchpadlib.launchpad
def add_cli_arguments(parser):
"""Add command line arguments for launchpad to the argument parser
Given an argparse.ArgumentParser instance, add options
to let the user control how they interact with launchpad.
"""
lp_grp = parser.add_argument_group('launchpad')
lp_grp.add_argument(
"--test",
action='store_const',
dest='lp_service_root',
const='staging',
default='production',
help='Use LP staging server to test',
)
lp_grp.add_argument(
'--credentials-file', '-c',
dest='lp_creds_file',
default=os.environ.get('LP_CREDS_FILE'),
help=('plain-text credentials file, '
'defaults to value of $LP_CREDS_FILE'),
)
def login(parsed_args):
"""Return a live launchpad connection
Given the results of parsing command line arguments,
open a connection to launchpad using the values
specified by the user and return the handle.
"""
return launchpadlib.launchpad.Launchpad.login_with(
application_name='openstack-releasing',
service_root=parsed_args.lp_service_root,
credentials_file=parsed_args.lp_creds_file,
)