2019-11-15 16:01:13 -08:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as os from 'os';
|
|
|
|
import * as path from 'path';
|
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as io from '@actions/io';
|
|
|
|
|
2019-11-20 10:25:21 -08:00
|
|
|
export const M2_DIR = '.m2';
|
|
|
|
export const SETTINGS_FILE = 'settings.xml';
|
|
|
|
|
2019-11-28 12:40:08 -08:00
|
|
|
export async function configAuthentication(id: string, username: string, password: string) {
|
|
|
|
if (id && username && password) {
|
2019-11-20 10:25:21 -08:00
|
|
|
core.debug(`configAuthentication with ${username} and a password`);
|
|
|
|
const directory: string = path.join(os.homedir(), M2_DIR);
|
|
|
|
await io.mkdirP(directory);
|
|
|
|
core.debug(`created directory ${directory}`);
|
2019-11-28 12:40:08 -08:00
|
|
|
await write(directory, generate(id, username, password));
|
2019-11-20 10:25:21 -08:00
|
|
|
} else {
|
|
|
|
core.debug(
|
|
|
|
`no auth without username: ${username} and password: ${password}`
|
|
|
|
);
|
|
|
|
}
|
2019-11-15 16:01:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// only exported for testing purposes
|
2019-11-28 12:40:08 -08:00
|
|
|
export function generate(id: string, username: string, password: string) {
|
2019-11-20 10:25:21 -08:00
|
|
|
return `
|
|
|
|
<settings>
|
|
|
|
<servers>
|
|
|
|
<server>
|
2019-11-28 12:40:08 -08:00
|
|
|
<id>${id}</id>
|
2019-11-20 10:25:21 -08:00
|
|
|
<username>${username}</username>
|
|
|
|
<password>${password}</password>
|
|
|
|
</server>
|
|
|
|
</servers>
|
|
|
|
</settings>
|
|
|
|
`;
|
2019-11-15 16:01:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function write(directory: string, settings: string) {
|
2019-11-20 10:25:21 -08:00
|
|
|
const options = {encoding: 'utf-8'};
|
|
|
|
const location = path.join(directory, SETTINGS_FILE);
|
|
|
|
core.debug(`writing ${location}`);
|
|
|
|
return fs.writeFileSync(location, settings, options);
|
2019-11-15 16:01:13 -08:00
|
|
|
}
|