Skip to content

Commit

Permalink
feat: Add config option for external secret update interval (#7995)
Browse files Browse the repository at this point in the history
## Summary
Adds `N8N_EXTERNAL_SECRETS_UPDATE_INTERVAL` to allow enterprise users to
tweak the update internal for importing new secrets.

If using a config file the value is:

```
"externalSecrets": {
  "updateInterval": 300
}
```

#### How to test the change:
1. Run as normal and check that the secret is updated every 5 minutes
2. Set `N8N_EXTERNAL_SECRETS_UPDATE_INTERVAL` to 10
3. Check the secret is reloaded after 10 seconds


## Review / Merge checklist
- [x] PR title and summary are descriptive. **Remember, the title
automatically goes into the changelog. Use `(no-changelog)` otherwise.**
([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md))
- [x] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up
ticket created.
  • Loading branch information
Joffcom authored Dec 12, 2023
1 parent d0e44d4 commit b6c1c04
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
12 changes: 3 additions & 9 deletions packages/cli/src/ExternalSecrets/ExternalSecretsManager.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import Container, { Service } from 'typedi';
import { Logger } from '@/Logger';

import { jsonParse, type IDataObject, ApplicationError } from 'n8n-workflow';
import {
EXTERNAL_SECRETS_INITIAL_BACKOFF,
EXTERNAL_SECRETS_MAX_BACKOFF,
EXTERNAL_SECRETS_UPDATE_INTERVAL,
} from './constants';
import { EXTERNAL_SECRETS_INITIAL_BACKOFF, EXTERNAL_SECRETS_MAX_BACKOFF } from './constants';
import { License } from '@/License';
import { InternalHooks } from '@/InternalHooks';
import { updateIntervalTime } from './externalSecretsHelper.ee';
import { ExternalSecretsProviders } from './ExternalSecretsProviders.ee';
import { SingleMainSetup } from '@/services/orchestration/main/SingleMainSetup';

Expand Down Expand Up @@ -51,10 +48,7 @@ export class ExternalSecretsManager {
this.initialized = true;
resolve();
this.initializingPromise = undefined;
this.updateInterval = setInterval(
async () => this.updateSecrets(),
EXTERNAL_SECRETS_UPDATE_INTERVAL,
);
this.updateInterval = setInterval(async () => this.updateSecrets(), updateIntervalTime());
});
}
return this.initializingPromise;
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/ExternalSecrets/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const EXTERNAL_SECRETS_DB_KEY = 'feature.externalSecrets';
export const EXTERNAL_SECRETS_UPDATE_INTERVAL = 5 * 60 * 1000;
export const EXTERNAL_SECRETS_INITIAL_BACKOFF = 10 * 1000;
export const EXTERNAL_SECRETS_MAX_BACKOFF = 5 * 60 * 1000;

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/ExternalSecrets/externalSecretsHelper.ee.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { License } from '@/License';
import config from '@/config';
import Container from 'typedi';

export const updateIntervalTime = () => config.getEnv('externalSecrets.updateInterval') * 1000;

export function isExternalSecretsEnabled() {
const license = Container.get(License);
return license.isExternalSecretsEnabled();
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,15 @@ export const schema = {
},
},

externalSecrets: {
updateInterval: {
format: Number,
default: 300,
env: 'N8N_EXTERNAL_SECRETS_UPDATE_INTERVAL',
doc: 'How often (in seconds) to check for secret updates.',
},
},

deployment: {
type: {
format: String,
Expand Down

0 comments on commit b6c1c04

Please sign in to comment.