Fix small typos and remove unused code
Change-Id: I4d07b285b781e99d5a233f1525b136e7e857b92f
This commit is contained in:
parent
5cf1030ca8
commit
cb049588f8
@ -1,35 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Base utilities to build API operation managers and objects on top of.
|
||||
|
||||
DEPRECATED post v.0.12.0. Use 'glareclient.openstack.common.apiclient.base'
|
||||
instead of this module."
|
||||
"""
|
||||
|
||||
import warnings
|
||||
|
||||
from glareclient.openstack.common.apiclient import base
|
||||
|
||||
|
||||
warnings.warn("The 'glareclient.common.base' module is deprecated post "
|
||||
"v.0.12.0. Use 'glareclient.openstack.common.apiclient.base' "
|
||||
"instead of this one.", DeprecationWarning)
|
||||
|
||||
|
||||
getid = base.getid
|
||||
Manager = base.ManagerWithFind
|
||||
Resource = base.Resource
|
@ -19,7 +19,7 @@ import six
|
||||
|
||||
|
||||
class _ProgressBarBase(object):
|
||||
"""A progress bar provider for a wrapped obect.
|
||||
"""A progress bar provider for a wrapped object.
|
||||
|
||||
Base abstract class used by specific class wrapper to show
|
||||
a progress bar when the wrapped object are consumed.
|
||||
|
@ -18,9 +18,7 @@ from __future__ import print_function
|
||||
import errno
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import sys
|
||||
|
||||
if os.name == 'nt':
|
||||
@ -34,16 +32,6 @@ from oslo_utils import importutils
|
||||
SENSITIVE_HEADERS = ('X-Auth-Token', )
|
||||
|
||||
|
||||
# Decorator for cli-args
|
||||
def arg(*args, **kwargs):
|
||||
def _decorator(func):
|
||||
# Because of the semantics of decorator composition if we just append
|
||||
# to the options list positional options will appear to be backwards.
|
||||
func.__dict__.setdefault('arguments', []).insert(0, (args, kwargs))
|
||||
return func
|
||||
return _decorator
|
||||
|
||||
|
||||
def env(*vars, **kwargs):
|
||||
"""Search for the first defined of possibly many env vars.
|
||||
|
||||
@ -66,36 +54,10 @@ def import_versioned_module(version, submodule=None):
|
||||
|
||||
def exit(msg='', exit_code=1):
|
||||
if msg:
|
||||
print_err(msg)
|
||||
print(encodeutils.safe_decode(msg), file=sys.stderr)
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def print_err(msg):
|
||||
print(encodeutils.safe_decode(msg), file=sys.stderr)
|
||||
|
||||
|
||||
def strip_version(endpoint):
|
||||
"""Strip version from the last component of endpoint if present."""
|
||||
# NOTE(flaper87): This shouldn't be necessary if
|
||||
# we make endpoint the first argument. However, we
|
||||
# can't do that just yet because we need to keep
|
||||
# backwards compatibility.
|
||||
if not isinstance(endpoint, six.string_types):
|
||||
raise ValueError("Expected endpoint")
|
||||
|
||||
version = None
|
||||
# Get rid of trailing '/' if present
|
||||
endpoint = endpoint.rstrip('/')
|
||||
url_parts = urlparse.urlparse(endpoint)
|
||||
(scheme, netloc, path, __, __, __) = url_parts
|
||||
path = path.lstrip('/')
|
||||
# regex to match 'v1' or 'v2.0' etc
|
||||
if re.match('v\d+\.?\d*', path):
|
||||
version = float(path.lstrip('v'))
|
||||
endpoint = scheme + '://' + netloc
|
||||
return endpoint, version
|
||||
|
||||
|
||||
def integrity_iter(iter, checksum):
|
||||
"""Check blob integrity.
|
||||
|
||||
@ -114,31 +76,6 @@ def integrity_iter(iter, checksum):
|
||||
(md5sum, checksum))
|
||||
|
||||
|
||||
def safe_header(name, value):
|
||||
if value is not None and name in SENSITIVE_HEADERS:
|
||||
h = hashlib.sha1(value)
|
||||
d = h.hexdigest()
|
||||
return name, "{SHA1}%s" % d
|
||||
else:
|
||||
return name, value
|
||||
|
||||
|
||||
def endpoint_version_from_url(endpoint, default_version=None):
|
||||
if endpoint:
|
||||
endpoint, version = strip_version(endpoint)
|
||||
return endpoint, version or default_version
|
||||
else:
|
||||
return None, default_version
|
||||
|
||||
|
||||
def debug_enabled(argv):
|
||||
if bool(env('GLARECLIENT_DEBUG')) is True:
|
||||
return True
|
||||
if '--debug' in argv or '-d' in argv:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class IterableWithLength(object):
|
||||
def __init__(self, iterable, length):
|
||||
self.iterable = iterable
|
||||
|
@ -96,7 +96,7 @@ class ShowArtifact(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -170,12 +170,12 @@ class UpdateArtifact(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<NAME>',
|
||||
help='Name of the artifact',
|
||||
help='Name of the artifact.',
|
||||
),
|
||||
parser.add_argument(
|
||||
'--remove-property',
|
||||
@ -228,7 +228,7 @@ class DeleteArtifact(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -254,7 +254,7 @@ class ActivateArtifact(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -280,7 +280,7 @@ class DeactivateArtifact(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -306,7 +306,7 @@ class ReactivateArtifact(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
return parser
|
||||
|
||||
@ -319,7 +319,7 @@ class ReactivateArtifact(command.ShowOne):
|
||||
|
||||
|
||||
class PublishArtifact(command.ShowOne):
|
||||
"""Publish the artifact"""
|
||||
"""Publish the artifact"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(PublishArtifact, self).get_parser(prog_name)
|
||||
@ -332,7 +332,7 @@ class PublishArtifact(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
return parser
|
||||
|
||||
|
@ -50,11 +50,11 @@ class UploadBlob(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--file',
|
||||
metavar='<TYPE_NAME>',
|
||||
metavar='<FILE_PATH>',
|
||||
help='Local file that contains data to be uploaded.',
|
||||
)
|
||||
parser.add_argument(
|
||||
@ -109,7 +109,7 @@ class DownloadBlob(command.Command):
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<ID>',
|
||||
help='ID of the artifact to update',
|
||||
help='ID of the artifact to update.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--progress',
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
|
||||
import mock
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
import testtools
|
||||
|
||||
@ -64,20 +63,3 @@ class TestUtils(testtools.TestCase):
|
||||
i = utils.IterableWithLength(data, 10)
|
||||
self.assertRaises(IOError, _iterate, i)
|
||||
data.close.assert_called_with()
|
||||
|
||||
def test_safe_header(self):
|
||||
self.assertEqual(('somekey', 'somevalue'),
|
||||
utils.safe_header('somekey', 'somevalue'))
|
||||
self.assertEqual(('somekey', None),
|
||||
utils.safe_header('somekey', None))
|
||||
|
||||
for sensitive_header in utils.SENSITIVE_HEADERS:
|
||||
(name, value) = utils.safe_header(
|
||||
sensitive_header,
|
||||
encodeutils.safe_encode('somestring'))
|
||||
self.assertEqual(sensitive_header, name)
|
||||
self.assertTrue(value.startswith("{SHA1}"))
|
||||
|
||||
(name, value) = utils.safe_header(sensitive_header, None)
|
||||
self.assertEqual(sensitive_header, name)
|
||||
self.assertIsNone(value)
|
||||
|
@ -27,7 +27,7 @@ class Controller(object):
|
||||
self.sort_dir_values = ('asc', 'desc')
|
||||
|
||||
def _check_type_name(self, type_name):
|
||||
"""Check that type name and type versions were specified"""
|
||||
"""Check that type name and type versions were specified."""
|
||||
type_name = type_name or self.type_name
|
||||
if type_name is None:
|
||||
msg = "Type name must be specified"
|
||||
|
Loading…
x
Reference in New Issue
Block a user