Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
feat: adds ability to set custom baseUrl for API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Jul 17, 2020
1 parent 039d0bc commit 6f379b4
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Install package globally:
| zipFilename | Name of zip used for export / restoring data. E.g. 'kontent-backup'. |
| enableLog | Indicates if default logging is enabled (useful to indicate progress)
| force | If enabled, project will we exported / restored even if there are data inconsistencies. Enabled by default. |

| baseUrl | Custom base URL for Management API calls. |

### Execution

Expand Down Expand Up @@ -52,7 +52,8 @@ Create a `json` configuration file in the folder where you are attempting to run
"zipFilename": "backup",
"action": "backup",
"enableLog": true,
"force": true
"force": true,
"baseUrl": null
}
```

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"build:commonjs": "npm run tsc-local -- -m commonjs --outDir _commonjs",
"build:all": "npm run build:commonjs",
"test:all": "npm run build:all",
"test:backup": "npm run build:commonjs && cd output && node ../_commonjs/src/cli/app --config=backup-config.json",
"test:clean": "npm run build:commonjs && cd output && node ../_commonjs/src/cli/app --config=clean-config.json",
"test:restore": "npm run build:commonjs && cd output && node ../_commonjs/src/cli/app --config=restore-config.json",
"test:backup": "npm run build:commonjs && cd output && node ../_commonjs/src/node-js/cli/app --config=backup-config.json",
"test:clean": "npm run build:commonjs && cd output && node ../_commonjs/src/node-js/cli/app --config=clean-config.json",
"test:restore": "npm run build:commonjs && cd output && node ../_commonjs/src/node-js/cli/app --config=restore-config.json",
"ts-lint-local": "./node_modules/.bin/tslint",
"ts-lint:fix": "npm run ts-lint:check -- --fix",
"ts-lint:check": "npm run ts-lint-local -- --project ./tsconfig.json"
Expand Down
1 change: 1 addition & 0 deletions src/clean/clean.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IProcessedItem } from '../core';
export interface ICleanConfig {
projectId: string;
apiKey: string;
baseUrl?: string;
onDelete?: (item: IProcessedItem) => void;
}

Expand Down
3 changes: 2 additions & 1 deletion src/clean/clean.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class CleanService {
constructor(private config: ICleanConfig) {
this.client = new ManagementClient({
apiKey: config.apiKey,
projectId: config.projectId
projectId: config.projectId,
baseUrl: config.baseUrl
});
}

Expand Down
1 change: 1 addition & 0 deletions src/core/core.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ICliFileConfig {
zipFilename: string;
enableLog: boolean;
force: boolean;
baseUrl?: string;
}

export type CliAction = 'backup' | 'restore' | 'clean';
Expand Down
1 change: 1 addition & 0 deletions src/export/export.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IProcessedItem, IPackageMetadata } from '../core';
export interface IExportConfig {
projectId: string;
apiKey: string;
baseUrl?: string;
onExport?: (item: IProcessedItem) => void;
}

Expand Down
3 changes: 2 additions & 1 deletion src/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class ExportService {
constructor(private config: IExportConfig) {
this.client = new ManagementClient({
apiKey: config.apiKey,
projectId: config.projectId
projectId: config.projectId,
baseUrl: config.baseUrl
});
}

Expand Down
1 change: 1 addition & 0 deletions src/import/import.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { IProcessedItem, ItemType, IPackageMetadata } from '../core';

export interface IImportConfig {
workflowIdForImportedItems?: string;
baseUrl?: string;
projectId: string;
apiKey: string;
enableLog: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/import/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class ImportService {
constructor(private config: IImportConfig) {
this.client = new ManagementClient({
apiKey: config.apiKey,
baseUrl: config.baseUrl,
projectId: config.projectId,
retryStrategy: {
addJitter: true,
Expand Down
7 changes: 6 additions & 1 deletion src/node-js/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const backupAsync = async (config: ICliFileConfig) => {
const exportService = new ExportService({
apiKey: config.apiKey,
projectId: config.projectId,
baseUrl: config.baseUrl,
onExport: (item) => {
if (config.enableLog) {
console.log(`Exported: ${item.title} | ${item.type}`);
Expand Down Expand Up @@ -63,6 +64,7 @@ const cleanAsync = async (config: ICliFileConfig) => {
console.log(`Deleted: ${item.title} | ${item.type}`);
}
},
baseUrl: config.baseUrl,
projectId: config.projectId,
apiKey: config.apiKey
});
Expand All @@ -88,6 +90,7 @@ const restoreAsync = async (config: ICliFileConfig) => {
console.log(`Imported: ${item.title} | ${item.type}`);
}
},
baseUrl: config.baseUrl,
fixLanguages: true,
projectId: config.projectId,
apiKey: config.apiKey,
Expand Down Expand Up @@ -192,6 +195,7 @@ const getConfig = async () => {
const enableLog: boolean | undefined = (argv.enableLog as boolean | undefined) ?? true;
const force: boolean | undefined = (argv.force as boolean | undefined) ?? true;
const projectId: string | undefined = argv.projectId as string | undefined;
const baseUrl: string | undefined = argv.baseUrl as string | undefined;
const zipFilename: string | undefined = (argv.zipFilename as string | undefined) ?? getDefaultBackupFilename();

if (!action) {
Expand All @@ -213,7 +217,8 @@ const getConfig = async () => {
enableLog,
force,
projectId,
zipFilename
zipFilename,
baseUrl
};

return config;
Expand Down
3 changes: 2 additions & 1 deletion src/node-js/cli/sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"zipFilename": "backup",
"action": "backup",
"enableLog": true,
"force": false
"force": false,
"baseUrl": null
}

0 comments on commit 6f379b4

Please sign in to comment.