From b33cb108ead541eb22143ad2edeea274b3de04d1 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Tue, 13 Oct 2015 11:49:15 +0200 Subject: [PATCH] Set x-roles when noauth is used This change sets the x-roles headers when no auth is used. This allow to use the Gnocchi polices rules without auth plugins. By default, the roles is 'admin' Change-Id: I647473dca5474308580eac240b87d1920182f99c --- gnocchiclient/noauth.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gnocchiclient/noauth.py b/gnocchiclient/noauth.py index bf816c9..bbe4174 100644 --- a/gnocchiclient/noauth.py +++ b/gnocchiclient/noauth.py @@ -24,17 +24,19 @@ class GnocchiNoAuthPlugin(plugin.BaseAuthPlugin): doing authentication, it just fill the 'x-user-id' and 'x-project-id' headers with the user provided one. """ - def __init__(self, user_id, project_id, endpoint): + def __init__(self, user_id, project_id, roles, endpoint): self._user_id = user_id self._project_id = project_id self._endpoint = endpoint + self._roles = roles def get_token(self, session, **kwargs): return '' def get_headers(self, session, **kwargs): return {'x-user-id': self._user_id, - 'x-project-id': self._project_id} + 'x-project-id': self._project_id, + 'x-roles': self._roles} def get_user_id(self, session, **kwargs): return self._user_id @@ -69,6 +71,7 @@ class GnocchiNoAuthLoader(loading.BaseLoader): options.extend([ GnocchiOpt('user-id', help='User ID', required=True), GnocchiOpt('project-id', help='Project ID', required=True), + GnocchiOpt('roles', help='Roles', default="admin"), GnocchiOpt('gnocchi-endpoint', help='Gnocchi endpoint', dest="endpoint", required=True), ])