This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfiguration.js
162 lines (134 loc) · 4.6 KB
/
configuration.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const argv = require("yargs").argv;
const _ = require("lodash");
const path = require("path");
const logger = require("./logger");
const settings = require("./settings");
const guid = require("./util/guid");
const _loadConfig = (filename) => {
const filepath = path.resolve(process.cwd() + path.sep + filename);
try {
/*eslint-disable global-require*/
const config = require(filepath);
logger.log(`Loaded config file ${filename}`);
logger.debug(`Loading config from ${filename}:`);
logger.debug(`${JSON.stringify(config)}`);
return _.cloneDeep(config);
} catch (err) {
logger.err(`Cannot load config file from ${filename}`);
logger.err(err);
throw new Error(err);
}
};
module.exports = {
getConfig: () => {
return settings.config;
},
/*eslint-disable complexity*/
validateConfig: (opts, argvMock, envMock) => {
let runArgv = argv;
let env = process.env;
if (argvMock) {
runArgv = argvMock;
}
if (envMock) {
env = envMock;
}
if (runArgv.sauce_tunnel_config) {
settings.config.tunnel = _loadConfig(runArgv.sauce_tunnel_config);
}
// override sauce configurations from default source
// required:
if (env.SAUCE_USERNAME) {
settings.config.tunnel.username = env.SAUCE_USERNAME;
}
if (env.SAUCE_ACCESS_KEY) {
settings.config.tunnel.accessKey = env.SAUCE_ACCESS_KEY;
}
if (env.SAUCE_CONNECT_VERSION) {
settings.config.tunnel.connectVersion = env.SAUCE_CONNECT_VERSION;
}
// optional:
if (runArgv.sauce_tunnel_id) {
settings.config.tunnel.tunnelIdentifier = runArgv.sauce_tunnel_id;
}
// optional:
if (runArgv.sauce_app) {
settings.config.app = runArgv.sauce_app;
}
// optional:
if (runArgv.sauce_app_capabilities_config) {
settings.config.appCapabilitiesConfig = _loadConfig(runArgv.sauce_app_capabilities_config);
}
// optional: *Outbound* HTTP Sauce-specific proxy configuration. Note
// that this is for Selenium outbound control traffic only, not the
// return path, and not to be confused with sauceconnect.
if (env.SAUCE_OUTBOUND_PROXY) {
settings.config.sauceOutboundProxy = env.SAUCE_OUTBOUND_PROXY;
}
if (env.SAUCE_TUNNEL_FAST_FAIL_REGEXPS
&& !settings.config.tunnel.fastFailRegexps) {
// only if fastFailRegexps isn't set anywhere
settings.config.tunnel.fastFailRegexps = env.SAUCE_TUNNEL_FAST_FAIL_REGEXPS;
}
if (runArgv.shared_sauce_parent_account) {
settings.config.sharedSauceParentAccount = runArgv.shared_sauce_parent_account;
}
if (runArgv.sauce_create_tunnels) {
settings.config.useTunnels = !!runArgv.sauce_create_tunnels;
}
const parameterWarnings = {
username: {
required: true,
envKey: "SAUCE_USERNAME"
},
accessKey: {
required: true,
envKey: "SAUCE_ACCESS_KEY"
},
connectVersion: {
required: false,
envKey: "SAUCE_CONNECT_VERSION"
}
};
// Validate configuration if we have --sauce
if (runArgv.sauce_browsers
|| runArgv.sauce_browser
|| opts.isEnabled) {
let valid = true;
_.forEach(parameterWarnings, (v, k) => {
if (!settings.config.tunnel[k]) {
if (v.required) {
logger.err(`Error! Sauce requires ${k} to be set. Check if the`
+ ` environment variable $${v.envKey} is defined.`);
valid = false;
} else {
logger.warn(`Warning! No ${k} is set. This is set via the`
+ ` environment variable $${v.envKey} . This isn't required, but can cause `
+ "problems with Sauce if not set");
}
}
});
if (!valid) {
throw new Error("Missing configuration for Saucelabs connection.");
}
if (runArgv.sauce_create_tunnels) {
if (runArgv.sauce_tunnel_id) {
throw new Error("Only one Saucelabs tunnel arg is allowed, --sauce_tunnel_id " +
"or --create_tunnels.");
}
if (runArgv.shared_sauce_parent_account) {
throw new Error("--shared_sauce_parent_account only works with --sauce_tunnel_id.");
}
}
// after verification we want to add sauce_tunnel_id if it's null till now
if (!settings.config.tunnel.tunnelIdentifier && settings.config.useTunnels) {
// auto generate tunnel id
settings.config.tunnel.tunnelIdentifier = guid();
}
logger.debug("Sauce configuration: ");
logger.debug(JSON.stringify(settings.config));
logger.log("Sauce configuration OK");
}
return settings.config;
}
};