-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathActionInputs.ts
70 lines (59 loc) · 2.4 KB
/
ActionInputs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as core from '@actions/core';
import { PsqlConstants } from '../Constants';
export class ActionInputs {
private static actionInputs: ActionInputs;
private _serverName: string;
private _connectionString: string;
private _plsqlFile: string;
private _args: string;
constructor() {
this._serverName = core.getInput('server-name', { required: true });
this._connectionString = core.getInput('connection-string', { required: true });
this._plsqlFile = core.getInput('plsql-file', { required: true });
this._args = core.getInput('arguments');
this.parseConnectionString();
}
public static getActionInputs() {
if (!this.actionInputs) {
this.actionInputs = new ActionInputs();
}
return this.actionInputs;
}
private parseConnectionString() {
// Replace the "psql " part of the psql command copied from the Azure portal connection info
this._connectionString = this._connectionString.replace(/^psql\s/,'').replace(/["]+/g, '').trim();
if (!this.validateConnectionString()) {
throw new Error(`Please provide a valid connection string. A valid connection string is a series of keyword/value pairs separated by space. Spaces around the equal sign are optional. To write an empty value, or a value containing spaces, surround it with single quotes, e.g., keyword = 'a value'. Single quotes and backslashes within the value must be escaped with a backslash`);
}
const password = this.getPassword();
if (!password) {
throw new Error(`Password not found in connection string`);
}
core.setSecret(password);
}
private validateConnectionString(): boolean {
return PsqlConstants.connectionStringTestRegex.test(this.connectionString);
}
private getPassword() {
let password = '';
let matchingGroup = PsqlConstants.extractPasswordRegex.exec(this.connectionString);
if (matchingGroup) {
for(let match of matchingGroup) {
password = match;
}
}
return password;
};
public get connectionString() {
return this._connectionString;
}
public get plsqlFile() {
return this._plsqlFile;
}
public get args() {
return this._args;
}
public get serverName() {
return this._serverName;
}
}