Skip to content

Commit 399cc84

Browse files
authored
fix: add oso-api-key argument (#5585)
1 parent ea9d3cd commit 399cc84

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

lib/oss-artifact-validators/src/onchain/contracts-v0.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { gql, request } from "graphql-request";
1+
import { gql, GraphQLClient } from "graphql-request";
22
import { createPublicClient, http, PublicClient } from "viem";
33
import { EVMNetworkValidator } from "./evm.js";
44

55
const ANY_EVM = "ANY_EVM";
6-
const DEFAULT_API_URL = "https://www.opensource.observer/api/v1/graphql";
6+
const DEFAULT_API_URL = "https://www.oso.xyz/api/v1/graphql";
77

88
export interface ContractsV0ValidatorOptions {
99
apiUrl?: string;
1010
contractNamespace?: string;
1111
rpcUrl: string;
12+
apiKey?: string;
1213
}
1314

1415
interface ContractsV0Response {
@@ -24,16 +25,22 @@ interface ContractsV0Response {
2425
}
2526

2627
export class ContractsV0Validator implements EVMNetworkValidator {
27-
private readonly apiUrl: string;
28+
private readonly graphqlClient: GraphQLClient;
2829
private readonly contractNamespace: string;
2930
private readonly client: PublicClient;
3031

3132
constructor(options: ContractsV0ValidatorOptions) {
32-
this.apiUrl = options.apiUrl ?? DEFAULT_API_URL;
33+
const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
3334
this.contractNamespace = options.contractNamespace ?? ANY_EVM;
3435
this.client = createPublicClient({
3536
transport: http(options.rpcUrl),
3637
});
38+
39+
const headers: Record<string, string> = {};
40+
if (options.apiKey) {
41+
headers.Authorization = `Bearer ${options.apiKey}`;
42+
}
43+
this.graphqlClient = new GraphQLClient(apiUrl, { headers });
3744
}
3845

3946
private normalizeAddress(address: string): `0x${string}` {
@@ -106,8 +113,7 @@ export class ContractsV0Validator implements EVMNetworkValidator {
106113
variables: Record<string, string>,
107114
): Promise<boolean> {
108115
try {
109-
const response = await request<ContractsV0Response>(
110-
this.apiUrl,
116+
const response = await this.graphqlClient.request<ContractsV0Response>(
111117
query,
112118
variables,
113119
);
@@ -129,28 +135,37 @@ export class ContractsV0Validator implements EVMNetworkValidator {
129135
export const createContractsV0Validator = (
130136
rpcUrl: string,
131137
network?: string,
138+
apiKey?: string,
132139
): ContractsV0Validator => {
133140
const contractNamespace = network ?? ANY_EVM;
134141

135-
return new ContractsV0Validator({ contractNamespace, rpcUrl });
142+
return new ContractsV0Validator({ contractNamespace, rpcUrl, apiKey });
136143
};
137144

138145
export const EthereumContractsV0Validator = (
139146
rpcUrl: string,
140-
): ContractsV0Validator => createContractsV0Validator(rpcUrl, "ETHEREUM");
147+
apiKey?: string,
148+
): ContractsV0Validator =>
149+
createContractsV0Validator(rpcUrl, "ETHEREUM", apiKey);
141150

142151
export const ArbitrumContractsV0Validator = (
143152
rpcUrl: string,
144-
): ContractsV0Validator => createContractsV0Validator(rpcUrl, "ARBITRUM");
153+
apiKey?: string,
154+
): ContractsV0Validator =>
155+
createContractsV0Validator(rpcUrl, "ARBITRUM", apiKey);
145156

146157
export const BaseContractsV0Validator = (
147158
rpcUrl: string,
148-
): ContractsV0Validator => createContractsV0Validator(rpcUrl, "BASE");
159+
apiKey?: string,
160+
): ContractsV0Validator => createContractsV0Validator(rpcUrl, "BASE", apiKey);
149161

150162
export const OptimismContractsV0Validator = (
151163
rpcUrl: string,
152-
): ContractsV0Validator => createContractsV0Validator(rpcUrl, "OPTIMISM");
164+
apiKey?: string,
165+
): ContractsV0Validator =>
166+
createContractsV0Validator(rpcUrl, "OPTIMISM", apiKey);
153167

154168
export const AnyEVMContractsV0Validator = (
155169
rpcUrl: string,
156-
): ContractsV0Validator => createContractsV0Validator(rpcUrl, ANY_EVM);
170+
apiKey?: string,
171+
): ContractsV0Validator => createContractsV0Validator(rpcUrl, ANY_EVM, apiKey);

ops/external-prs/.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ PR_TOOLS_REPO=
1212
PR_TOOLS_MAINNET_RPC_URL=
1313
PR_TOOLS_ARBITRUM_RPC_URL=
1414
PR_TOOLS_BASE_RPC_URL=
15-
PR_TOOLS_OPTIMISM_RPC_URL=
15+
PR_TOOLS_OPTIMISM_RPC_URL=
16+
# API key for OSO
17+
PR_TOOLS_OSO_API_KEY=

ops/external-prs/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ Then `git clone` to 2 different paths on your filesystem,
5050
the oss-directory main branch
5151
and the PR branch to compare.
5252

53+
> [!TIP]
54+
> In order to get an OSO API key, visit [`oso.xyz`](https://www.oso.xyz)
55+
5356
You can run the app via:
5457

5558
```bash
5659
# Handle PR validations
57-
pnpm external-prs ossd validate-pr {pr_number} {commit_sha} {main_path} {pr_path}
60+
pnpm external-prs ossd validate-pr {pr_number} {commit_sha} {main_path} {pr_path} --oso-api-key {oso_api_key}
5861
```
5962

6063
If you've configured your GitHub secrets correctly,

ops/external-prs/src/ossd/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export function ossdSubcommands(yargs: Argv) {
169169
type: "string",
170170
description: "Optimism RPC URL",
171171
demandOption: true,
172+
})
173+
.option("oso-api-key", {
174+
type: "string",
175+
description: "OSO API Key",
176+
demandOption: true,
172177
});
173178
},
174179
(args) => handleError(validatePR(args)),
@@ -205,6 +210,7 @@ interface RpcUrlArgs {
205210
arbitrumRpcUrl: string;
206211
baseRpcUrl: string;
207212
optimismRpcUrl: string;
213+
osoApiKey: string;
208214
}
209215

210216
type ValidatePRArgs = OSSDirectoryPullRequestArgs & RpcUrlArgs;
@@ -325,18 +331,23 @@ class OSSDirectoryPullRequest {
325331
this.defillamaValidator = new DefiLlamaValidator();
326332
this.blockchainValidators["any_evm"] = AnyEVMContractsV0Validator(
327333
urls.mainnetRpcUrl,
334+
urls.osoApiKey,
328335
);
329336
this.blockchainValidators["mainnet"] = EthereumContractsV0Validator(
330337
urls.mainnetRpcUrl,
338+
urls.osoApiKey,
331339
);
332340
this.blockchainValidators["arbitrum_one"] = ArbitrumContractsV0Validator(
333341
urls.arbitrumRpcUrl,
342+
urls.osoApiKey,
334343
);
335344
this.blockchainValidators["base"] = BaseContractsV0Validator(
336345
urls.baseRpcUrl,
346+
urls.osoApiKey,
337347
);
338348
this.blockchainValidators["optimism"] = OptimismContractsV0Validator(
339349
urls.optimismRpcUrl,
350+
urls.osoApiKey,
340351
);
341352
}
342353

0 commit comments

Comments
 (0)