Allow to disable the authentification layer

This commit is contained in:
Mehdi Abaakouk
2015-08-31 11:13:55 +02:00
parent a9ebfd6188
commit 84beb97c69
3 changed files with 51 additions and 6 deletions

View File

@@ -43,6 +43,13 @@ set these environment variables::
export GNOCCHI_ENDPOINT=http://gnocchi.example.org:8041
export OS_AUTH_TOKEN=3bcc3d3a03f44e3d8377f9247b0ad155
Also if the server doesn't support authentification need to provide
:option:`--no-auth` and :option:`--gnocchi-endpoint`. You can alternatively set these
environment variables::
export GNOCCHI_ENDPOINT=http://gnocchi.example.org:8041
export GNOCCHI_NO_AUTH=True
From there, all shell commands take the form::
gnocchi <command> [arguments...]

View File

@@ -56,7 +56,6 @@ class GnocchiShell(app.App):
)
self.api_version = api_version
self.auth_plugin = None
self.client = None
def build_option_parser(self, description, version):
@@ -116,6 +115,12 @@ class GnocchiShell(app.App):
help='The Gnocchi REST endpoint'
' (Env: GNOCCHI_ENDPOINT)')
parser.add_argument(
'--no-auth', action='store_true',
default=os.environ.get('GNOCCHI_NO_AUTH'),
help='Don\'t use authentification'
' (Env: GNOCCHI_NO_AUTH)')
parser.add_argument('--timeout',
default=600,
type=_positive_non_zero_int,
@@ -128,12 +133,13 @@ class GnocchiShell(app.App):
def initialize_app(self, argv):
super(GnocchiShell, self).initialize_app(argv)
self.auth_plugin = keystoneclient_cli.load_from_argparse_arguments(
self.options)
# TODO(sileht): allow to pass None as auth_plugin in case of
# gnocchi use noauth
if self.options.no_auth:
auth_plugin = None
else:
auth_plugin = keystoneclient_cli.load_from_argparse_arguments(
self.options)
self.client = client.Client(self.api_version,
auth=self.auth_plugin,
auth=auth_plugin,
endpoint=self.options.endpoint,
region_name=self.options.region_name,
interface=self.options.interface,

View File

@@ -0,0 +1,32 @@
# 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 re
from gnocchiclient.tests.functional import base
class ResourceClientTest(base.ClientTestBase):
def test_no_auth(self):
result = self.gnocchi('resource', params="list", flags="--debug",
merge_stderr=True)
endpoint = re.findall("(http://[^/]*)/v1/resource/generic",
result, re.M)[0]
result = self.gnocchi('resource',
params="list",
flags=("--no-auth "
"--endpoint %s") % endpoint,
fail_ok=True, merge_stderr=True)
self.assertFirstLineStartsWith(result.split('\n'),
"Unauthorized (HTTP 401)")