Skip to content
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/unlucky-queens-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

`graph auth`: fix bug with setting deploy key
20 changes: 12 additions & 8 deletions packages/cli/src/commands/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { print, prompt } from 'gluegun';
import { Args, Command, Flags, ux } from '@oclif/core';
import { Args, Command, Flags } from '@oclif/core';
import { saveDeployKey } from '../command-helpers/auth.js';
import { chooseNodeUrl } from '../command-helpers/node.js';

Expand All @@ -16,6 +16,11 @@ export default class AuthCommand extends Command {
}),
};

private validateStudioDeployKey(value: string | undefined): boolean {
if (!value) return false;
return /^[0-9a-fA-F]{32}$/.test(value);
}

async run() {
const {
args: { 'deploy-key': initialDeployKey },
Expand All @@ -25,23 +30,22 @@ export default class AuthCommand extends Command {

const { deployKey } = await prompt.ask<{ deployKey: string }>([
{
type: 'invisible',
type: 'input',
name: 'deployKey',
message: () => 'What is the deploy key?',
initial: initialDeployKey,
message: () => 'What is your Subgraph Studio deploy key?',
required: true,
initial: initialDeployKey,
skip: this.validateStudioDeployKey(initialDeployKey),
validate: value =>
value.length > 200
? ux.error('✖ Deploy key must not exceed 200 characters', { exit: 1 })
: value,
this.validateStudioDeployKey(value) || `Invalid Subgraph Studio deploy key: ${value}`,
},
]);

try {
await saveDeployKey(node!, deployKey);
print.success(`Deploy key set for ${node}`);
} catch (e) {
this.error(e, { exit: 1 });
this.error(`Failed to set deploy key: ${e.message}`, { exit: 1 });
}
}
}
Loading