[PATCH] Fix stack settings serialization

This commit is contained in:
Komal Ali 2021-04-15 19:05:12 +01:00 committed by stack72
parent 5db7c9e277
commit 87906ca395
3 changed files with 54 additions and 135 deletions

View file

@ -1,118 +1,4 @@
### Breaking
- [automation/dotnet] Rename (Get,Set,Remove)Config(Value)
[#6731](https://github.com/pulumi/pulumi/pull/6731)
The following methods on Workspace and WorkspaceStack classes have
been renamed. Please update your code (before -> after):
* GetConfigValue -> GetConfig
* SetConfigValue -> SetConfig
* RemoveConfigValue -> RemoveConfig
* GetConfig -> GetAllConfig
* SetConfig -> SetAllConfig
* RemoveConfig -> RemoveAllConfig
This change was made to align with the other Pulumi language SDKs.
### Improvements
- [cli] Add option to print absolute rather than relative dates in stack history
[#6742](https://github.com/pulumi/pulumi/pull/6742)
Example:
```bash
pulumi stack history --full-dates
```
- [cli] Enable absolute and relative parent paths for pulumi main
[#6734](https://github.com/pulumi/pulumi/pull/6734)
- [sdk/dotnet] Thread-safe concurrency-friendly global state
[#6139](https://github.com/pulumi/pulumi/pull/6139)
- [tooling] Update pulumi python docker image to python 3.9
[#6706](https://github.com/pulumi/pulumi/pull/6706)
- [sdk/nodejs] Add program side caching for dynamic provider serialization behind env var
[#6673](https://github.com/pulumi/pulumi/pull/6673)
- [sdk/nodejs] Allow prompt values in `construct` for multi-lang components.
[#6522](https://github.com/pulumi/pulumi/pull/6522)
- [automation/dotnet] Allow null environment variables
[#6687](https://github.com/pulumi/pulumi/pull/6687)
- [automation/dotnet] Expose WorkspaceStack.GetOutputsAsync
[#6699](https://github.com/pulumi/pulumi/pull/6699)
Example:
```csharp
var stack = await WorkspaceStack.CreateAsync(stackName, workspace);
await stack.SetConfigAsync(config);
var initialOutputs = await stack.GetOutputsAsync();
```
- [automation/dotnet] Implement (Import,Export)StackAsync methods on LocalWorkspace and WorkspaceStack and expose StackDeployment helper class.
[#6728](https://github.com/pulumi/pulumi/pull/6728)
Example:
```csharp
var stack = await WorkspaceStack.CreateAsync(stackName, workspace);
var upResult = await stack.UpAsync();
deployment = await workspace.ExportStackAsync(stackName);
```
- [automation/dotnet] Implement CancelAsync method on WorkspaceStack
[#6729](https://github.com/pulumi/pulumi/pull/6729)
Example:
```csharp
var stack = await WorkspaceStack.CreateAsync(stackName, workspace);
var cancelTask = stack.CancelAsync();
```
- [automation/python] - Expose structured logging for Stack.up/preview/refresh/destroy.
[#6527](https://github.com/pulumi/pulumi/pull/6527)
You can now pass in an `on_event` callback function as a keyword arg to `up`, `preview`, `refresh`
and `destroy` to process streaming json events defined in `automation/events.py`
Example:
```python
stack.up(on_event=print)
```
### Bug Fixes
- [cli] Handle non-existent creds file in `pulumi logout --all`
[#6741](https://github.com/pulumi/pulumi/pull/6741)
- [automation/nodejs] Do not run the promise leak checker if an inline program has errored.
[#6758](https://github.com/pulumi/pulumi/pull/6758)
- [sdk/nodejs] Explicitly create event log file for NodeJS Automation API.
[#6730](https://github.com/pulumi/pulumi/pull/6730)
- [sdk/nodejs] Fix error handling for failed logging statements
[#6714](https://github.com/pulumi/pulumi/pull/6714)
- [sdk/nodejs] Fix `Construct` to wait for child resources of a multi-lang components to be created.
[#6452](https://github.com/pulumi/pulumi/pull/6452)
- [sdk/python] Fix serialization bug if output contains 'items' property.
[#6701](https://github.com/pulumi/pulumi/pull/6701)
- [automation] Set default value for 'main' for inline programs to support relative paths, assets, and closure serialization.
[#6743](https://github.com/pulumi/pulumi/pull/6743)
- [automation/dotnet] Environment variable value type is now nullable.
[#6520](https://github.com/pulumi/pulumi/pull/6520)
- [automation/dotnet] Fix GetConfigValueAsync failing to deserialize
[#6698](https://github.com/pulumi/pulumi/pull/6698)
- [automation] Fix (de)serialization of StackSettings in .NET, Node, and Python.
[#6752](https://github.com/pulumi/pulumi/pull/6752)
[#6754](https://github.com/pulumi/pulumi/pull/6754)
[#6749](https://github.com/pulumi/pulumi/pull/6749)
- [automation/python] - Fix serialization bug in `StackSettings`
[#6776](https://github.com/pulumi/pulumi/pull/6776)

View file

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional, Mapping, Any, Union, Dict
from typing import Optional, Any, Dict
class StackSettingsSecureConfigValue:
@ -28,38 +28,52 @@ class StackSettings:
secrets_provider: Optional[str]
encrypted_key: Optional[str]
encryption_salt: Optional[str]
config: Optional[Mapping[str, Any]]
config: Optional[Dict[str, Any]]
def __init__(self,
secrets_provider: Optional[str] = None,
encrypted_key: Optional[str] = None,
encryption_salt: Optional[str] = None,
config: Optional[Mapping[str, Any]] = None):
config: Optional[Dict[str, Any]] = None):
self.secrets_provider = secrets_provider
self.encrypted_key = encrypted_key
self.encryption_salt = encryption_salt
if config:
stack_config: Dict[str, Union[str, StackSettingsSecureConfigValue]] = {}
for key in config:
val = config[key]
self.config = config
@classmethod
def _deserialize(cls, data: dict):
config = data.get("config")
if config is not None:
stack_config: Dict[str, Any] = {}
for key, val in config.items():
if isinstance(val, str):
stack_config[key] = val
elif "secure" in val:
stack_config[key] = StackSettingsSecureConfigValue(**val)
if len(stack_config.keys()) > 0:
self.config = stack_config
@classmethod
def _deserialize(cls, data: dict):
config = stack_config
return cls(secrets_provider=data.get("secretsprovider"),
encrypted_key=data.get("encryptedkey"),
encryption_salt=data.get("encryptionsalt"),
config=data.get("config"))
config=config)
def _serialize(self):
return {
"secretsprovider": self.secrets_provider,
"encryptedkey": self.encrypted_key,
"encryptionsalt": self.encryption_salt,
"config": self.config
}
serializable = {}
# Only add the keys that are present to avoid writing nulls to the
# Pulumi.[stack].yaml file.
if self.secrets_provider:
serializable["secretsprovider"] = self.secrets_provider
if self.encrypted_key:
serializable["encryptedkey"] = self.encrypted_key
if self.encryption_salt:
serializable["encryptionsalt"] = self.encryption_salt
if self.config:
config = {}
for key, val in self.config.items():
if isinstance(val, StackSettingsSecureConfigValue):
config[key] = {"secure": val.secure}
else:
config[key] = val
serializable["config"] = config
return serializable

View file

@ -34,6 +34,7 @@ from pulumi.x.automation import (
ProjectSettings,
StackSummary,
Stack,
StackSettings,
StackAlreadyExistsError,
fully_qualified_stack_name,
)
@ -106,6 +107,24 @@ class TestLocalWorkspace(unittest.TestCase):
self.assertEqual(settings.config["plain"], "plain")
self.assertEqual(settings.config["secure"].secure, "secret")
settings_with_no_config = StackSettings(secrets_provider="blah",
encrypted_key="thisiskey",
encryption_salt="salty")
self.assertEqual(settings_with_no_config._serialize(), {
"secretsprovider": "blah",
"encryptedkey": "thisiskey",
"encryptionsalt": "salty"
})
config = {
"cool": "sup",
"foo": {"secure": "thisisasecret"},
}
settings_with_only_config = StackSettings(config=config)
self.assertEqual(settings_with_only_config._serialize(), {
"config": config
})
def test_plugin_functions(self):
ws = LocalWorkspace()
# Install aws 3.0.0 plugin