Skip to content

Commit

Permalink
Implements noauth mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi Abaakouk committed Jul 12, 2016
1 parent c273d16 commit b1d7511
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 39 deletions.
25 changes: 21 additions & 4 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export default class GnocchiDatasource {
type: string;
supportMetrics: boolean;
default_headers: any;
domain: string;
project: string;
username: string;
password: string;
roles: string;
url: string;
keystone_endpoint: string;

Expand All @@ -28,16 +30,31 @@ export default class GnocchiDatasource {
self.project = instanceSettings.jsonData.project;
self.username = instanceSettings.jsonData.username;
self.password = instanceSettings.jsonData.password;
self.default_headers['X-Auth-Token'] = instanceSettings.jsonData.token;
self.roles = instanceSettings.jsonData.roles;
self.domain = instanceSettings.jsonData.domain;
if (self.domain === undefined || self.domain === "") {
self.domain = 'default';
}
if (self.roles === undefined || self.roles === "") {
self.roles = 'admin';
}
}

// If the URL starts with http, we are in direct mode
if (instanceSettings.url.indexOf('http') === 0){
if (instanceSettings.jsonData.mode === "keystone"){
self.url = null;
self.keystone_endpoint = self.sanitize_url(instanceSettings.url);
} else if (instanceSettings.jsonData.mode === "token"){
self.url = self.sanitize_url(instanceSettings.url);
self.keystone_endpoint = null;
self.default_headers['X-Auth-Token'] = instanceSettings.jsonData.token;
} else {
self.url = self.sanitize_url(instanceSettings.url);
self.keystone_endpoint = null;
self.default_headers['X-Project-Id'] = self.project;
self.default_headers['X-User-Id'] = self.username;
self.default_headers['X-Domain-Id'] = self.domain;
self.default_headers['X-Roles'] = self.roles;
}
}

Expand Down Expand Up @@ -414,13 +431,13 @@ export default class GnocchiDatasource {
"user": {
"name": self.username,
"password": self.password,
"domain": { "id": "default" }
"domain": { "id": self.domain }
}
}
},
"scope": {
"project": {
"domain": { "id": "default" },
"domain": { "id": self.domain },
"name": self.project,
}
}
Expand Down
80 changes: 53 additions & 27 deletions src/partials/config.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,68 @@
<datasource-http-settings current="ctrl.current">
</datasource-http-settings>

<h3>Gnocchi Details</h3>
<div class="gf-info-box" style="margin: 30px 0 0 0">
If you plan to use the proxy mode, use the Gnocchi URL and fill the Token
<div class="gf-info-box" style="margin: 10px 0 30px 0" ng-if="ctrl.current.access == 'direct'">
When "direct" access is used, Gnocchi and Keystone MUST have CORS configured correctly on the server side.<br />
</div>

<h3>Gnocchi Details</h3>
<div class="gf-form-group">
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Token</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.token' placeholder=""></input>
<span class="gf-form-label width-7">Auth Mode</span>
<div class="gf-form-select-wrapper gf-form-select-wrapper--has-help-icon max-width-24">
<select class="gf-form-input" ng-model="ctrl.current.jsonData.mode" ng-options="f for f in ['noauth', 'token', 'keystone']"></select>
<info-popover mode="right-absolute">
noauth = we send domain/project/username in X-<XXX>-Id headers to Gnocchi<br />
token = we send the X-Token-ID header to Gnocchi<br />
keystone = we retreive the token on keystone with domain/project/username/password
</info-popover>
</div>
</div>
</div>
</div>

<div class="gf-info-box" style="margin: 30px 0 0 0">
If you plan to use the direct mode, use the Keystone URL and fill the Project, User and Password<br>
In this mode, Gnocchi and Keystone MUST have CORS configured correctly on the server side.
</div>

