mirror of
https://gitea.com/actions/setup-java.git
synced 2025-04-07 15:59:38 +00:00
move required parameters to auth module
username and password are required from within the auth module now. Update the tests to ensure this is the case.
This commit is contained in:
46
src/auth.ts
46
src/auth.ts
@ -4,28 +4,40 @@ import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
|
||||
export const M2_DIR = '.m2';
|
||||
export const SETTINGS_FILE = 'settings.xml';
|
||||
|
||||
export async function configAuthentication(username: string, password: string) {
|
||||
const directory: string = path.join(os.homedir(), '.m2');
|
||||
await io.mkdirP(directory);
|
||||
await write(directory, generate(username, password));
|
||||
if (username && password) {
|
||||
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}`);
|
||||
await write(directory, generate(username, password));
|
||||
} else {
|
||||
core.debug(
|
||||
`no auth without username: ${username} and password: ${password}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// only exported for testing purposes
|
||||
export function generate(
|
||||
username = '${actions.username}',
|
||||
password = '${actions.password}'
|
||||
) {
|
||||
return `<settings>
|
||||
<servers>
|
||||
<server>
|
||||
<username>${username}</username>
|
||||
<password>${password}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
`;
|
||||
export function generate(username: string, password: string) {
|
||||
return `
|
||||
<settings>
|
||||
<servers>
|
||||
<server>
|
||||
<username>${username}</username>
|
||||
<password>${password}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
`;
|
||||
}
|
||||
|
||||
async function write(directory: string, settings: string) {
|
||||
return fs.writeFileSync(path.join(directory, 'settings.xml'), settings);
|
||||
const options = {encoding: 'utf-8'};
|
||||
const location = path.join(directory, SETTINGS_FILE);
|
||||
core.debug(`writing ${location}`);
|
||||
return fs.writeFileSync(location, settings, options);
|
||||
}
|
||||
|
Reference in New Issue
Block a user