Skip to content

Commit

Permalink
Support assets for tee content (#109)
Browse files Browse the repository at this point in the history
* Support assets for tee content

* Regen SDKs

* Actually Regen SDKs
  • Loading branch information
UnstoppableMango authored Aug 11, 2024
1 parent 7f0eb68 commit dee6a01
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 89 deletions.
15 changes: 11 additions & 4 deletions provider/pkg/provider/cmd/tee.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (

provider "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/asset"
pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1"
)

type TeeArgs struct {
CommandArgsBase

Append bool `pulumi:"append,optional"`
Content string `pulumi:"content"`
Files []string `pulumi:"files"`
Append bool `pulumi:"append,optional"`
Content asset.Asset `pulumi:"content"`
Files []string `pulumi:"files"`
}

func (o TeeArgs) Cmd() *pb.Command {
Expand All @@ -25,10 +26,16 @@ func (o TeeArgs) Cmd() *pb.Command {
args = append(args, "--append")
}

data, err := o.Content.Bytes()
if err != nil {
panic(err)
}

stdin := string(data)
return &pb.Command{
Bin: pb.Bin_BIN_TEE,
Args: append(args, o.Files...),
Stdin: &o.Content,
Stdin: &stdin,
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/dotnet/Cmd/Inputs/TeeArgsArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class TeeArgsArgs : global::Pulumi.ResourceArgs
public Input<bool>? Append { get; set; }

[Input("content", required: true)]
public Input<string> Content { get; set; } = null!;
public Input<AssetOrArchive> Content { get; set; } = null!;

[Input("files", required: true)]
private InputList<string>? _files;
Expand Down
4 changes: 2 additions & 2 deletions sdk/dotnet/Cmd/Outputs/TeeArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace UnMango.Baremetal.Cmd.Outputs
public sealed class TeeArgs
{
public readonly bool? Append;
public readonly string Content;
public readonly AssetOrArchive Content;
public readonly ImmutableArray<string> Files;

[OutputConstructor]
private TeeArgs(
bool? append,

string content,
AssetOrArchive content,

ImmutableArray<string> files)
{
Expand Down
16 changes: 8 additions & 8 deletions sdk/go/baremetal/cmd/pulumiTypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions sdk/go/baremetal/x/cmd/pulumiTypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/nodejs/types/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export namespace cmd {

export interface TeeArgsArgs {
append?: pulumi.Input<boolean>;
content: pulumi.Input<string>;
content: pulumi.Input<pulumi.asset.Asset | pulumi.asset.Archive>;
files: pulumi.Input<pulumi.Input<string>[]>;
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/nodejs/types/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export namespace cmd {

export interface TeeArgs {
append?: boolean;
content: string;
content: pulumi.asset.Asset | pulumi.asset.Archive;
files: string[];
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/python/unmango_baremetal/cmd/_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ def zstd(self, value: Optional[pulumi.Input[bool]]):
@pulumi.input_type
class TeeArgsArgs:
def __init__(__self__, *,
content: pulumi.Input[str],
content: pulumi.Input[Union[pulumi.Asset, pulumi.Archive]],
files: pulumi.Input[Sequence[pulumi.Input[str]]],
append: Optional[pulumi.Input[bool]] = None):
pulumi.set(__self__, "content", content)
Expand All @@ -1115,11 +1115,11 @@ def __init__(__self__, *,

@property
@pulumi.getter
def content(self) -> pulumi.Input[str]:
def content(self) -> pulumi.Input[Union[pulumi.Asset, pulumi.Archive]]:
return pulumi.get(self, "content")

@content.setter
def content(self, value: pulumi.Input[str]):
def content(self, value: pulumi.Input[Union[pulumi.Asset, pulumi.Archive]]):
pulumi.set(self, "content", value)

@property
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/unmango_baremetal/cmd/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def zstd(self) -> Optional[bool]:
@pulumi.output_type
class TeeArgs(dict):
def __init__(__self__, *,
content: str,
content: Union[pulumi.Asset, pulumi.Archive],
files: Sequence[str],
append: Optional[bool] = None):
pulumi.set(__self__, "content", content)
Expand All @@ -886,7 +886,7 @@ def __init__(__self__, *,

@property
@pulumi.getter
def content(self) -> str:
def content(self) -> Union[pulumi.Asset, pulumi.Archive]:
return pulumi.get(self, "content")

@property
Expand Down
97 changes: 38 additions & 59 deletions tests/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
p "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/integration"
pr "github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/asset"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/unmango/pulumi-baremetal/tests/util"
)
Expand Down Expand Up @@ -431,11 +432,17 @@ var _ = Describe("Command Resources", func() {
var resource tokens.Type = "baremetal:cmd:Tee"

It("should complete a full lifecycle", func(ctx context.Context) {
stdin := "Test lifecycle stdin"
newStdin := "Updated stdin"
file := containerPath("create.txt")
newFile := containerPath("update.txt")

By("creating the stdin asset")
stdin, err := asset.FromText("Test lifecycle stdin")
Expect(err).NotTo(HaveOccurred())

By("creating the updated asset")
newStdin, err := asset.FromText("Updated stdin")
Expect(err).NotTo(HaveOccurred())

run(server, integration.LifeCycleTest{
Resource: resource,
Create: integration.Operation{
Expand All @@ -447,22 +454,16 @@ var _ = Describe("Command Resources", func() {
}),
Hook: func(inputs, output pr.PropertyMap) {
Expect(output["stderr"]).To(HavePropertyValue(""))
data, err := provisioner.ReadFile(context.Background(), file)
Expect(output["stdout"]).To(HavePropertyValue(stdin.Text))
Expect(output["exitCode"]).To(HavePropertyValue(0))
Expect(output["createdFiles"].V).NotTo(BeEmpty()) // TODO: Make this better
Expect(output["movedFiles"].V).To(BeEmpty())
Expect(output["args"]).To(Equal(inputs["args"]))

data, err := provisioner.ReadFile(ctx, file)
Expect(err).NotTo(HaveOccurred())
Expect(string(data)).To(Equal(stdin))
Expect(string(data)).To(Equal(stdin.Text))
},
ExpectedOutput: pr.NewPropertyMapFromMap(map[string]interface{}{
"exitCode": 0,
"stdout": stdin,
"stderr": "",
"createdFiles": []string{file},
"movedFiles": map[string]string{},
"args": map[string]interface{}{
"append": false,
"content": stdin,
"files": []string{file},
},
}),
},
Updates: []integration.Operation{
{
Expand All @@ -473,25 +474,18 @@ var _ = Describe("Command Resources", func() {
},
}),
Hook: func(inputs, output pr.PropertyMap) {
ctx := context.Background()
Expect(output["stderr"]).To(HavePropertyValue(""))
Expect(output["stdout"]).To(HavePropertyValue(stdin.Text))
Expect(output["exitCode"]).To(HavePropertyValue(0))
Expect(output["createdFiles"].V).NotTo(BeEmpty()) // TODO: Make this better
Expect(output["movedFiles"].V).To(BeEmpty())
Expect(output["args"]).To(Equal(inputs["args"]))
Expect(provisioner).NotTo(ContainFile(ctx, file))

data, err := provisioner.ReadFile(ctx, newFile)
Expect(err).NotTo(HaveOccurred())
Expect(string(data)).To(Equal(stdin))
Expect(string(data)).To(Equal(stdin.Text))
},
ExpectedOutput: pr.NewPropertyMapFromMap(map[string]interface{}{
"exitCode": 0,
"stdout": stdin,
"stderr": "",
"createdFiles": []string{newFile},
"movedFiles": map[string]string{},
"args": map[string]interface{}{
"append": false,
"content": stdin,
"files": []string{newFile},
},
}),
},
{
Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{
Expand All @@ -502,23 +496,16 @@ var _ = Describe("Command Resources", func() {
}),
Hook: func(inputs, output pr.PropertyMap) {
Expect(output["stderr"]).To(HavePropertyValue(""))
ctx := context.Background()
Expect(output["stdout"]).To(HavePropertyValue(newStdin.Text))
Expect(output["exitCode"]).To(HavePropertyValue(0))
Expect(output["createdFiles"].V).NotTo(BeEmpty()) // TODO: Make this better
Expect(output["movedFiles"].V).To(BeEmpty())
Expect(output["args"]).To(Equal(inputs["args"]))

data, err := provisioner.ReadFile(ctx, newFile)
Expect(err).NotTo(HaveOccurred())
Expect(string(data)).To(Equal(newStdin))
Expect(string(data)).To(Equal(newStdin.Text))
},
ExpectedOutput: pr.NewPropertyMapFromMap(map[string]interface{}{
"exitCode": 0,
"stdout": newStdin,
"stderr": "",
"createdFiles": []string{newFile},
"movedFiles": map[string]string{},
"args": map[string]interface{}{
"append": false,
"content": newStdin,
"files": []string{newFile},
},
}),
},
{
Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{
Expand All @@ -529,28 +516,20 @@ var _ = Describe("Command Resources", func() {
}),
Hook: func(inputs, output pr.PropertyMap) {
Expect(output["stderr"]).To(HavePropertyValue(""))
Expect(output["stdout"]).To(HavePropertyValue(newStdin.Text))
Expect(output["exitCode"]).To(HavePropertyValue(0))
Expect(output["createdFiles"].V).To(HaveLen(2)) // TODO: Make this better
Expect(output["movedFiles"].V).To(BeEmpty())
Expect(output["args"]).To(Equal(inputs["args"]))

ctx := context.Background()
data, err := provisioner.ReadFile(ctx, file)
Expect(err).NotTo(HaveOccurred())
Expect(string(data)).To(Equal(newStdin))
Expect(string(data)).To(Equal(newStdin.Text))

data, err = provisioner.ReadFile(ctx, newFile)
Expect(err).NotTo(HaveOccurred())
Expect(string(data)).To(Equal(newStdin))
Expect(string(data)).To(Equal(newStdin.Text))
},
ExpectedOutput: pr.NewPropertyMapFromMap(map[string]interface{}{
"exitCode": 0,
"stdout": newStdin,
"stderr": "",
"createdFiles": []string{file, newFile},
"movedFiles": map[string]string{},
"args": map[string]interface{}{
"append": false,
"content": newStdin,
"files": []string{file, newFile},
},
}),
},
},
})
Expand Down

0 comments on commit dee6a01

Please sign in to comment.