Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users/aamallad/maven auth fix #13429

Merged
merged 7 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"loc.messages.Info_SettingsXmlRead": "Adding authentication to settings file %s.",
"loc.messages.Info_CreatingSettingsXml": "Creating new settings.xml at path %s.",
"loc.messages.Info_WritingToSettingsXml": "Writing new settings.xml with added authentication.",
"loc.messages.Error_InvalidServiceConnection": "The service connection for %s is invalid."
"loc.messages.Error_InvalidServiceConnection": "The service connection for %s is invalid.",
"loc.messages.Error_FailedCleanupM2": "Failed to delete credentials from the user settings.xml file: %s"
}
25 changes: 25 additions & 0 deletions Tasks/MavenAuthenticateV0/cleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as path from 'path';
import * as tl from 'azure-pipelines-task-lib/task';

async function run() {
try {
tl.setResourcePath(path.join(__dirname, 'task.json'));

const userM2SettingsXmlPath: string = tl.getTaskVariable('userM2SettingsXmlPath');
const backupUserM2SettingsFilePath: string = tl.getTaskVariable('backupUserM2SettingsFilePath');

if (userM2SettingsXmlPath && tl.exist(userM2SettingsXmlPath)) {
tl.rmRF(userM2SettingsXmlPath);
tl.debug('Deleted user m2 settings.xml file: ' + userM2SettingsXmlPath);

if (backupUserM2SettingsFilePath && tl.exist(backupUserM2SettingsFilePath)) {
tl.mv(backupUserM2SettingsFilePath, userM2SettingsXmlPath);
tl.debug('Restored old user m2 settings.xml file: ' + backupUserM2SettingsFilePath);
}
}
} catch (err) {
tl.warning(tl.loc('Error_FailedCleanupM2', err));
}
}

run();
10 changes: 8 additions & 2 deletions Tasks/MavenAuthenticateV0/mavenauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { emitTelemetry } from 'artifacts-common/telemetry';

const M2FolderName: string = ".m2";
const SettingsXmlName: string = "settings.xml";
const backupSettingsXmlName: string = "_settings.xml";

tl.setResourcePath(path.join(__dirname, 'task.json'));

Expand Down Expand Up @@ -36,11 +37,16 @@ async function run(): Promise<void> {
}

let userSettingsXmlPath: string = path.join(userM2FolderPath, SettingsXmlName);
let backupSettingsXmlPath: string = path.join(userM2FolderPath, backupSettingsXmlName);
let settingsJson: any;

tl.setTaskVariable('userM2SettingsXmlPath', userSettingsXmlPath);

if(tl.exist(userSettingsXmlPath)) {
if (tl.exist(userSettingsXmlPath)) {
tl.debug(tl.loc("Info_SettingsXmlRead", userSettingsXmlPath));
settingsJson = await util.readXmlFileAsJson(userSettingsXmlPath)
tl.cp(userSettingsXmlPath, backupSettingsXmlPath);
tl.setTaskVariable("backupUserM2SettingsFilePath", backupSettingsXmlPath);
settingsJson = await util.readXmlFileAsJson(userSettingsXmlPath);
}
else {
tl.debug(tl.loc("Info_CreatingSettingsXml", userSettingsXmlPath));
Expand Down
13 changes: 10 additions & 3 deletions Tasks/MavenAuthenticateV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 167,
"Patch": 2
"Minor": 175,
"Patch": 0
},
"runsOn": [
"Agent",
Expand Down Expand Up @@ -54,6 +54,12 @@
"target": "mavenauth.js"
}
},
"postjobexecution": {
"Node": {
"target": "cleanup.js",
"argumentFormat": ""
}
},
"messages": {
"Warning_FeedEntryAlreadyExists": "The settings for the feed or repository '%s' already exists in the users settings.xml file.",
"Warning_NoEndpointsToAuth": "No repositories were selected to authenticate, please check your task configuration.",
Expand All @@ -63,6 +69,7 @@
"Info_SettingsXmlRead": "Adding authentication to settings file %s.",
"Info_CreatingSettingsXml": "Creating new settings.xml at path %s.",
"Info_WritingToSettingsXml": "Writing new settings.xml with added authentication.",
"Error_InvalidServiceConnection": "The service connection for %s is invalid."
"Error_InvalidServiceConnection": "The service connection for %s is invalid.",
"Error_FailedCleanupM2": "Failed to delete credentials from the user settings.xml file: %s"
}
}
13 changes: 10 additions & 3 deletions Tasks/MavenAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 167,
"Patch": 2
"Minor": 175,
"Patch": 0
},
"runsOn": [
"Agent",
Expand Down Expand Up @@ -54,6 +54,12 @@
"target": "mavenauth.js"
}
},
"postjobexecution": {
"Node": {
"target": "cleanup.js",
"argumentFormat": ""
}
},
"messages": {
"Warning_FeedEntryAlreadyExists": "ms-resource:loc.messages.Warning_FeedEntryAlreadyExists",
"Warning_NoEndpointsToAuth": "ms-resource:loc.messages.Warning_NoEndpointsToAuth",
Expand All @@ -63,6 +69,7 @@
"Info_SettingsXmlRead": "ms-resource:loc.messages.Info_SettingsXmlRead",
"Info_CreatingSettingsXml": "ms-resource:loc.messages.Info_CreatingSettingsXml",
"Info_WritingToSettingsXml": "ms-resource:loc.messages.Info_WritingToSettingsXml",
"Error_InvalidServiceConnection": "ms-resource:loc.messages.Error_InvalidServiceConnection"
"Error_InvalidServiceConnection": "ms-resource:loc.messages.Error_InvalidServiceConnection",
"Error_FailedCleanupM2": "ms-resource:loc.messages.Error_FailedCleanupM2"
}
}