devenv: Add docker load test which authenticates with API key (#28905)

* Add loadtest which authenticates with API key
- Edit load tests to assign the orgId in the default function, as the setup function is only called once for all VUs and therefore the change is not persisted to each VU.
- Remove side effect from orgId setup function and explicitly set orgId in setup client

* sort semicolons, whitespace
This commit is contained in:
Dafydd
2020-11-24 09:34:47 +02:00
committed by GitHub
parent 763e958d9d
commit d29f73b197
8 changed files with 156 additions and 22 deletions
+27
View File
@@ -17,6 +17,10 @@ export const DatasourcesEndpoint = class DatasourcesEndpoint {
this.httpClient = httpClient;
}
getAll() {
return this.httpClient.get('/datasources');
}
getById(id) {
return this.httpClient.get(`/datasources/${id}`);
}
@@ -177,6 +181,25 @@ export class BasicAuthClient extends BaseClient {
}
}
export class BearerAuthClient extends BaseClient {
constructor(url, subUrl, token) {
super(url, subUrl);
this.token = token;
}
withUrl(subUrl) {
let c = new BearerAuthClient(this.url, subUrl, this.token);
c.onBeforeRequest = this.onBeforeRequest;
return c;
}
beforeRequest(params) {
params = params || {};
params.headers = params.headers || {};
params.headers['Authorization'] = `Bearer ${this.token}`;
}
}
export const createClient = url => {
return new GrafanaClient(new BaseClient(url, ''));
};
@@ -184,3 +207,7 @@ export const createClient = url => {
export const createBasicAuthClient = (url, username, password) => {
return new GrafanaClient(new BasicAuthClient(url, '', username, password));
};
export const createBearerAuthClient = (url, token) => {
return new GrafanaClient(new BearerAuthClient(url, '', token));
}