Skip to content

Commit

Permalink
graph auth bug fix (#1859)
Browse files Browse the repository at this point in the history
fixes #1858
  • Loading branch information
YaroShkvorets authored Dec 18, 2024
1 parent a6f6f11 commit 71c8405
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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 });
}
}
}

0 comments on commit 71c8405

Please sign in to comment.