Set basic access authentication for registries requests (#15292)
* set basic access authentication for requests to the plugin and devfile registries Signed-off-by: Oleksii Orel <oorel@redhat.com>7.20.x
parent
9cb3549e30
commit
2cc7da549e
|
|
@ -46,6 +46,8 @@ export class DevfileRegistry {
|
|||
|
||||
private jwtproxyMemoryLimitNumber: number;
|
||||
|
||||
private headers: { [name: string]: string; };
|
||||
|
||||
/**
|
||||
* Default constructor that is using resource
|
||||
*/
|
||||
|
|
@ -56,10 +58,17 @@ export class DevfileRegistry {
|
|||
this.devfilesMap = new Map<string, che.IWorkspaceDevfile>();
|
||||
this.isKeycloackPresent = cheKeycloak.isPresent();
|
||||
this.jwtproxyMemoryLimitNumber = this.getMemoryLimit(DEFAULT_JWTPROXY_MEMORY_LIMIT);
|
||||
|
||||
this.headers = { 'Authorization': undefined };
|
||||
}
|
||||
|
||||
fetchDevfiles(location: string): ng.IPromise<Array<IDevfileMetaData>> {
|
||||
let promise = this.$http({ 'method': 'GET', 'url': location + '/devfiles/index.json' });
|
||||
let promise = this.$http({
|
||||
'method': 'GET',
|
||||
'url': `${location}/devfiles/index.json`,
|
||||
'headers': this.headers
|
||||
});
|
||||
|
||||
return promise.then((result: any) => {
|
||||
return result.data.map((devfileMetaData: IDevfileMetaData) => {
|
||||
let globalMemoryLimitNumber = this.getMemoryLimit(devfileMetaData.globalMemoryLimit);
|
||||
|
|
@ -74,9 +83,13 @@ export class DevfileRegistry {
|
|||
}
|
||||
|
||||
fetchDevfile(location: string, link: string): ng.IPromise<che.IWorkspaceDevfile> {
|
||||
let promise = this.$http({ 'method': 'GET', 'url': location + link });
|
||||
let promise = this.$http({
|
||||
'method': 'GET',
|
||||
'url': `${location}${link}`,
|
||||
'headers': this.headers
|
||||
});
|
||||
return promise.then((result: any) => {
|
||||
let devfile = this.devfileYamlToJson(result.data)
|
||||
let devfile = this.devfileYamlToJson(result.data);
|
||||
this.devfilesMap.set(location + link, devfile);
|
||||
return devfile;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -59,12 +59,16 @@ export class PluginRegistry {
|
|||
|
||||
private plugins = new Map<string, Array<IPlugin>>();
|
||||
|
||||
private headers: { [name: string]: string; };
|
||||
|
||||
/**
|
||||
* Default constructor that is using resource
|
||||
*/
|
||||
constructor($http: ng.IHttpService, $q: ng.IQService) {
|
||||
this.$http = $http;
|
||||
this.$q = $q;
|
||||
|
||||
this.headers = { 'Authorization': undefined };
|
||||
}
|
||||
|
||||
static get EDITOR_TYPE(): string {
|
||||
|
|
@ -72,7 +76,13 @@ export class PluginRegistry {
|
|||
}
|
||||
|
||||
fetchPlugins(location: string): ng.IPromise<Array<IPlugin>> {
|
||||
return this.$http({'method': 'GET', 'url': location + '/plugins/'}).then((result: ng.IHttpResponse<IPlugin[]>) => {
|
||||
const promise = this.$http({
|
||||
'method': 'GET',
|
||||
'url': `${location}/plugins/`,
|
||||
'headers': this.headers
|
||||
});
|
||||
|
||||
return promise.then((result: ng.IHttpResponse<IPlugin[]>) => {
|
||||
this.plugins.set(location, result.data);
|
||||
return this.$q.when(result.data);
|
||||
}, (error: any) => {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import {HttpInterceptorBase} from './interceptor-base';
|
|||
|
||||
const GITHUB_API = 'api.github.com';
|
||||
|
||||
const AUTHORIZATION = 'Authorization';
|
||||
|
||||
/**
|
||||
* @author Oleksii Kurinnyi
|
||||
*/
|
||||
|
|
@ -49,11 +51,15 @@ export class KeycloakTokenInterceptor extends HttpInterceptorBase {
|
|||
return config;
|
||||
}
|
||||
|
||||
if (config.headers.Authorization) {
|
||||
const headers = config.headers;
|
||||
if (headers && Object.keys(headers).indexOf(AUTHORIZATION) != -1) {
|
||||
if (headers[AUTHORIZATION] === undefined) {
|
||||
delete headers[AUTHORIZATION];
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (this.keycloak && this.keycloak.token) {
|
||||
let deferred = this.$q.defer();
|
||||
this.keycloak.updateToken(5).success(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue