Skip to content

Commit

Permalink
feat: support README_API_KEY env var (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta authored Dec 5, 2023
1 parent 72991bf commit bcf3f18
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ For local CLI usage with a single project, you can authenticate `rdme` to your R
> [!WARNING]
> For security reasons, we strongly recommend providing a project API key via the `--key` option in automations or CI environments (GitHub Actions, CircleCI, Travis CI, etc.). It's also recommended if you're working with multiple ReadMe projects to avoid accidentally overwriting existing data.
You can also pass in your API key via the `RDME_API_KEY` environmental variable. Here is the order of precedence when passing your API key into `rdme`:
You can also pass in your API key via environmental variable. Here is the order of precedence when passing your API key into `rdme`:

1. The `--key` option. If that isn't present, we look for...
1. The `RDME_API_KEY` environmental variable. If that isn't present, we look for...
1. The `README_API_KEY` environmental variable. If that isn't present, we look for...
1. The API key value stored in your local configuration file (i.e., the one set via `rdme login`)

`rdme whoami` is also available to you to determine who is logged in, and to what project. You can clear your stored credentials with `rdme logout`.
Expand Down
4 changes: 2 additions & 2 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ describe('cli', () => {
});
});

describe('stored API key via env vars', () => {
describe.each(['README_API_KEY', 'RDME_API_KEY'])('stored API key via %s env var', envKey => {
let consoleInfoSpy;
const key = '123456-env';
const getCommandOutput = () => {
return [consoleInfoSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n');
};

beforeEach(() => {
vi.stubEnv('RDME_API_KEY', key);
vi.stubEnv(envKey, key);
vi.stubEnv('RDME_EMAIL', '[email protected]');
vi.stubEnv('RDME_PROJECT', 'project-owlbert-env');
consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/getCurrentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import configstore from './configstore.js';
* with env variables taking precedent
*/
export default function getCurrentConfig(): { apiKey?: string; email?: string; project?: string } {
const apiKey = process.env.RDME_API_KEY || configstore.get('apiKey');
const apiKey = process.env.RDME_API_KEY || process.env.README_API_KEY || configstore.get('apiKey');
const email = process.env.RDME_EMAIL || configstore.get('email');
const project = process.env.RDME_PROJECT || configstore.get('project');

Expand Down

0 comments on commit bcf3f18

Please sign in to comment.