adding certs based auth for remote host
This commit is contained in:
Родитель
07446bfe97
Коммит
b10553c327
|
@ -1,5 +1,7 @@
|
|||
/// <reference path="../../../typings/vsts-task-lib/vsts-task-lib.d.ts" />
|
||||
|
||||
import fs = require("fs");
|
||||
import path = require("path");
|
||||
import tl = require("vsts-task-lib/task");
|
||||
import tr = require("vsts-task-lib/toolrunner");
|
||||
|
||||
|
@ -9,6 +11,7 @@ export class DockerCommand {
|
|||
public context: string;
|
||||
public imageName: string;
|
||||
public additionalArguments: string;
|
||||
public dockerConnectionString: string;
|
||||
public registryConnetionDetails: tl.EndpointAuthorization;
|
||||
|
||||
constructor(commandName: string) {
|
||||
|
@ -18,6 +21,8 @@ export class DockerCommand {
|
|||
public execSync() {
|
||||
var command = this.getBasicCommand();
|
||||
|
||||
this.appendAuth(command);
|
||||
|
||||
switch (this.commandName) {
|
||||
case "run":
|
||||
this.appendRunCmdArgs(command);
|
||||
|
@ -55,6 +60,32 @@ export class DockerCommand {
|
|||
return basicDockerCommand;
|
||||
}
|
||||
|
||||
private appendAuth(command: tr.ToolRunner) {
|
||||
var serverUrl = tl.getEndpointUrl(this.dockerConnectionString, false);
|
||||
var authDetails = tl.getEndpointAuthorization(this.dockerConnectionString, false);
|
||||
|
||||
var dir = path.join("", "certs");
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
|
||||
var caPath = path.join(dir, "ca.pem");
|
||||
fs.writeFileSync(caPath, authDetails.parameters["username"]);
|
||||
|
||||
var certPath = path.join(dir, "cert.pem");
|
||||
fs.writeFileSync(certPath, authDetails.parameters["password"]);
|
||||
|
||||
var keyPath = path.join(dir, "key.pem");
|
||||
fs.writeFileSync(keyPath, authDetails.parameters["key"]);
|
||||
|
||||
command.arg("--tls");
|
||||
command.arg("--tlscacert='" + caPath + "'");
|
||||
command.arg("--tlscert='" + certPath + "'");
|
||||
command.arg("--tlskey='" + keyPath + "'");
|
||||
command.arg("-H");
|
||||
command.arg(serverUrl);
|
||||
}
|
||||
|
||||
private appendRunCmdArgs(command: tr.ToolRunner) {
|
||||
command.arg("run");
|
||||
command.arg(this.imageName);
|
||||
|
|
|
@ -4,11 +4,13 @@ import tl = require("vsts-task-lib/task");
|
|||
import * as docker from "./dockerCommand";
|
||||
|
||||
export function dockerRun(): void {
|
||||
var dockerConnectionString = tl.getInput("dockerServiceEndpoint", true);
|
||||
var imageName = tl.getInput("imageName", true);
|
||||
var additionalArgs = tl.getInput("additionalArgs", false);
|
||||
|
||||
var cmd = new docker.DockerCommand("run");
|
||||
cmd.imageName = imageName;
|
||||
cmd.dockerConnectionString = dockerConnectionString;
|
||||
cmd.additionalArguments = additionalArgs;
|
||||
cmd.execSync();
|
||||
}
|
|
@ -17,6 +17,13 @@
|
|||
},
|
||||
"demands": [],
|
||||
"inputs": [
|
||||
{
|
||||
"name": "dockerServiceEndpoint",
|
||||
"type": "connectedService:Docker",
|
||||
"label": "Docker connection",
|
||||
"required": true,
|
||||
"helpMarkDown": "The Docker endpoint, set the certs and url."
|
||||
},
|
||||
{
|
||||
"name": "action",
|
||||
"type": "pickList",
|
||||
|
|
Загрузка…
Ссылка в новой задаче