2018-05-22 19:43:36 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
Implement initial Lumi-as-a-library
This is the initial step towards redefining Lumi as a library that runs
atop vanilla Node.js/V8, rather than as its own runtime.
This change is woefully incomplete but this includes some of the more
stable pieces of my current work-in-progress.
The new structure is that within the sdk/ directory we will have a client
library per language. This client library contains the object model for
Lumi (resources, properties, assets, config, etc), in addition to the
"language runtime host" components required to interoperate with the
Lumi resource monitor. This resource monitor is effectively what we call
"Lumi" today, in that it's the thing orchestrating plans and deployments.
Inside the sdk/ directory, you will find nodejs/, the Node.js client
library, alongside proto/, the definitions for RPC interop between the
different pieces of the system. This includes existing RPC definitions
for resource providers, etc., in addition to the new ones for hosting
different language runtimes from within Lumi.
These new interfaces are surprisingly simple. There is effectively a
bidirectional RPC channel between the Lumi resource monitor, represented
by the lumirpc.ResourceMonitor interface, and each language runtime,
represented by the lumirpc.LanguageRuntime interface.
The overall orchestration goes as follows:
1) Lumi decides it needs to run a program written in language X, so
it dynamically loads the language runtime plugin for language X.
2) Lumi passes that runtime a loopback address to its ResourceMonitor
service, while language X will publish a connection back to its
LanguageRuntime service, which Lumi will talk to.
3) Lumi then invokes LanguageRuntime.Run, passing information like
the desired working directory, program name, arguments, and optional
configuration variables to make available to the program.
4) The language X runtime receives this, unpacks it and sets up the
necessary context, and then invokes the program. The program then
calls into Lumi object model abstractions that internally communicate
back to Lumi using the ResourceMonitor interface.
5) The key here is ResourceMonitor.NewResource, which Lumi uses to
serialize state about newly allocated resources. Lumi receives these
and registers them as part of the plan, doing the usual diffing, etc.,
to decide how to proceed. This interface is perhaps one of the
most subtle parts of the new design, as it necessitates the use of
promises internally to allow parallel evaluation of the resource plan,
letting dataflow determine the available concurrency.
6) The program exits, and Lumi continues on its merry way. If the program
fails, the RunResponse will include information about the failure.
Due to (5), all properties on resources are now instances of a new
Property<T> type. A Property<T> is just a thin wrapper over a T, but it
encodes the special properties of Lumi resource properties. Namely, it
is possible to create one out of a T, other Property<T>, Promise<T>, or
to freshly allocate one. In all cases, the Property<T> does not "settle"
until its final state is known. This cannot occur before the deployment
actually completes, and so in general it's not safe to depend on concrete
resolutions of values (unlike ordinary Promise<T>s which are usually
expected to resolve). As a result, all derived computations are meant to
use the `then` function (as in `someValue.then(v => v+x)`).
Although this change includes tests that may be run in isolation to test
the various RPC interactions, we are nowhere near finished. The remaining
work primarily boils down to three things:
1) Wiring all of this up to the Lumi code.
2) Fixing the handful of known loose ends required to make this work,
primarily around the serialization of properties (waiting on
unresolved ones, serializing assets properly, etc).
3) Implementing lambda closure serialization as a native extension.
This ongoing work is part of pulumi/pulumi-fabric#311.
2017-08-26 19:07:54 +00:00
|
|
|
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
import { RunError } from "./errors";
|
2022-09-01 18:39:09 +00:00
|
|
|
import { getProject as metadataGetProject } from "./metadata";
|
2019-05-10 07:06:10 +00:00
|
|
|
import { Output } from "./output";
|
2022-09-01 18:39:09 +00:00
|
|
|
import { allConfig, getConfig as runtimeGetConfig } from "./runtime/config";
|
Implement initial Lumi-as-a-library
This is the initial step towards redefining Lumi as a library that runs
atop vanilla Node.js/V8, rather than as its own runtime.
This change is woefully incomplete but this includes some of the more
stable pieces of my current work-in-progress.
The new structure is that within the sdk/ directory we will have a client
library per language. This client library contains the object model for
Lumi (resources, properties, assets, config, etc), in addition to the
"language runtime host" components required to interoperate with the
Lumi resource monitor. This resource monitor is effectively what we call
"Lumi" today, in that it's the thing orchestrating plans and deployments.
Inside the sdk/ directory, you will find nodejs/, the Node.js client
library, alongside proto/, the definitions for RPC interop between the
different pieces of the system. This includes existing RPC definitions
for resource providers, etc., in addition to the new ones for hosting
different language runtimes from within Lumi.
These new interfaces are surprisingly simple. There is effectively a
bidirectional RPC channel between the Lumi resource monitor, represented
by the lumirpc.ResourceMonitor interface, and each language runtime,
represented by the lumirpc.LanguageRuntime interface.
The overall orchestration goes as follows:
1) Lumi decides it needs to run a program written in language X, so
it dynamically loads the language runtime plugin for language X.
2) Lumi passes that runtime a loopback address to its ResourceMonitor
service, while language X will publish a connection back to its
LanguageRuntime service, which Lumi will talk to.
3) Lumi then invokes LanguageRuntime.Run, passing information like
the desired working directory, program name, arguments, and optional
configuration variables to make available to the program.
4) The language X runtime receives this, unpacks it and sets up the
necessary context, and then invokes the program. The program then
calls into Lumi object model abstractions that internally communicate
back to Lumi using the ResourceMonitor interface.
5) The key here is ResourceMonitor.NewResource, which Lumi uses to
serialize state about newly allocated resources. Lumi receives these
and registers them as part of the plan, doing the usual diffing, etc.,
to decide how to proceed. This interface is perhaps one of the
most subtle parts of the new design, as it necessitates the use of
promises internally to allow parallel evaluation of the resource plan,
letting dataflow determine the available concurrency.
6) The program exits, and Lumi continues on its merry way. If the program
fails, the RunResponse will include information about the failure.
Due to (5), all properties on resources are now instances of a new
Property<T> type. A Property<T> is just a thin wrapper over a T, but it
encodes the special properties of Lumi resource properties. Namely, it
is possible to create one out of a T, other Property<T>, Promise<T>, or
to freshly allocate one. In all cases, the Property<T> does not "settle"
until its final state is known. This cannot occur before the deployment
actually completes, and so in general it's not safe to depend on concrete
resolutions of values (unlike ordinary Promise<T>s which are usually
expected to resolve). As a result, all derived computations are meant to
use the `then` function (as in `someValue.then(v => v+x)`).
Although this change includes tests that may be run in isolation to test
the various RPC interactions, we are nowhere near finished. The remaining
work primarily boils down to three things:
1) Wiring all of this up to the Lumi code.
2) Fixing the handful of known loose ends required to make this work,
primarily around the serialization of properties (waiting on
unresolved ones, serializing assets properly, etc).
3) Implementing lambda closure serialization as a native extension.
This ongoing work is part of pulumi/pulumi-fabric#311.
2017-08-26 19:07:54 +00:00
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
function makeSecret<T>(value: T): Output<T> {
|
2022-09-01 18:39:09 +00:00
|
|
|
const output = require("./output");
|
|
|
|
return new output.Output(
|
2023-04-28 22:27:10 +00:00
|
|
|
[],
|
|
|
|
Promise.resolve(value),
|
|
|
|
/*isKnown:*/ Promise.resolve(true),
|
|
|
|
/*isSecret:*/ Promise.resolve(true),
|
|
|
|
Promise.resolve([]),
|
|
|
|
);
|
2019-05-10 07:06:10 +00:00
|
|
|
}
|
|
|
|
|
2022-09-01 18:39:09 +00:00
|
|
|
function getProject(): string {
|
|
|
|
return metadataGetProject();
|
2023-04-28 22:27:10 +00:00
|
|
|
}
|
2022-09-01 18:39:09 +00:00
|
|
|
|
|
|
|
// This is used to capture and serialize the results of
|
|
|
|
// getProject for use in non-pulumi engine contexts
|
|
|
|
(<any>getProject).captureReplacement = () => {
|
|
|
|
const project = metadataGetProject();
|
|
|
|
const funcToSerialize = () => project;
|
|
|
|
return funcToSerialize;
|
|
|
|
};
|
|
|
|
|
|
|
|
function getConfig(k: string): string | undefined {
|
|
|
|
return runtimeGetConfig(k);
|
2023-04-28 22:27:10 +00:00
|
|
|
}
|
2022-09-01 18:39:09 +00:00
|
|
|
|
|
|
|
// This is used to capture and serialize the results of
|
|
|
|
// getConfig for use in non-pulumi engine contexts
|
|
|
|
(<any>getConfig).captureReplacement = () => {
|
|
|
|
const config = allConfig();
|
|
|
|
|
|
|
|
const funcToSerialize = (k: string) => config[k];
|
|
|
|
return funcToSerialize;
|
|
|
|
};
|
|
|
|
|
2017-09-22 01:15:29 +00:00
|
|
|
/**
|
|
|
|
* Config is a bag of related configuration state. Each bag contains any number of configuration variables, indexed by
|
|
|
|
* simple keys, and each has a name that uniquely identifies it; two bags with different names do not share values for
|
|
|
|
* variables that otherwise share the same key. For example, a bag whose name is `pulumi:foo`, with keys `a`, `b`,
|
|
|
|
* and `c`, is entirely separate from a bag whose name is `pulumi:bar` with the same simple key names. Each key has a
|
|
|
|
* fully qualified names, such as `pulumi:foo:a`, ..., and `pulumi:bar:a`, respectively.
|
|
|
|
*/
|
Implement initial Lumi-as-a-library
This is the initial step towards redefining Lumi as a library that runs
atop vanilla Node.js/V8, rather than as its own runtime.
This change is woefully incomplete but this includes some of the more
stable pieces of my current work-in-progress.
The new structure is that within the sdk/ directory we will have a client
library per language. This client library contains the object model for
Lumi (resources, properties, assets, config, etc), in addition to the
"language runtime host" components required to interoperate with the
Lumi resource monitor. This resource monitor is effectively what we call
"Lumi" today, in that it's the thing orchestrating plans and deployments.
Inside the sdk/ directory, you will find nodejs/, the Node.js client
library, alongside proto/, the definitions for RPC interop between the
different pieces of the system. This includes existing RPC definitions
for resource providers, etc., in addition to the new ones for hosting
different language runtimes from within Lumi.
These new interfaces are surprisingly simple. There is effectively a
bidirectional RPC channel between the Lumi resource monitor, represented
by the lumirpc.ResourceMonitor interface, and each language runtime,
represented by the lumirpc.LanguageRuntime interface.
The overall orchestration goes as follows:
1) Lumi decides it needs to run a program written in language X, so
it dynamically loads the language runtime plugin for language X.
2) Lumi passes that runtime a loopback address to its ResourceMonitor
service, while language X will publish a connection back to its
LanguageRuntime service, which Lumi will talk to.
3) Lumi then invokes LanguageRuntime.Run, passing information like
the desired working directory, program name, arguments, and optional
configuration variables to make available to the program.
4) The language X runtime receives this, unpacks it and sets up the
necessary context, and then invokes the program. The program then
calls into Lumi object model abstractions that internally communicate
back to Lumi using the ResourceMonitor interface.
5) The key here is ResourceMonitor.NewResource, which Lumi uses to
serialize state about newly allocated resources. Lumi receives these
and registers them as part of the plan, doing the usual diffing, etc.,
to decide how to proceed. This interface is perhaps one of the
most subtle parts of the new design, as it necessitates the use of
promises internally to allow parallel evaluation of the resource plan,
letting dataflow determine the available concurrency.
6) The program exits, and Lumi continues on its merry way. If the program
fails, the RunResponse will include information about the failure.
Due to (5), all properties on resources are now instances of a new
Property<T> type. A Property<T> is just a thin wrapper over a T, but it
encodes the special properties of Lumi resource properties. Namely, it
is possible to create one out of a T, other Property<T>, Promise<T>, or
to freshly allocate one. In all cases, the Property<T> does not "settle"
until its final state is known. This cannot occur before the deployment
actually completes, and so in general it's not safe to depend on concrete
resolutions of values (unlike ordinary Promise<T>s which are usually
expected to resolve). As a result, all derived computations are meant to
use the `then` function (as in `someValue.then(v => v+x)`).
Although this change includes tests that may be run in isolation to test
the various RPC interactions, we are nowhere near finished. The remaining
work primarily boils down to three things:
1) Wiring all of this up to the Lumi code.
2) Fixing the handful of known loose ends required to make this work,
primarily around the serialization of properties (waiting on
unresolved ones, serializing assets properly, etc).
3) Implementing lambda closure serialization as a native extension.
This ongoing work is part of pulumi/pulumi-fabric#311.
2017-08-26 19:07:54 +00:00
|
|
|
export class Config {
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
/**
|
2018-08-02 22:27:37 +00:00
|
|
|
* name is the configuration bag's logical name and uniquely identifies it. The default is the name of the current
|
|
|
|
* project.
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
*/
|
Implement initial Lumi-as-a-library
This is the initial step towards redefining Lumi as a library that runs
atop vanilla Node.js/V8, rather than as its own runtime.
This change is woefully incomplete but this includes some of the more
stable pieces of my current work-in-progress.
The new structure is that within the sdk/ directory we will have a client
library per language. This client library contains the object model for
Lumi (resources, properties, assets, config, etc), in addition to the
"language runtime host" components required to interoperate with the
Lumi resource monitor. This resource monitor is effectively what we call
"Lumi" today, in that it's the thing orchestrating plans and deployments.
Inside the sdk/ directory, you will find nodejs/, the Node.js client
library, alongside proto/, the definitions for RPC interop between the
different pieces of the system. This includes existing RPC definitions
for resource providers, etc., in addition to the new ones for hosting
different language runtimes from within Lumi.
These new interfaces are surprisingly simple. There is effectively a
bidirectional RPC channel between the Lumi resource monitor, represented
by the lumirpc.ResourceMonitor interface, and each language runtime,
represented by the lumirpc.LanguageRuntime interface.
The overall orchestration goes as follows:
1) Lumi decides it needs to run a program written in language X, so
it dynamically loads the language runtime plugin for language X.
2) Lumi passes that runtime a loopback address to its ResourceMonitor
service, while language X will publish a connection back to its
LanguageRuntime service, which Lumi will talk to.
3) Lumi then invokes LanguageRuntime.Run, passing information like
the desired working directory, program name, arguments, and optional
configuration variables to make available to the program.
4) The language X runtime receives this, unpacks it and sets up the
necessary context, and then invokes the program. The program then
calls into Lumi object model abstractions that internally communicate
back to Lumi using the ResourceMonitor interface.
5) The key here is ResourceMonitor.NewResource, which Lumi uses to
serialize state about newly allocated resources. Lumi receives these
and registers them as part of the plan, doing the usual diffing, etc.,
to decide how to proceed. This interface is perhaps one of the
most subtle parts of the new design, as it necessitates the use of
promises internally to allow parallel evaluation of the resource plan,
letting dataflow determine the available concurrency.
6) The program exits, and Lumi continues on its merry way. If the program
fails, the RunResponse will include information about the failure.
Due to (5), all properties on resources are now instances of a new
Property<T> type. A Property<T> is just a thin wrapper over a T, but it
encodes the special properties of Lumi resource properties. Namely, it
is possible to create one out of a T, other Property<T>, Promise<T>, or
to freshly allocate one. In all cases, the Property<T> does not "settle"
until its final state is known. This cannot occur before the deployment
actually completes, and so in general it's not safe to depend on concrete
resolutions of values (unlike ordinary Promise<T>s which are usually
expected to resolve). As a result, all derived computations are meant to
use the `then` function (as in `someValue.then(v => v+x)`).
Although this change includes tests that may be run in isolation to test
the various RPC interactions, we are nowhere near finished. The remaining
work primarily boils down to three things:
1) Wiring all of this up to the Lumi code.
2) Fixing the handful of known loose ends required to make this work,
primarily around the serialization of properties (waiting on
unresolved ones, serializing assets properly, etc).
3) Implementing lambda closure serialization as a native extension.
This ongoing work is part of pulumi/pulumi-fabric#311.
2017-08-26 19:07:54 +00:00
|
|
|
public readonly name: string;
|
|
|
|
|
2018-08-02 22:27:37 +00:00
|
|
|
constructor(name?: string) {
|
|
|
|
if (name === undefined) {
|
|
|
|
name = getProject();
|
|
|
|
}
|
|
|
|
|
2018-03-02 19:36:07 +00:00
|
|
|
if (name.endsWith(":config")) {
|
2018-07-31 15:37:46 +00:00
|
|
|
name = name.replace(/:config$/, "");
|
2018-03-02 19:36:07 +00:00
|
|
|
}
|
|
|
|
|
Implement initial Lumi-as-a-library
This is the initial step towards redefining Lumi as a library that runs
atop vanilla Node.js/V8, rather than as its own runtime.
This change is woefully incomplete but this includes some of the more
stable pieces of my current work-in-progress.
The new structure is that within the sdk/ directory we will have a client
library per language. This client library contains the object model for
Lumi (resources, properties, assets, config, etc), in addition to the
"language runtime host" components required to interoperate with the
Lumi resource monitor. This resource monitor is effectively what we call
"Lumi" today, in that it's the thing orchestrating plans and deployments.
Inside the sdk/ directory, you will find nodejs/, the Node.js client
library, alongside proto/, the definitions for RPC interop between the
different pieces of the system. This includes existing RPC definitions
for resource providers, etc., in addition to the new ones for hosting
different language runtimes from within Lumi.
These new interfaces are surprisingly simple. There is effectively a
bidirectional RPC channel between the Lumi resource monitor, represented
by the lumirpc.ResourceMonitor interface, and each language runtime,
represented by the lumirpc.LanguageRuntime interface.
The overall orchestration goes as follows:
1) Lumi decides it needs to run a program written in language X, so
it dynamically loads the language runtime plugin for language X.
2) Lumi passes that runtime a loopback address to its ResourceMonitor
service, while language X will publish a connection back to its
LanguageRuntime service, which Lumi will talk to.
3) Lumi then invokes LanguageRuntime.Run, passing information like
the desired working directory, program name, arguments, and optional
configuration variables to make available to the program.
4) The language X runtime receives this, unpacks it and sets up the
necessary context, and then invokes the program. The program then
calls into Lumi object model abstractions that internally communicate
back to Lumi using the ResourceMonitor interface.
5) The key here is ResourceMonitor.NewResource, which Lumi uses to
serialize state about newly allocated resources. Lumi receives these
and registers them as part of the plan, doing the usual diffing, etc.,
to decide how to proceed. This interface is perhaps one of the
most subtle parts of the new design, as it necessitates the use of
promises internally to allow parallel evaluation of the resource plan,
letting dataflow determine the available concurrency.
6) The program exits, and Lumi continues on its merry way. If the program
fails, the RunResponse will include information about the failure.
Due to (5), all properties on resources are now instances of a new
Property<T> type. A Property<T> is just a thin wrapper over a T, but it
encodes the special properties of Lumi resource properties. Namely, it
is possible to create one out of a T, other Property<T>, Promise<T>, or
to freshly allocate one. In all cases, the Property<T> does not "settle"
until its final state is known. This cannot occur before the deployment
actually completes, and so in general it's not safe to depend on concrete
resolutions of values (unlike ordinary Promise<T>s which are usually
expected to resolve). As a result, all derived computations are meant to
use the `then` function (as in `someValue.then(v => v+x)`).
Although this change includes tests that may be run in isolation to test
the various RPC interactions, we are nowhere near finished. The remaining
work primarily boils down to three things:
1) Wiring all of this up to the Lumi code.
2) Fixing the handful of known loose ends required to make this work,
primarily around the serialization of properties (waiting on
unresolved ones, serializing assets properly, etc).
3) Implementing lambda closure serialization as a native extension.
This ongoing work is part of pulumi/pulumi-fabric#311.
2017-08-26 19:07:54 +00:00
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
2017-09-22 01:15:29 +00:00
|
|
|
/**
|
|
|
|
* get loads an optional configuration value by its key, or undefined if it doesn't exist.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
2018-08-29 01:05:24 +00:00
|
|
|
* @param opts An options bag to constrain legal values.
|
2017-09-22 01:15:29 +00:00
|
|
|
*/
|
2023-04-28 22:27:10 +00:00
|
|
|
private getImpl<K extends string = string>(
|
|
|
|
key: string,
|
|
|
|
opts?: StringConfigOptions<K>,
|
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): K | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const fullKey = this.fullKey(key);
|
|
|
|
const v: string | undefined = getConfig(fullKey);
|
2018-08-29 01:05:24 +00:00
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
2021-05-24 23:06:27 +00:00
|
|
|
// TODO[pulumi/pulumi#7127]: Re-enable the warning.
|
|
|
|
// Temporarily disabling the new warning.
|
|
|
|
// if (use && insteadOf && isConfigSecret(fullKey)) {
|
|
|
|
// log.warn(`Configuration '${fullKey}' value is a secret; ` +
|
|
|
|
// `use \`${use.name}\` instead of \`${insteadOf.name}\``);
|
|
|
|
// }
|
2018-08-29 01:05:24 +00:00
|
|
|
if (opts) {
|
2019-03-20 18:52:44 +00:00
|
|
|
// SAFETY: if allowedValues != null, verifying v ∈ K[]
|
|
|
|
if (opts.allowedValues !== undefined && opts.allowedValues.indexOf(v as any) === -1) {
|
2021-05-18 16:48:08 +00:00
|
|
|
throw new ConfigEnumError(fullKey, v, opts.allowedValues);
|
2018-08-29 01:05:24 +00:00
|
|
|
} else if (opts.minLength !== undefined && v.length < opts.minLength) {
|
2021-05-18 16:48:08 +00:00
|
|
|
throw new ConfigRangeError(fullKey, v, opts.minLength, undefined);
|
2018-08-29 01:05:24 +00:00
|
|
|
} else if (opts.maxLength !== undefined && v.length > opts.maxLength) {
|
2021-05-18 16:48:08 +00:00
|
|
|
throw new ConfigRangeError(fullKey, v, undefined, opts.maxLength);
|
2018-08-29 01:05:24 +00:00
|
|
|
} else if (opts.pattern !== undefined) {
|
|
|
|
let pattern = opts.pattern;
|
|
|
|
if (typeof pattern === "string") {
|
|
|
|
pattern = new RegExp(pattern);
|
|
|
|
}
|
|
|
|
if (!pattern.test(v)) {
|
2021-05-18 16:48:08 +00:00
|
|
|
throw new ConfigPatternError(fullKey, v, pattern);
|
2018-08-29 01:05:24 +00:00
|
|
|
}
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-20 18:52:44 +00:00
|
|
|
// SAFETY:
|
|
|
|
// allowedValues != null ⇒ v ∈ K[]
|
|
|
|
// allowedValues == null ⇒ K = string & v : string
|
|
|
|
return v as K;
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 16:48:08 +00:00
|
|
|
/**
|
|
|
|
* get loads an optional configuration value by its key, or undefined if it doesn't exist.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
* @param opts An options bag to constrain legal values.
|
|
|
|
*/
|
|
|
|
public get<K extends string = string>(key: string, opts?: StringConfigOptions<K>): K | undefined {
|
|
|
|
return this.getImpl(key, opts, this.getSecret, this.get);
|
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
|
|
|
* getSecret loads an optional configuration value by its key, marking it as a secret, or undefined if it
|
|
|
|
* doesn't exist.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
* @param opts An options bag to constrain legal values.
|
|
|
|
*/
|
|
|
|
public getSecret<K extends string = string>(key: string, opts?: StringConfigOptions<K>): Output<K> | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v = this.getImpl(key, opts);
|
2019-05-10 07:06:10 +00:00
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeSecret(v);
|
|
|
|
}
|
|
|
|
|
2023-04-28 22:27:10 +00:00
|
|
|
private getBooleanImpl(
|
|
|
|
key: string,
|
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): boolean | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v: string | undefined = this.getImpl(key, undefined, use, insteadOf);
|
2017-09-01 00:57:49 +00:00
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
|
|
|
} else if (v === "true") {
|
|
|
|
return true;
|
|
|
|
} else if (v === "false") {
|
|
|
|
return false;
|
|
|
|
}
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
throw new ConfigTypeError(this.fullKey(key), v, "boolean");
|
2017-09-01 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 16:48:08 +00:00
|
|
|
/**
|
|
|
|
* getBoolean loads an optional configuration value, as a boolean, by its key, or undefined if it doesn't exist.
|
|
|
|
* If the configuration value isn't a legal boolean, this function will throw an error.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
|
|
|
public getBoolean(key: string): boolean | undefined {
|
|
|
|
return this.getBooleanImpl(key, this.getSecretBoolean, this.getBoolean);
|
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
|
|
|
* getSecretBoolean loads an optional configuration value, as a boolean, by its key, making it as a secret
|
|
|
|
* or undefined if it doesn't exist. If the configuration value isn't a legal boolean, this function will
|
|
|
|
* throw an error.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
|
|
|
public getSecretBoolean(key: string): Output<boolean> | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v = this.getBooleanImpl(key);
|
2019-05-10 07:06:10 +00:00
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeSecret(v);
|
|
|
|
}
|
|
|
|
|
2023-04-28 22:27:10 +00:00
|
|
|
private getNumberImpl(
|
|
|
|
key: string,
|
|
|
|
opts?: NumberConfigOptions,
|
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): number | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v: string | undefined = this.getImpl(key, undefined, use, insteadOf);
|
2017-09-01 00:57:49 +00:00
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2017-10-10 21:50:55 +00:00
|
|
|
const f: number = parseFloat(v);
|
2017-09-01 00:57:49 +00:00
|
|
|
if (isNaN(f)) {
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
throw new ConfigTypeError(this.fullKey(key), v, "number");
|
2017-09-01 00:57:49 +00:00
|
|
|
}
|
2018-08-29 01:05:24 +00:00
|
|
|
if (opts) {
|
|
|
|
if (opts.min !== undefined && f < opts.min) {
|
|
|
|
throw new ConfigRangeError(this.fullKey(key), f, opts.min, undefined);
|
|
|
|
} else if (opts.max !== undefined && f > opts.max) {
|
|
|
|
throw new ConfigRangeError(this.fullKey(key), f, undefined, opts.max);
|
|
|
|
}
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
2018-08-29 01:05:24 +00:00
|
|
|
return f;
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 16:48:08 +00:00
|
|
|
/**
|
|
|
|
* getNumber loads an optional configuration value, as a number, by its key, or undefined if it doesn't exist.
|
|
|
|
* If the configuration value isn't a legal number, this function will throw an error.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
* @param opts An options bag to constrain legal values.
|
|
|
|
*/
|
|
|
|
public getNumber(key: string, opts?: NumberConfigOptions): number | undefined {
|
|
|
|
return this.getNumberImpl(key, opts, this.getSecretNumber, this.getNumber);
|
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
|
|
|
* getSecretNumber loads an optional configuration value, as a number, by its key, marking it as a secret
|
|
|
|
* or undefined if it doesn't exist.
|
|
|
|
* If the configuration value isn't a legal number, this function will throw an error.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
* @param opts An options bag to constrain legal values.
|
|
|
|
*/
|
|
|
|
public getSecretNumber(key: string, opts?: NumberConfigOptions): Output<number> | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v = this.getNumberImpl(key, opts);
|
2019-05-10 07:06:10 +00:00
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeSecret(v);
|
|
|
|
}
|
|
|
|
|
2023-04-28 22:27:10 +00:00
|
|
|
private getObjectImpl<T>(
|
|
|
|
key: string,
|
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): T | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v: string | undefined = this.getImpl(key, undefined, use, insteadOf);
|
2017-09-01 00:57:49 +00:00
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2017-09-04 15:30:39 +00:00
|
|
|
try {
|
|
|
|
return <T>JSON.parse(v);
|
2023-04-28 22:27:10 +00:00
|
|
|
} catch (err) {
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
throw new ConfigTypeError(this.fullKey(key), v, "JSON object");
|
2017-09-04 15:30:39 +00:00
|
|
|
}
|
2017-09-01 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 16:48:08 +00:00
|
|
|
/**
|
|
|
|
* getObject loads an optional configuration value, as an object, by its key, or undefined if it doesn't exist.
|
|
|
|
* This routine simply JSON parses and doesn't validate the shape of the contents.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
|
|
|
public getObject<T>(key: string): T | undefined {
|
|
|
|
return this.getObjectImpl<T>(key, this.getSecretObject, this.getObject);
|
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
|
|
|
* getSecretObject loads an optional configuration value, as an object, by its key, marking it as a secret
|
|
|
|
* or undefined if it doesn't exist.
|
|
|
|
* This routine simply JSON parses and doesn't validate the shape of the contents.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
|
|
|
public getSecretObject<T>(key: string): Output<T> | undefined {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v = this.getObjectImpl<T>(key);
|
2019-05-10 07:06:10 +00:00
|
|
|
|
|
|
|
if (v === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeSecret<T>(v);
|
|
|
|
}
|
|
|
|
|
2023-04-28 22:27:10 +00:00
|
|
|
private requireImpl<K extends string = string>(
|
|
|
|
key: string,
|
2023-06-22 08:45:24 +00:00
|
|
|
secret: boolean,
|
2023-04-28 22:27:10 +00:00
|
|
|
opts?: StringConfigOptions<K>,
|
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): K {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v: K | undefined = this.getImpl(key, opts, use, insteadOf);
|
|
|
|
if (v === undefined) {
|
2023-06-22 08:45:24 +00:00
|
|
|
throw new ConfigMissingError(this.fullKey(key), secret);
|
2021-05-18 16:48:08 +00:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-09-22 01:15:29 +00:00
|
|
|
/**
|
|
|
|
* require loads a configuration value by its given key. If it doesn't exist, an error is thrown.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
2018-08-29 01:05:24 +00:00
|
|
|
* @param opts An options bag to constrain legal values.
|
2017-09-22 01:15:29 +00:00
|
|
|
*/
|
2019-03-20 18:52:44 +00:00
|
|
|
public require<K extends string = string>(key: string, opts?: StringConfigOptions<K>): K {
|
2023-06-22 08:45:24 +00:00
|
|
|
return this.requireImpl(key, false, opts, this.requireSecret, this.require);
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
2021-06-04 23:40:28 +00:00
|
|
|
* require loads a configuration value by its given key, marking it as a secret. If it doesn't exist, an error
|
2019-05-10 07:06:10 +00:00
|
|
|
* is thrown.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
* @param opts An options bag to constrain legal values.
|
|
|
|
*/
|
|
|
|
public requireSecret<K extends string = string>(key: string, opts?: StringConfigOptions<K>): Output<K> {
|
2023-06-22 08:45:24 +00:00
|
|
|
return makeSecret(this.requireImpl(key, true, opts));
|
2021-05-18 16:48:08 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 22:27:10 +00:00
|
|
|
private requireBooleanImpl(
|
|
|
|
key: string,
|
2023-06-22 08:45:24 +00:00
|
|
|
secret: boolean,
|
2023-04-28 22:27:10 +00:00
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): boolean {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v: boolean | undefined = this.getBooleanImpl(key, use, insteadOf);
|
|
|
|
if (v === undefined) {
|
2023-06-22 08:45:24 +00:00
|
|
|
throw new ConfigMissingError(this.fullKey(key), secret);
|
2021-05-18 16:48:08 +00:00
|
|
|
}
|
|
|
|
return v;
|
2019-05-10 07:06:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 01:15:29 +00:00
|
|
|
/**
|
|
|
|
* requireBoolean loads a configuration value, as a boolean, by its given key. If it doesn't exist, or the
|
|
|
|
* configuration value is not a legal boolean, an error is thrown.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
2017-09-01 00:57:49 +00:00
|
|
|
public requireBoolean(key: string): boolean {
|
2023-06-22 08:45:24 +00:00
|
|
|
return this.requireBooleanImpl(key, false, this.requireSecretBoolean, this.requireBoolean);
|
2017-09-01 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
|
|
|
* requireSecretBoolean loads a configuration value, as a boolean, by its given key, marking it as a secret.
|
|
|
|
* If it doesn't exist, or the configuration value is not a legal boolean, an error is thrown.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
|
|
|
public requireSecretBoolean(key: string): Output<boolean> {
|
2023-06-22 08:45:24 +00:00
|
|
|
return makeSecret(this.requireBooleanImpl(key, true));
|
2021-05-18 16:48:08 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 22:27:10 +00:00
|
|
|
private requireNumberImpl(
|
|
|
|
key: string,
|
2023-06-22 08:45:24 +00:00
|
|
|
secret: boolean,
|
2023-04-28 22:27:10 +00:00
|
|
|
opts?: NumberConfigOptions,
|
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): number {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v: number | undefined = this.getNumberImpl(key, opts, use, insteadOf);
|
|
|
|
if (v === undefined) {
|
2023-06-22 08:45:24 +00:00
|
|
|
throw new ConfigMissingError(this.fullKey(key), secret);
|
2021-05-18 16:48:08 +00:00
|
|
|
}
|
|
|
|
return v;
|
2019-05-10 07:06:10 +00:00
|
|
|
}
|
|
|
|
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
/**
|
2018-08-29 18:29:18 +00:00
|
|
|
* requireNumber loads a configuration value, as a number, by its given key. If it doesn't exist, or the
|
2017-09-22 01:15:29 +00:00
|
|
|
* configuration value is not a legal number, an error is thrown.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
2018-08-29 01:05:24 +00:00
|
|
|
* @param opts An options bag to constrain legal values.
|
2017-09-22 01:15:29 +00:00
|
|
|
*/
|
2018-08-29 01:05:24 +00:00
|
|
|
public requireNumber(key: string, opts?: NumberConfigOptions): number {
|
2023-06-22 08:45:24 +00:00
|
|
|
return this.requireNumberImpl(key, false, opts, this.requireSecretNumber, this.requireNumber);
|
2017-09-01 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
|
|
|
* requireSecretNumber loads a configuration value, as a number, by its given key, marking it as a secret.
|
|
|
|
* If it doesn't exist, or the configuration value is not a legal number, an error is thrown.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
* @param opts An options bag to constrain legal values.
|
|
|
|
*/
|
|
|
|
public requireSecretNumber(key: string, opts?: NumberConfigOptions): Output<number> {
|
2023-06-22 08:45:24 +00:00
|
|
|
return makeSecret(this.requireNumberImpl(key, true, opts));
|
2021-05-18 16:48:08 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 08:45:24 +00:00
|
|
|
private requireObjectImpl<T>(
|
|
|
|
key: string,
|
|
|
|
secret: boolean,
|
|
|
|
use?: (...args: any[]) => any,
|
|
|
|
insteadOf?: (...args: any[]) => any,
|
|
|
|
): T {
|
2021-05-18 16:48:08 +00:00
|
|
|
const v: T | undefined = this.getObjectImpl<T>(key, use, insteadOf);
|
|
|
|
if (v === undefined) {
|
2023-06-22 08:45:24 +00:00
|
|
|
throw new ConfigMissingError(this.fullKey(key), secret);
|
2021-05-18 16:48:08 +00:00
|
|
|
}
|
|
|
|
return v;
|
2019-05-10 07:06:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 01:15:29 +00:00
|
|
|
/**
|
2018-09-21 14:58:14 +00:00
|
|
|
* requireObject loads a configuration value as a JSON string and deserializes the JSON into a JavaScript object. If
|
|
|
|
* it doesn't exist, or the configuration value is not a legal JSON string, an error is thrown.
|
2017-09-22 01:15:29 +00:00
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
2017-09-01 00:57:49 +00:00
|
|
|
public requireObject<T>(key: string): T {
|
2023-06-22 08:45:24 +00:00
|
|
|
return this.requireObjectImpl<T>(key, false, this.requireSecretObject, this.requireObject);
|
2017-09-01 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 07:06:10 +00:00
|
|
|
/**
|
|
|
|
* requireSecretObject loads a configuration value as a JSON string and deserializes the JSON into a JavaScript
|
|
|
|
* object, marking it as a secret. If it doesn't exist, or the configuration value is not a legal JSON
|
|
|
|
* string, an error is thrown.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
|
|
|
public requireSecretObject<T>(key: string): Output<T> {
|
2023-06-22 08:45:24 +00:00
|
|
|
return makeSecret(this.requireObjectImpl<T>(key, true));
|
2019-05-10 07:06:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 01:15:29 +00:00
|
|
|
/**
|
|
|
|
* fullKey turns a simple configuration key into a fully resolved one, by prepending the bag's name.
|
|
|
|
*
|
|
|
|
* @param key The key to lookup.
|
|
|
|
*/
|
Implement initial Lumi-as-a-library
This is the initial step towards redefining Lumi as a library that runs
atop vanilla Node.js/V8, rather than as its own runtime.
This change is woefully incomplete but this includes some of the more
stable pieces of my current work-in-progress.
The new structure is that within the sdk/ directory we will have a client
library per language. This client library contains the object model for
Lumi (resources, properties, assets, config, etc), in addition to the
"language runtime host" components required to interoperate with the
Lumi resource monitor. This resource monitor is effectively what we call
"Lumi" today, in that it's the thing orchestrating plans and deployments.
Inside the sdk/ directory, you will find nodejs/, the Node.js client
library, alongside proto/, the definitions for RPC interop between the
different pieces of the system. This includes existing RPC definitions
for resource providers, etc., in addition to the new ones for hosting
different language runtimes from within Lumi.
These new interfaces are surprisingly simple. There is effectively a
bidirectional RPC channel between the Lumi resource monitor, represented
by the lumirpc.ResourceMonitor interface, and each language runtime,
represented by the lumirpc.LanguageRuntime interface.
The overall orchestration goes as follows:
1) Lumi decides it needs to run a program written in language X, so
it dynamically loads the language runtime plugin for language X.
2) Lumi passes that runtime a loopback address to its ResourceMonitor
service, while language X will publish a connection back to its
LanguageRuntime service, which Lumi will talk to.
3) Lumi then invokes LanguageRuntime.Run, passing information like
the desired working directory, program name, arguments, and optional
configuration variables to make available to the program.
4) The language X runtime receives this, unpacks it and sets up the
necessary context, and then invokes the program. The program then
calls into Lumi object model abstractions that internally communicate
back to Lumi using the ResourceMonitor interface.
5) The key here is ResourceMonitor.NewResource, which Lumi uses to
serialize state about newly allocated resources. Lumi receives these
and registers them as part of the plan, doing the usual diffing, etc.,
to decide how to proceed. This interface is perhaps one of the
most subtle parts of the new design, as it necessitates the use of
promises internally to allow parallel evaluation of the resource plan,
letting dataflow determine the available concurrency.
6) The program exits, and Lumi continues on its merry way. If the program
fails, the RunResponse will include information about the failure.
Due to (5), all properties on resources are now instances of a new
Property<T> type. A Property<T> is just a thin wrapper over a T, but it
encodes the special properties of Lumi resource properties. Namely, it
is possible to create one out of a T, other Property<T>, Promise<T>, or
to freshly allocate one. In all cases, the Property<T> does not "settle"
until its final state is known. This cannot occur before the deployment
actually completes, and so in general it's not safe to depend on concrete
resolutions of values (unlike ordinary Promise<T>s which are usually
expected to resolve). As a result, all derived computations are meant to
use the `then` function (as in `someValue.then(v => v+x)`).
Although this change includes tests that may be run in isolation to test
the various RPC interactions, we are nowhere near finished. The remaining
work primarily boils down to three things:
1) Wiring all of this up to the Lumi code.
2) Fixing the handful of known loose ends required to make this work,
primarily around the serialization of properties (waiting on
unresolved ones, serializing assets properly, etc).
3) Implementing lambda closure serialization as a native extension.
This ongoing work is part of pulumi/pulumi-fabric#311.
2017-08-26 19:07:54 +00:00
|
|
|
private fullKey(key: string): string {
|
|
|
|
return `${this.name}:${key}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 01:05:24 +00:00
|
|
|
/**
|
|
|
|
* StringConfigOptions may be used to constrain the set of legal values a string config value may contain.
|
|
|
|
*/
|
2019-12-09 22:48:54 +00:00
|
|
|
export interface StringConfigOptions<K extends string = string> {
|
2018-08-29 01:05:24 +00:00
|
|
|
/**
|
|
|
|
* The legal enum values. If it does not match, a ConfigEnumError is thrown.
|
|
|
|
*/
|
2019-03-20 18:52:44 +00:00
|
|
|
allowedValues?: K[];
|
2018-08-29 01:05:24 +00:00
|
|
|
/**
|
|
|
|
* The minimum string length. If the string is not this long, a ConfigRangeError is thrown.
|
|
|
|
*/
|
|
|
|
minLength?: number;
|
|
|
|
/**
|
|
|
|
* The maximum string length. If the string is longer than this, a ConfigRangeError is thrown.
|
|
|
|
*/
|
|
|
|
maxLength?: number;
|
|
|
|
/**
|
|
|
|
* A regular expression the string must match. If it does not match, a ConfigPatternError is thrown.
|
|
|
|
*/
|
|
|
|
pattern?: string | RegExp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NumberConfigOptions may be used to constrain the set of legal values a number config value may contain.
|
|
|
|
*/
|
2019-12-09 22:48:54 +00:00
|
|
|
export interface NumberConfigOptions {
|
2018-08-29 01:05:24 +00:00
|
|
|
/**
|
|
|
|
* The minimum number value, inclusive. If the number is less than this, a ConfigRangeError is thrown.
|
|
|
|
*/
|
|
|
|
min?: number;
|
|
|
|
/**
|
|
|
|
* The maximum number value, inclusive. If the number is greater than this, a ConfigRangeError is thrown.
|
|
|
|
*/
|
|
|
|
max?: number;
|
|
|
|
}
|
|
|
|
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
/**
|
|
|
|
* ConfigTypeError is used when a configuration value is of the wrong type.
|
|
|
|
*/
|
|
|
|
class ConfigTypeError extends RunError {
|
|
|
|
constructor(key: string, v: any, expectedType: string) {
|
|
|
|
super(`Configuration '${key}' value '${v}' is not a valid ${expectedType}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
/**
|
|
|
|
* ConfigEnumError is used when a configuration value isn't a correct enum value.
|
|
|
|
*/
|
|
|
|
class ConfigEnumError extends RunError {
|
|
|
|
constructor(key: string, v: any, values: any[]) {
|
|
|
|
super(`Configuration '${key}' value '${v}' is not a legal enum value (${JSON.stringify(values)})`);
|
2021-08-10 18:31:59 +00:00
|
|
|
}
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ConfigRangeError is used when a configuration value is outside of the range of legal sizes.
|
|
|
|
*/
|
|
|
|
class ConfigRangeError extends RunError {
|
|
|
|
constructor(key: string, v: any, min: number | undefined, max: number | undefined) {
|
|
|
|
let range: string;
|
|
|
|
if (max === undefined) {
|
|
|
|
range = `min ${min}`;
|
|
|
|
} else if (min === undefined) {
|
|
|
|
range = `max ${max}`;
|
|
|
|
} else {
|
|
|
|
range = `${min}-${max}`;
|
|
|
|
}
|
|
|
|
if (typeof v === "string") {
|
|
|
|
range += " chars";
|
|
|
|
}
|
|
|
|
super(`Configuration '${key}' value '${v}' is outside of the legal range (${range}, inclusive)`);
|
2021-08-10 18:31:59 +00:00
|
|
|
}
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ConfigPatternError is used when a configuration value does not match the given regular expression.
|
|
|
|
*/
|
|
|
|
class ConfigPatternError extends RunError {
|
|
|
|
constructor(key: string, v: string, regexp: RegExp) {
|
|
|
|
super(`Configuration '${key}' value '${v}' does not match the regular expression ${regexp.toString()}`);
|
2021-08-10 18:31:59 +00:00
|
|
|
}
|
Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.
In this change, I've added a number of config helpers for these cases:
For string enums:
getEnum(key: string, values: string[]): string | undefined;
requireEnum(key: string: values: string[]): string;
For min/max strlen:
getMinMax(key: string, min: number, max: number): string | undefined;
requireMinMax(key: string, min: number, max: number): string;
For regex patterns:
getPattern(key: string, regexp: string | RegExp): string | undefined;
requirePattern(key: string, regexp: string | RegExp): string;
For min/max strlen _and_ regex patterns:
getMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string | undefined;
requireMinMaxPattern(key: string, min: number, max: number,
regexp: string | RegExp): string;
For min/max numbers:
getNumberMinMax(key: string, min: number, max: number): number | undefined;
requireNumberMinMax(key: string, min: number, max: number): number;
Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.
This fixes pulumi/pulumi#1671.
2018-08-28 20:14:27 +00:00
|
|
|
}
|
|
|
|
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
/**
|
|
|
|
* ConfigMissingError is used when a configuration value is completely missing.
|
|
|
|
*/
|
|
|
|
class ConfigMissingError extends RunError {
|
2024-06-24 11:14:56 +00:00
|
|
|
constructor(
|
|
|
|
public key: string,
|
|
|
|
public secret: boolean,
|
|
|
|
) {
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
super(
|
|
|
|
`Missing required configuration variable '${key}'\n` +
|
2023-06-22 08:45:24 +00:00
|
|
|
`\tplease set a value using the command \`pulumi config set${
|
|
|
|
secret ? " --secret " : " "
|
|
|
|
}${key} <value>\``,
|
Improve output formatting
This change improves our output formatting by generally adding
fewer prefixes. As shown in pulumi/pulumi#359, we were being
excessively verbose in many places, including prefixing every
console.out with "langhost[nodejs].stdout: ", displaying full
stack traces for simple errors like missing configuration, etc.
Overall, this change includes the following:
* Don't prefix stdout and stderr output from the program, other
than the standard "info:" prefix. I experimented with various
schemes here, but they all felt gratuitous. Simply emitting
the output seems fine, especially as it's closer to what would
happen if you just ran the program under node.
* Do NOT make writes to stderr fail the plan/deploy. Previously
we assumed that any console.errors, for instance, meant that
the overall program should fail. This simply isn't how stderr
is treated generally and meant you couldn't use certain
logging techniques and libraries, among other things.
* Do make sure that stderr writes in the program end up going to
stderr in the Pulumi CLI output, however, so that redirection
works as it should. This required a new Infoerr log level.
* Make a small fix to the planning logic so we don't attempt to
print the summary if an error occurs.
* Finally, add a new error type, RunError, that when thrown and
uncaught does not result in a full stack trace being printed.
Anyone can use this, however, we currently use it for config
errors so that we can terminate with a pretty error message,
rather than the monstrosity shown in pulumi/pulumi#359.
2017-09-23 12:20:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|