<div class="gf-form-group">
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Project</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.project' placeholder=""></input>
</div>
<div style="padding:5px">
<span ng-if="ctrl.current.access == 'direct' && ctrl.current.jsonData.mode == 'keystone'">The Keystone URL is expected in Http settings</span>
<span ng-if="ctrl.current.access == 'proxy' && ctrl.current.jsonData.mode == 'keystone'">This configuration can't works, select another 'Access' or 'Auth Mode'</span>
<span ng-if="ctrl.current.jsonData.mode != 'keystone'">The Gnocchi URL is expected in Http settings</span>
</div>
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">User</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.username' placeholder=""></input>
<div ng-if="(ctrl.current.access == 'direct' && ctrl.current.jsonData.mode != 'token') || ctrl.current.jsonData.mode == 'noauth'">
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Domain</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.domain' placeholder="default"></input>
</div>
</div>
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Project</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.project' placeholder=""></input>
</div>
</div>
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">User</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.username' placeholder=""></input>
</div>
</div>
<div class="gf-form-inline" ng-if="ctrl.current.jsonData.mode == 'keystone'">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Password</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.password' placeholder=""></input>
</div>
</div>
<div class="gf-form-inline" ng-if="ctrl.current.jsonData.mode == 'noauth'">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Roles</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.roles' placeholder="admin"></input>
</div>
</div>

</div>
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Password</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.password' placeholder=""></input>
<div ng-if="ctrl.current.jsonData.mode == 'token'">
<div class="gf-form-inline">
<div class="gf-form max-width-30">
<span class="gf-form-label width-7">Token</span>
<input type="text" class="tight-form-input input-xlarge" ng-model='ctrl.current.jsonData.token' placeholder=""></input>
</div>
</div>
</div>
</div>
14 changes: 6 additions & 8 deletions src/specs/gnocchi-datasource-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('GnocchiDatasource', function() {
$httpBackend = $injector.get('$httpBackend');
backendSrv = new BackendSrvMock($injector.get('$http'));
templateSrv = new TemplateSrvMock();
ds = new Datasource({url: [''], jsonData: {token: 'XXXXXXXXXXXXX'} },
ds = new Datasource({url: [''], jsonData: {token: 'XXXXXXXXXXXXX', 'mode': 'token'} },
$q, backendSrv, templateSrv);
}));

Expand All @@ -34,10 +34,8 @@ describe('GnocchiDatasource', function() {
targets: targets,
interval: '1s'
};
var headers = {"X-Auth-Token": "XXXXXXXXXXXXX", "Accept": "application/json, text/plain, */*"};
//if (data) {
headers["Content-Type"] = "application/json";
//}
var headers = {"X-Auth-Token": "XXXXXXXXXXXXX", "Accept": "application/json, text/plain, */*",
"Content-Type": "application/json"};

it('should return series list', angular.mock.inject(function() {
if (pre_assert) {
Expand Down Expand Up @@ -216,14 +214,14 @@ describe('GnocchiDatasource', function() {
beforeEach(function() {
ds = new Datasource({
'url': 'http://localhost:5000',
'jsonData': {'username': 'user', 'project': 'proj', 'password': 'pass'}
'jsonData': {'mode': 'keystone', 'username': 'user', 'project': 'proj', 'password': 'pass', 'domain': 'foo'}
}, $q, backendSrv, templateSrv);

$httpBackend.expect(
'POST', "http://localhost:5000/v3/auth/tokens",
{"auth": { "identity": { "methods": ["password"],
"password": { "user": { "name": "user", "password": "pass", "domain": { "id": "default"}}}},
"scope": { "project": { "domain": { "id": "default" }, "name": "proj"}}}},
"password": { "user": { "name": "user", "password": "pass", "domain": { "id": "foo"}}}},
"scope": { "project": { "domain": { "id": "foo" }, "name": "proj"}}}},
{'Content-Type': 'application/json', "Accept": "application/json, text/plain, */*"}
).respond({'token': {'catalog': [{'type': 'metric', 'endpoints':
[{'url': 'http://localhost:8041/', 'interface': 'public'}]}]}}, {'X-Subject-Token': 'foobar'});
Expand Down

0 comments on commit b1d7511

Please sign in to comment.