Skip to content

Commit

Permalink
Fix Helm repo quoting for Windows (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone authored Apr 18, 2019
1 parent f5b32da commit 4b01b51
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### Bug fixes

- None
- Fix Helm repo quoting for Windows (https://github.com/pulumi/pulumi-kubernetes/pull/540)

## 0.22.2 (April 11, 2019)

Expand Down
15 changes: 7 additions & 8 deletions sdk/nodejs/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import * as nodepath from "path";
import * as shell from "shell-quote";
import * as tmp from "tmp";
import * as path from "../../path";

import * as yaml from "../../yaml/index";

interface BaseChartOpts {
Expand Down Expand Up @@ -361,20 +360,20 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) {
// For arguments that are not paths to files, it is sufficent to use shell.quote to quote the arguments.
// However, for arguments that are actual paths to files we use path.quotePath (note that path here is
// not the node path builtin module). This ensures proper escaping of paths on Windows.
if (opts.version !== undefined) { flags.push(`--version ${shell.quote([opts.version])}`); }
if (opts.version !== undefined) { flags.push(`--version ${shell.quote([opts.version])}`); }
if (opts.caFile !== undefined) { flags.push(`--ca-file ${path.quotePath(opts.caFile)}`); }
if (opts.certFile !== undefined) { flags.push(`--cert-file ${path.quotePath(opts.certFile)}`); }
if (opts.keyFile !== undefined) { flags.push(`--key-file ${path.quotePath(opts.keyFile)}`); }
if (opts.destination !== undefined) { flags.push(`--destination ${path.quotePath(opts.destination)}`); }
if (opts.keyring !== undefined) { flags.push(`--keyring ${path.quotePath(opts.keyring)}`); }
if (opts.password !== undefined) { flags.push(`--password ${shell.quote([opts.password])}`); }
if (opts.repo !== undefined) { flags.push(`--repo ${shell.quote([opts.repo])}`); }
if (opts.password !== undefined) { flags.push(`--password ${shell.quote([opts.password])}`); }
if (opts.repo !== undefined) { flags.push(`--repo ${path.quotePath(opts.repo)}`); }
if (opts.untardir !== undefined) { flags.push(`--untardir ${path.quotePath(opts.untardir)}`); }
if (opts.username !== undefined) { flags.push(`--username ${shell.quote([opts.username])}`); }
if (opts.username !== undefined) { flags.push(`--username ${shell.quote([opts.username])}`); }
if (opts.home !== undefined) { flags.push(`--home ${path.quotePath(opts.home)}`); }
if (opts.devel === true) { flags.push(`--devel`); }
if (opts.prov === true) { flags.push(`--prov`); }
if (opts.verify === true) { flags.push(`--verify`); }
if (opts.devel === true) { flags.push(`--devel`); }
if (opts.prov === true) { flags.push(`--prov`); }
if (opts.verify === true) { flags.push(`--verify`); }
}
execSync(`helm fetch ${shell.quote([chart])} ${flags.join(" ")}`);
}
1 change: 1 addition & 0 deletions sdk/nodejs/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ import * as shell from "shell-quote";
// [1]: https://github.com/substack/node-shell-quote/pull/34

path = String(path).replace(/([A-z]:)?([#!"$&'()*,:;<=>?@\[\\\]^`{|}])/g, "$1\\$2");
path = path.replace(/\\:/g, ":");
return path.replace(/\\\\/g, "\\");
}
10 changes: 7 additions & 3 deletions sdk/nodejs/tests/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import * as path from "../path";
describe("path.quoteWindowsPath", () => {
it("escapes Windows path with drive prefix correctly", () => {
const p = path.quoteWindowsPath("C:\\Users\\grace hopper\\AppData\\Local\\Temp");
assert.equal(p, "C:\\Users\\grace hopper\\AppData\\Local\\Temp");
assert.strictEqual(p, "C:\\Users\\grace hopper\\AppData\\Local\\Temp");
});
it("escapes Windows path with no drive prefix correctly", () => {
const p = path.quoteWindowsPath("\\Users\\grace hopper\\AppData\\Local\\Temp");
assert.equal(p, "\\Users\\grace hopper\\AppData\\Local\\Temp");
assert.strictEqual(p, "\\Users\\grace hopper\\AppData\\Local\\Temp");
});
it("escapes relative Windows path correctly", () => {
const p = path.quoteWindowsPath("Users\\grace hopper\\AppData\\Local\\Temp");
assert.equal(p, "Users\\grace hopper\\AppData\\Local\\Temp");
assert.strictEqual(p, "Users\\grace hopper\\AppData\\Local\\Temp");
});
it("escapes Windows repo URL correctly", () => {
const p = path.quoteWindowsPath("https\://gcsweb.istio.io/gcs/istio-release/releases/1.1.2/charts/");
assert.strictEqual(p, "https://gcsweb.istio.io/gcs/istio-release/releases/1.1.2/charts/");
});
});

0 comments on commit 4b01b51

Please sign in to comment.