Skip to content

Commit

Permalink
Allow yaml.ConfigGroup to take URLs as argument
Browse files Browse the repository at this point in the history
Fixes #448.
  • Loading branch information
hausdorff committed Jul 13, 2019
1 parent a8047e5 commit 37bbedb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
20 changes: 16 additions & 4 deletions pkg/gen/nodejs-templates/yaml.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ import * as outputApi from "../types/output";
if (config.files !== undefined) {
let files: string[] = [];
if (typeof config.files === 'string') {
files = glob.sync(config.files);
if (isUrl(config.files)) {
files = [config.files];
} else {
files = glob.sync(config.files);
}
} else {
for (const file of config.files) {
files.push(...glob.sync(file));
if (isUrl(file)) {
files.push(file);
} else {
files.push(...glob.sync(file));
}
}
}

Expand Down Expand Up @@ -235,7 +243,7 @@ import * as outputApi from "../types/output";
super("kubernetes:yaml:ConfigFile", name, config, opts);
const fileId = config && config.file || name;
let text: Promise<string>;
if (fileId.startsWith("http://") || fileId.startsWith("https://")) {
if (isUrl(fileId)) {
text = fetch(fileId).then(r => r.text())
} else {
text = Promise.resolve(fs.readFileSync(fileId).toString());
Expand All @@ -249,6 +257,10 @@ import * as outputApi from "../types/output";
}
}

/** @ignore */ function isUrl(s: string): boolean {
return s.startsWith("http://") || s.startsWith("https://")
}

/** @ignore */ function parseYamlDocument(
config: ConfigOpts,
opts?: pulumi.CustomResourceOptions,
Expand Down Expand Up @@ -285,7 +297,7 @@ import * as outputApi from "../types/output";
// Create a copy of opts to pass into potentially mutating transforms that will be applied to this resource.
opts = Object.assign({}, opts);

// Allow users to change API objects before any validation.
// Allow users to change API objects before any validation.
for (const t of transformations || []) {
t(obj, opts);
}
Expand Down
20 changes: 16 additions & 4 deletions sdk/nodejs/yaml/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ import * as outputApi from "../types/output";
if (config.files !== undefined) {
let files: string[] = [];
if (typeof config.files === 'string') {
files = glob.sync(config.files);
if (isUrl(config.files)) {
files = [config.files];
} else {
files = glob.sync(config.files);
}
} else {
for (const file of config.files) {
files.push(...glob.sync(file));
if (isUrl(file)) {
files.push(file);
} else {
files.push(...glob.sync(file));
}
}
}

Expand Down Expand Up @@ -2211,7 +2219,7 @@ import * as outputApi from "../types/output";
super("kubernetes:yaml:ConfigFile", name, config, opts);
const fileId = config && config.file || name;
let text: Promise<string>;
if (fileId.startsWith("http://") || fileId.startsWith("https://")) {
if (isUrl(fileId)) {
text = fetch(fileId).then(r => r.text())
} else {
text = Promise.resolve(fs.readFileSync(fileId).toString());
Expand All @@ -2225,6 +2233,10 @@ import * as outputApi from "../types/output";
}
}

/** @ignore */ function isUrl(s: string): boolean {
return s.startsWith("http://") || s.startsWith("https://")
}

/** @ignore */ function parseYamlDocument(
config: ConfigOpts,
opts?: pulumi.CustomResourceOptions,
Expand Down Expand Up @@ -2261,7 +2273,7 @@ import * as outputApi from "../types/output";
// Create a copy of opts to pass into potentially mutating transforms that will be applied to this resource.
opts = Object.assign({}, opts);

// Allow users to change API objects before any validation.
// Allow users to change API objects before any validation.
for (const t of transformations || []) {
t(obj, opts);
}
Expand Down

0 comments on commit 37bbedb

Please sign in to comment.