Skip to content

Commit

Permalink
fix(frontend): for over null/undefined
Browse files Browse the repository at this point in the history
there where some null/undefined mapping, when the request is
unauthorized

Related to: redpanda-data/cloudv2#6318

Signed-off-by: Santiago Jimenez Giraldo <santiago@redpanda.com>
  • Loading branch information
sago2k8 committed Jun 7, 2023
1 parent 20c97bd commit 0ba44b2
Showing 1 changed file with 49 additions and 41 deletions.
90 changes: 49 additions & 41 deletions frontend/src/state/backendApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,16 @@ const apiStore = {
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}

let hex = '';
for (let i = 0; i < bytes.length; i++) {
const b = bytes[i].toString(16);
hex += b.length === 1 ? '0' + b : b;

if (i < bytes.length - 1)
hex += ' ';
}

return hex;
},

Expand All @@ -438,19 +438,22 @@ const apiStore = {
refreshTopics(force?: boolean) {
cachedApiRequest<GetTopicsResponse>(`${appConfig.restBasePath}/topics`, force)
.then(v => {
for (const t of v.topics) {
if (!t.allowedActions) continue;

// DEBUG: randomly remove some allowedActions
/*
const numToRemove = Math.round(Math.random() * t.allowedActions.length);
for (let i = 0; i < numToRemove; i++) {
const randomIndex = Math.round(Math.random() * (t.allowedActions.length - 1));
t.allowedActions.splice(randomIndex, 1);
if (v?.topics != null) {
for (const t of v.topics) {
if (!t.allowedActions) continue;

// DEBUG: randomly remove some allowedActions
/*
const numToRemove = Math.round(Math.random() * t.allowedActions.length);
for (let i = 0; i < numToRemove; i++) {
const randomIndex = Math.round(Math.random() * (t.allowedActions.length - 1));
t.allowedActions.splice(randomIndex, 1);
}
*/
}
*/

}
this.topics = v.topics;
this.topics = v?.topics;
}, addError);
},

Expand Down Expand Up @@ -760,24 +763,26 @@ const apiStore = {
refreshCluster(force?: boolean) {
cachedApiRequest<ClusterInfoResponse>(`${appConfig.restBasePath}/cluster`, force)
.then(v => {
transaction(() => {
// add 'type' to each synonym entry
for (const broker of v.clusterInfo.brokers)
if (broker.config && !broker.config.error)
prepareSynonyms(broker.config.configs);

// don't assign if the value didn't change
// we'd re-trigger all observers!
// TODO: it would probably be easier to just annotate 'clusterInfo' with a structural comparer
if (!comparer.structural(this.clusterInfo, v.clusterInfo))
this.clusterInfo = v.clusterInfo;

for (const b of v.clusterInfo.brokers)
if (b.config.error)
this.brokerConfigs.set(b.brokerId, b.config.error);
else
this.brokerConfigs.set(b.brokerId, b.config.configs);
});
if (v?.clusterInfo != null) {
transaction(() => {
// add 'type' to each synonym entry
for (const broker of v.clusterInfo.brokers)
if (broker.config && !broker.config.error)
prepareSynonyms(broker.config.configs);

// don't assign if the value didn't change
// we'd re-trigger all observers!
// TODO: it would probably be easier to just annotate 'clusterInfo' with a structural comparer
if (!comparer.structural(this.clusterInfo, v.clusterInfo))
this.clusterInfo = v.clusterInfo;

for (const b of v.clusterInfo.brokers)
if (b.config.error)
this.brokerConfigs.set(b.brokerId, b.config.error);
else
this.brokerConfigs.set(b.brokerId, b.config.configs);
});
}
}, addError);
},

Expand All @@ -803,14 +808,16 @@ const apiStore = {
refreshConsumerGroups(force?: boolean) {
cachedApiRequest<GetConsumerGroupsResponse>(`${appConfig.restBasePath}/consumer-groups`, force)
.then(v => {
for (const g of v.consumerGroups)
addFrontendFieldsForConsumerGroup(g);

transaction(() => {
this.consumerGroups.clear();
if (v?.consumerGroups != null) {
for (const g of v.consumerGroups)
this.consumerGroups.set(g.groupId, g);
});
addFrontendFieldsForConsumerGroup(g);

transaction(() => {
this.consumerGroups.clear();
for (const g of v.consumerGroups)
this.consumerGroups.set(g.groupId, g);
});
}
}, addError);
},

Expand Down Expand Up @@ -1390,14 +1397,15 @@ const apiStore = {
return parseOrUnwrap<any>(response, null);
},

async updateSecret(clusterName: string, secretId: string, secretValue: string): Promise<void> {
async updateSecret(clusterName: string, secretId: string, secretValue: string): Promise<void> {
const response = await appConfig.fetch(`${appConfig.restBasePath}/kafka-connect/clusters/${encodeURIComponent(clusterName)}/secrets/${encodeURIComponent(secretId)}`, {
method: 'PUT',
headers: [
['Content-Type', 'application/json']
],
body: JSON.stringify({
secretData: secretValue }),
secretData: secretValue
}),
});
return parseOrUnwrap<any>(response, null);
},
Expand Down

0 comments on commit 0ba44b2

Please sign in to comment.