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

feat: authenticated Github registry #5223

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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/calm-hounds-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': patch
---

feat: support github auth token for authenticated registries
2 changes: 2 additions & 0 deletions typescript/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { hookCommand } from './src/commands/hook.js';
import { ismCommand } from './src/commands/ism.js';
import {
disableProxyCommandOption,
githubAuthTokenOption,
keyCommandOption,
logFormatCommandOption,
logLevelCommandOption,
Expand Down Expand Up @@ -44,6 +45,7 @@ try {
.option('log', logFormatCommandOption)
.option('verbosity', logLevelCommandOption)
.option('registry', registryUriCommandOption)
.option('authToken', githubAuthTokenOption)
.option('overrides', overrideRegistryUriCommandOption)
.option('key', keyCommandOption)
.option('disableProxy', disableProxyCommandOption)
Expand Down
7 changes: 7 additions & 0 deletions typescript/cli/src/commands/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export const registryUriCommandOption: Options = {
default: DEFAULT_GITHUB_REGISTRY,
};

export const githubAuthTokenOption: Options = {
type: 'string',
description: 'Github auth token for accessing registry repository',
default: ENV.GH_AUTH_TOKEN,
defaultDescription: 'process.env.GH_AUTH_TOKEN',
};

export const overrideRegistryUriCommandOption: Options = {
type: 'string',
description: 'Path to a local registry to override the default registry',
Expand Down
19 changes: 17 additions & 2 deletions typescript/cli/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function contextMiddleware(argv: Record<string, any>) {
disableProxy: argv.disableProxy,
skipConfirmation: argv.yes,
strategyPath: argv.strategy,
authToken: argv.authToken,
};
if (!isDryRun && settings.fromAddress)
throw new Error(
Expand Down Expand Up @@ -106,8 +107,14 @@ export async function getContext({
skipConfirmation,
disableProxy = false,
strategyPath,
authToken,
}: ContextSettings): Promise<CommandContext> {
const registry = getRegistry(registryUri, registryOverrideUri, !disableProxy);
const registry = getRegistry(
registryUri,
registryOverrideUri,
!disableProxy,
authToken,
);

//Just for backward compatibility
let signerAddress: string | undefined = undefined;
Expand Down Expand Up @@ -143,10 +150,16 @@ export async function getDryRunContext(
fromAddress,
skipConfirmation,
disableProxy = false,
authToken,
}: ContextSettings,
chain?: ChainName,
): Promise<CommandContext> {
const registry = getRegistry(registryUri, registryOverrideUri, !disableProxy);
const registry = getRegistry(
registryUri,
registryOverrideUri,
!disableProxy,
authToken,
);
const chainMetadata = await registry.getMetadata();

if (!chain) {
Expand Down Expand Up @@ -192,6 +205,7 @@ function getRegistry(
primaryRegistryUri: string,
overrideRegistryUri: string,
enableProxy: boolean,
authToken?: string,
): IRegistry {
const logger = rootLogger.child({ module: 'MergedRegistry' });
const registries = [primaryRegistryUri, overrideRegistryUri]
Expand All @@ -203,6 +217,7 @@ function getRegistry(
return new GithubRegistry({
uri,
logger: childLogger,
authToken,
proxyUrl:
enableProxy && isCanonicalRepoUrl(uri)
? PROXY_DEPLOYED_URL
Expand Down
1 change: 1 addition & 0 deletions typescript/cli/src/context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ContextSettings {
disableProxy?: boolean;
skipConfirmation?: boolean;
strategyPath?: string;
authToken?: string;
}

export interface CommandContext {
Expand Down
1 change: 1 addition & 0 deletions typescript/cli/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const envScheme = z.object({
AWS_ACCESS_KEY_ID: z.string().optional(),
AWS_SECRET_ACCESS_KEY: z.string().optional(),
AWS_REGION: z.string().optional(),
GH_AUTH_TOKEN: z.string().optional(),
});

const parsedEnv = envScheme.safeParse(process.env);
Expand Down
Loading