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: support README_API_KEY env var #950

Merged
merged 2 commits into from
Dec 5, 2023
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
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