Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: aurora vc rbac #120

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-lies-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aurora-is-near/backstage-plugin-blockchainradar-backend': patch
---

fix: aurora vc rbac
27 changes: 17 additions & 10 deletions plugins/blockchainradar-backend/src/lib/OpenZeppelinClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { GET_ACCOUNT_ROLES, GET_CONTRACT_ACCESSCONTROL } from '../queries';
import { getRootLogger } from '@backstage/backend-common';
import { Config } from '@backstage/config';

const GOERLI_ENDPOINT =
'https://api.thegraph.com/subgraphs/name/aurora-is-near/ethereum-goerli-oz';

export class OpenZeppelinClient {
private logger;
private client;
private endpoint: string;

constructor(
config: Config,
Expand All @@ -18,13 +16,18 @@ export class OpenZeppelinClient {
logger = getRootLogger(),
) {
this.logger = logger.child({ class: this.constructor.name, network });
this.endpoint = this.getEndpoint(config, network, networkType);
this.client = new ApolloClient({
uri: this.getEndpoint(config, network, networkType),
uri: this.endpoint,
cache: new InMemoryCache(),
});
}

public async getContractAccessControl(address: string) {
if (!this.endpoint) {
this.logger.warn('no configured RBAC endpoint');
return undefined;
}
this.logger.debug('Performing GetContractAccessControl query');
const { data } = await this.client.query<ContractAccessControlResponse>({
query: GET_CONTRACT_ACCESSCONTROL,
Expand All @@ -45,6 +48,10 @@ export class OpenZeppelinClient {
}

public async getAccountRoles(address: string) {
if (!this.endpoint) {
this.logger.warn('no configured RBAC endpoint');
return undefined;
}
this.logger.debug('Performing GetAccountAccessControl query');
const { data } = await this.client.query<AccountRolesResponse>({
query: GET_ACCOUNT_ROLES,
Expand All @@ -63,14 +70,14 @@ export class OpenZeppelinClient {
}

getEndpoint(config: Config, network: string, networkType: string) {
const configuredEndpoint = config.getString(
`rbac.${network}-${networkType}`,
);
const networkName = `${network}-${networkType}`;
switch (network) {
case 'ethereum':
return networkType === 'goerli' ? GOERLI_ENDPOINT : configuredEndpoint;
case 'aurora':
return configuredEndpoint;
case 'ethereum': {
return networkType === 'mainnet'
? config.getString(`rbac.${networkName}`)
: '';
}
default:
return '';
}
Expand Down
Loading