Skip to content
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
13 changes: 12 additions & 1 deletion docs/using-seerr/settings/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ This is your Seerr API key, which can be used to integrate Seerr with third-part

If you need to generate a new API key for any reason, simply click the button to the right of the text box.

If you want to set the API key, rather than letting it be randomly generated, you can use the API_KEY environment variable. Whatever that variable is set to will be your API key.
If you want to set the API key, rather than letting it be randomly generated,
you can use the API_KEY environment variable. Whatever that variable is set to
will be your API key.

You can also use the `api-key` credential, if you're using a systemd service.

```ini
[Service]
LoadCredential=api-key:/path/to/your/api-key-secret
```

[Learn more](https://systemd.io/CREDENTIALS/).

## Application Title

Expand Down
29 changes: 20 additions & 9 deletions server/lib/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,19 +745,29 @@ class Settings {
}

public async regenerateApiKey(): Promise<MainSettings> {
this.main.apiKey = this.generateApiKey();
this.main.apiKey = await this.generateApiKey();
await this.save();
return this.main;
}

private generateApiKey(): string {
if (process.env.API_KEY) {
private async apiKeyFromEnvOrCred(): Promise<string | undefined> {
const apiKeyCredential = `${process.env.CREDENTIALS_DIRECTORY}/api-key`;

try {
return await fs.readFile(apiKeyCredential, 'utf-8');
} catch {
return process.env.API_KEY;
} else {
return Buffer.from(`${Date.now()}${randomUUID()}`).toString('base64');
}
}

private async generateApiKey(): Promise<string> {
const apiKey = await this.apiKeyFromEnvOrCred();

return (
apiKey || Buffer.from(`${Date.now()}${randomUUID()}`).toString('base64')
);
}

/**
* Settings Load
*
Expand Down Expand Up @@ -794,11 +804,12 @@ class Settings {
// generate keys and ids if it's missing
let change = false;
if (!this.data.main.apiKey) {
this.data.main.apiKey = this.generateApiKey();
this.data.main.apiKey = await this.generateApiKey();
change = true;
} else if (process.env.API_KEY) {
if (this.main.apiKey != process.env.API_KEY) {
this.main.apiKey = process.env.API_KEY;
} else {
const apiKey = await this.apiKeyFromEnvOrCred();
if (apiKey && this.main.apiKey != apiKey) {
this.main.apiKey = apiKey;
}
}
if (!this.data.clientId) {
Expand Down
Loading