feat(badges): Remove hash implementation and replace it with uuid one.
Signed-off-by: Rbillon59 <r.billon@celonis.com>
This commit is contained in:
@@ -47,17 +47,16 @@ export class BadgesClient implements BadgesApi {
|
||||
// Check if obfuscation is enabled in the configuration
|
||||
const obfuscate = this.configApi.getOptionalBoolean('app.badges.obfuscate');
|
||||
|
||||
// If obfuscation is enabled, get the hash of the entity and use that to get the badge specs
|
||||
if (obfuscate) {
|
||||
const entityHashUrl = await this.getEntityHashUrl(entity);
|
||||
const entityHash = await this.getEntityHash(entityHashUrl).then(data => {
|
||||
return data.hash;
|
||||
const entityUuidUrl = await this.getEntityUuidUrl(entity);
|
||||
const entityUuid = await this.getEntityUuid(entityUuidUrl).then(data => {
|
||||
return data.uuid;
|
||||
});
|
||||
const entityHashedBadgeSpecsUrl = await this.getEntityHashedBadgeSpecsUrl(
|
||||
entityHash,
|
||||
const entityUuidBadgeSpecsUrl = await this.getEntityUuidBadgeSpecsUrl(
|
||||
entityUuid,
|
||||
);
|
||||
|
||||
const response = await this.fetchApi.fetch(entityHashedBadgeSpecsUrl);
|
||||
const response = await this.fetchApi.fetch(entityUuidBadgeSpecsUrl);
|
||||
if (!response.ok) {
|
||||
throw await ResponseError.fromResponse(response);
|
||||
}
|
||||
@@ -75,8 +74,7 @@ export class BadgesClient implements BadgesApi {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
// This function is used to generate the URL to get the badge specs for an entity when obfuscation is enabled. Using the hash
|
||||
private async getEntityHashUrl(entity: Entity): Promise<string> {
|
||||
private async getEntityUuidUrl(entity: Entity): Promise<string> {
|
||||
const routeParams = this.getEntityRouteParams(entity);
|
||||
const path = generatePath(`:namespace/:kind/:name`, routeParams);
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl('badges');
|
||||
@@ -85,25 +83,22 @@ export class BadgesClient implements BadgesApi {
|
||||
return obfuscatedEntityUrl;
|
||||
}
|
||||
|
||||
// This function is used to get the hash of an entity when obfuscation is enabled. It's calling the badges backend to get the hash
|
||||
private async getEntityHash(entityHashUrl: string): Promise<any> {
|
||||
const responseEntityHash = await this.fetchApi.fetch(entityHashUrl);
|
||||
private async getEntityUuid(entityUuidUrl: string): Promise<any> {
|
||||
const responseEntityUuid = await this.fetchApi.fetch(entityUuidUrl);
|
||||
|
||||
if (!responseEntityHash.ok) {
|
||||
throw await ResponseError.fromResponse(responseEntityHash);
|
||||
if (!responseEntityUuid.ok) {
|
||||
throw await ResponseError.fromResponse(responseEntityUuid);
|
||||
}
|
||||
return await responseEntityHash.json();
|
||||
return await responseEntityUuid.json();
|
||||
}
|
||||
|
||||
// This function is used to generate the URLs to use in the frontend when obfuscation is enabled. It's using the hash of the entity to get the badge specs
|
||||
private async getEntityHashedBadgeSpecsUrl(entityHash: {
|
||||
hash: string;
|
||||
private async getEntityUuidBadgeSpecsUrl(entityUuid: {
|
||||
uuid: string;
|
||||
}): Promise<string> {
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl('badges');
|
||||
return `${baseUrl}/entity/${entityHash}/badge-specs`;
|
||||
return `${baseUrl}/entity/${entityUuid}/badge-specs`;
|
||||
}
|
||||
|
||||
// This function is used to generate the URLs to use in the frontend when obfuscation is disabled. It's using the entity name to get the badge specs
|
||||
private async getEntityBadgeSpecsUrl(entity: Entity): Promise<string> {
|
||||
const routeParams = this.getEntityRouteParams(entity);
|
||||
const path = generatePath(`:namespace/:kind/:name`, routeParams);
|
||||
|
||||
Reference in New Issue
Block a user