Skip to content

Commit

Permalink
Presonalized configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 16, 2020
1 parent 1f48d52 commit 763c60e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ describe('ServiceNow service', () => {

beforeAll(() => {
service = createExternalService({
url: 'https://dev102283.service-now.com',
username: 'admin',
password: 'admin',
config: { apiUrl: 'https://dev102283.service-now.com' },
secrets: { username: 'admin', password: 'admin' },
});
});

Expand All @@ -43,19 +42,28 @@ describe('ServiceNow service', () => {
describe('createExternalService', () => {
test('throws without url', () => {
expect(() =>
createExternalService({ url: null, username: 'admin', password: 'admin' })
createExternalService({
config: { apiUrl: null },
secrets: { username: 'admin', password: 'admin' },
})
).toThrow();
});

test('throws without username', () => {
expect(() =>
createExternalService({ url: 'test.com', username: '', password: 'admin' })
createExternalService({
config: { apiUrl: 'test.com' },
secrets: { username: '', password: 'admin' },
})
).toThrow();
});

test('throws without password', () => {
expect(() =>
createExternalService({ url: 'test.com', username: '', password: undefined })
createExternalService({
config: { apiUrl: 'test.com' },
secrets: { username: '', password: undefined },
})
).toThrow();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

import axios from 'axios';

import { ExternalServiceCredential, ExternalService, ExternalServiceParams } from '../types';
import {
ExternalServiceCredential,
ExternalService,
ExternalServiceParams,
ConnectorPublicConfigurationType,
ConnectorSecretConfigurationType,
} from '../types';
import { addTimeZoneToDate, patch, request } from '../utils';

const API_VERSION = 'v2';
Expand All @@ -21,10 +27,12 @@ export const getErrorMessage = (msg: string) => {
};

export const createExternalService = ({
url,
username,
password,
config,
secrets,
}: ExternalServiceCredential): ExternalService => {
const { apiUrl: url } = config as ConnectorPublicConfigurationType;
const { username, password } = secrets as ConnectorSecretConfigurationType;

if (!url || !username || !password) {
throw Error('[Action][ServiceNow]: Wrong configuration.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ export interface ConnectorConfiguration {
}

export interface ExternalServiceCredential {
url: string;
username: string;
password: string;
config: Record<string, any>;
secrets: Record<string, any>;
}

export interface ConnectorValidation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import {
CreateConnectorArgs,
ConnectorPublicConfigurationType,
ConnectorSecretConfigurationType,
CreateActionTypeArgs,
ExecutorParams,
MapRecord,
Expand Down Expand Up @@ -69,11 +68,9 @@ export const createConnectorExecutor = ({
): Promise<ActionTypeExecutorResult> => {
const actionId = execOptions.actionId;
const {
apiUrl,
casesConfiguration: { mapping: configurationMapping },
} = execOptions.config as ConnectorPublicConfigurationType;

const { username, password } = execOptions.secrets as ConnectorSecretConfigurationType;
const params = execOptions.params as ExecutorParams;
const { action, actionParams } = params;
const { comments, externalId, ...restParams } = actionParams;
Expand All @@ -87,7 +84,10 @@ export const createConnectorExecutor = ({
actionId,
};

const externalService = createExternalService({ url: apiUrl, username, password });
const externalService = createExternalService({
config: execOptions.config,
secrets: execOptions.secrets,
});

if (!api[action]) {
throw new Error('[Action][Connector] Unsupported action type');
Expand Down

0 comments on commit 763c60e

Please sign in to comment.