diff --git a/provider/pkg/provider/cmd/args.go b/provider/pkg/provider/cmd/args.go index e555cdb6..0d438ede 100644 --- a/provider/pkg/provider/cmd/args.go +++ b/provider/pkg/provider/cmd/args.go @@ -12,7 +12,7 @@ type CommandArgs[T Builder] struct { CustomDelete []string `pulumi:"customDelete,optional"` } -func (a *CommandArgs[T]) Cmd() *pb.Command { +func (a *CommandArgs[T]) Cmd() (*pb.Command, error) { return a.Args.Cmd() } diff --git a/provider/pkg/provider/cmd/builder.go b/provider/pkg/provider/cmd/builder.go index 271d4c35..07917191 100644 --- a/provider/pkg/provider/cmd/builder.go +++ b/provider/pkg/provider/cmd/builder.go @@ -4,7 +4,7 @@ import pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1 type Builder interface { FsManipulator - Cmd() *pb.Command + Cmd() (*pb.Command, error) } type B struct { diff --git a/provider/pkg/provider/cmd/create.go b/provider/pkg/provider/cmd/create.go index 56f9096c..75fdc697 100644 --- a/provider/pkg/provider/cmd/create.go +++ b/provider/pkg/provider/cmd/create.go @@ -17,6 +17,12 @@ func (s *State[T]) Create(ctx context.Context, inputs CommandArgs[T], preview bo return nil } + command, err := inputs.Cmd() + if err != nil { + log.Errorf("Failed constructing command: %s", err) + return err + } + p, err := provisioner.FromContext(ctx) if err != nil { log.Error("failed creating provisioner") @@ -25,7 +31,7 @@ func (s *State[T]) Create(ctx context.Context, inputs CommandArgs[T], preview bo log.InfoStatus("Sending create request to provisioner") res, err := p.Create(ctx, &pb.CreateRequest{ - Command: inputs.Cmd(), + Command: command, ExpectCreated: inputs.ExpectCreated(), ExpectMoved: inputs.ExpectMoved(), }) diff --git a/provider/pkg/provider/cmd/delete.go b/provider/pkg/provider/cmd/delete.go index 86a6b7a7..59a135ea 100644 --- a/provider/pkg/provider/cmd/delete.go +++ b/provider/pkg/provider/cmd/delete.go @@ -28,19 +28,16 @@ func (s *State[T]) Delete(ctx context.Context) error { log.InfoStatus("Normal delete") } + prev, err := s.Operation() + if err != nil { + log.Errorf("Failed generating operation from state: %s", err) + return fmt.Errorf("failed to generate operation from state: %w", err) + } + log.InfoStatus("Sending delete request to provisioner") res, err := p.Delete(ctx, &pb.DeleteRequest{ - Command: command, - Previous: &pb.Operation{ - Command: s.Cmd(), - CreatedFiles: s.CreatedFiles, - MovedFiles: s.MovedFiles, - Result: &pb.Result{ - ExitCode: int32(s.ExitCode), - Stdout: s.Stdout, - Stderr: s.Stderr, - }, - }, + Command: command, + Previous: prev, }) if err != nil { return fmt.Errorf("sending delete request: %w", err) diff --git a/provider/pkg/provider/cmd/state.go b/provider/pkg/provider/cmd/state.go index c81f3a1f..4b127e48 100644 --- a/provider/pkg/provider/cmd/state.go +++ b/provider/pkg/provider/cmd/state.go @@ -1,5 +1,11 @@ package cmd +import ( + "fmt" + + pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1" +) + type State[T Builder] struct { CommandArgs[T] @@ -20,3 +26,21 @@ func (s *State[T]) Copy() State[T] { MovedFiles: s.MovedFiles, } } + +func (s *State[T]) Operation() (*pb.Operation, error) { + command, err := s.Cmd() + if err != nil { + return nil, fmt.Errorf("failed to build command from state; %w", err) + } + + return &pb.Operation{ + Command: command, + CreatedFiles: s.CreatedFiles, + MovedFiles: s.MovedFiles, + Result: &pb.Result{ + ExitCode: int32(s.ExitCode), + Stdout: s.Stdout, + Stderr: s.Stderr, + }, + }, nil +} diff --git a/provider/pkg/provider/cmd/update.go b/provider/pkg/provider/cmd/update.go index 6a15569a..f661fe88 100644 --- a/provider/pkg/provider/cmd/update.go +++ b/provider/pkg/provider/cmd/update.go @@ -34,28 +34,31 @@ func (s *State[T]) Update(ctx context.Context, inputs CommandArgs[T], preview bo return s.Copy(), fmt.Errorf("parsing custom command: %w", err) } } else { - command = inputs.Cmd() + command, err = inputs.Cmd() + if err != nil { + log.Errorf("Failed to build command from inputs: %s", err) + return s.Copy(), fmt.Errorf("failed to build command from inputs: %w", err) + } + expectCreated = inputs.ExpectCreated() expectMoved = inputs.ExpectMoved() } + prev, err := s.Operation() + if err != nil { + log.Errorf("Failed generating operation from state: %s", err) + return s.Copy(), fmt.Errorf("failed to generate operation from state: %w", err) + } + log.DebugStatus("Sending update request to provisioner") res, err := p.Update(ctx, &pb.UpdateRequest{ Command: command, ExpectCreated: expectCreated, ExpectMoved: expectMoved, - Previous: &pb.Operation{ - Command: s.Cmd(), - CreatedFiles: s.CreatedFiles, - MovedFiles: s.MovedFiles, - Result: &pb.Result{ - ExitCode: int32(s.ExitCode), - Stdout: s.Stdout, - Stderr: s.Stderr, - }, - }, + Previous: prev, }) if err != nil { + log.Errorf("Failed sending update request: %s", err) return s.Copy(), fmt.Errorf("sending update request: %w", err) } diff --git a/provider/pkg/provider/coreutils/chmod.go b/provider/pkg/provider/coreutils/chmod.go index 227df890..6973fd08 100644 --- a/provider/pkg/provider/coreutils/chmod.go +++ b/provider/pkg/provider/coreutils/chmod.go @@ -28,7 +28,7 @@ type ChmodArgs struct { } // Cmd implements CommandArgs. -func (m ChmodArgs) Cmd() *pb.Command { +func (m ChmodArgs) Cmd() (*pb.Command, error) { b := cmd.B{} b.Op(m.Changes, "--changes") b.Op(m.NoPreserveRoot, "--no-preserve-root") @@ -50,7 +50,7 @@ func (m ChmodArgs) Cmd() *pb.Command { return &pb.Command{ Bin: pb.Bin_BIN_CHMOD, Args: b.Args, - } + }, nil } var _ cmd.Builder = ChmodArgs{} diff --git a/provider/pkg/provider/coreutils/mkdir.go b/provider/pkg/provider/coreutils/mkdir.go index 6e1f0faa..983285da 100644 --- a/provider/pkg/provider/coreutils/mkdir.go +++ b/provider/pkg/provider/coreutils/mkdir.go @@ -21,7 +21,7 @@ type MkdirArgs struct { } // Cmd implements CommandArgs. -func (m MkdirArgs) Cmd() *pb.Command { +func (m MkdirArgs) Cmd() (*pb.Command, error) { b := cmd.B{Args: m.Directory} b.Opv(m.Mode, "--mode") @@ -33,7 +33,7 @@ func (m MkdirArgs) Cmd() *pb.Command { return &pb.Command{ Bin: pb.Bin_BIN_MKDIR, Args: b.Args, - } + }, nil } var _ cmd.Builder = MkdirArgs{} diff --git a/provider/pkg/provider/coreutils/mktemp.go b/provider/pkg/provider/coreutils/mktemp.go index 96ff81fb..32823a58 100644 --- a/provider/pkg/provider/coreutils/mktemp.go +++ b/provider/pkg/provider/coreutils/mktemp.go @@ -26,7 +26,7 @@ type MktempArgs struct { } // Cmd implements CommandArgs. -func (m MktempArgs) Cmd() *pb.Command { +func (m MktempArgs) Cmd() (*pb.Command, error) { b := cmd.B{} b.Op(m.Directory, "--directory") @@ -46,7 +46,7 @@ func (m MktempArgs) Cmd() *pb.Command { return &pb.Command{ Bin: pb.Bin_BIN_MKTEMP, Args: b.Args, - } + }, nil } var _ cmd.Builder = MktempArgs{} diff --git a/provider/pkg/provider/coreutils/mv.go b/provider/pkg/provider/coreutils/mv.go index 21976c49..4f728dda 100644 --- a/provider/pkg/provider/coreutils/mv.go +++ b/provider/pkg/provider/coreutils/mv.go @@ -32,7 +32,7 @@ type MvArgs struct { } // Cmd implements CommandArgs. -func (m MvArgs) Cmd() *pb.Command { +func (m MvArgs) Cmd() (*pb.Command, error) { b := cmd.B{Args: m.Source} b.Opv(m.Backup, "--backup") @@ -53,7 +53,7 @@ func (m MvArgs) Cmd() *pb.Command { return &pb.Command{ Bin: pb.Bin_BIN_MV, Args: b.Args, - } + }, nil } // ExpectMoved implements FileManipulator. diff --git a/provider/pkg/provider/coreutils/rm.go b/provider/pkg/provider/coreutils/rm.go index d7e92152..f60af198 100644 --- a/provider/pkg/provider/coreutils/rm.go +++ b/provider/pkg/provider/coreutils/rm.go @@ -24,7 +24,7 @@ type RmArgs struct { } // Cmd implements CommandArgs. -func (r RmArgs) Cmd() *pb.Command { +func (r RmArgs) Cmd() (*pb.Command, error) { b := cmd.B{Args: r.Files} b.Op(r.Dir, "--dir") @@ -36,7 +36,7 @@ func (r RmArgs) Cmd() *pb.Command { return &pb.Command{ Bin: pb.Bin_BIN_RM, Args: b.Args, - } + }, nil } var _ cmd.Builder = RmArgs{} diff --git a/provider/pkg/provider/coreutils/tar.go b/provider/pkg/provider/coreutils/tar.go index 7b029da4..3db9271b 100644 --- a/provider/pkg/provider/coreutils/tar.go +++ b/provider/pkg/provider/coreutils/tar.go @@ -77,7 +77,7 @@ type TarArgs struct { } // Cmd implements CommandArgs. -func (t TarArgs) Cmd() *pb.Command { +func (t TarArgs) Cmd() (*pb.Command, error) { b := cmd.B{Args: t.Args} b.Op(t.Append, "--append") @@ -126,7 +126,7 @@ func (t TarArgs) Cmd() *pb.Command { return &pb.Command{ Bin: pb.Bin_BIN_TAR, Args: b.Args, - } + }, nil } // ExpectCreated implements CommandArgs. diff --git a/provider/pkg/provider/coreutils/tee.go b/provider/pkg/provider/coreutils/tee.go index e54933fb..75532d02 100644 --- a/provider/pkg/provider/coreutils/tee.go +++ b/provider/pkg/provider/coreutils/tee.go @@ -17,27 +17,33 @@ type TeeArgs struct { cmd.ArgsBase Append bool `pulumi:"append,optional"` - Content asset.Asset `pulumi:"content"` + Content asset.Asset `pulumi:"content,optional"` Files []string `pulumi:"files"` + Stdin string `pulumi:"stdin,optional"` } -func (o TeeArgs) Cmd() *pb.Command { +func (o TeeArgs) Cmd() (*pb.Command, error) { args := []string{} if o.Append { args = append(args, "--append") } - data, err := o.Content.Bytes() - if err != nil { - panic(err) + var stdin string + if len(o.Stdin) > 0 { + stdin = o.Stdin + } else { + data, err := o.Content.Bytes() + if err != nil { + return nil, fmt.Errorf("failed to read asset bytes: %w", err) + } + stdin = string(data) } - stdin := string(data) return &pb.Command{ Bin: pb.Bin_BIN_TEE, Args: append(args, o.Files...), Stdin: &stdin, - } + }, nil } // ExpectCreated implements FileManipulator. diff --git a/provider/pkg/provider/coreutils/wget.go b/provider/pkg/provider/coreutils/wget.go index 247b2de8..7f15a1cc 100644 --- a/provider/pkg/provider/coreutils/wget.go +++ b/provider/pkg/provider/coreutils/wget.go @@ -65,7 +65,7 @@ type WgetArgs struct { } // Cmd implements CommandArgs. -func (w WgetArgs) Cmd() *pb.Command { +func (w WgetArgs) Cmd() (*pb.Command, error) { b := &cmd.B{Args: w.Urls} b.Opv(w.AppendOutput, "--append-output") @@ -118,7 +118,7 @@ func (w WgetArgs) Cmd() *pb.Command { return &pb.Command{ Bin: pb.Bin_BIN_WGET, Args: b.Args, - } + }, nil } // ExpectCreated implements FileManipulator. diff --git a/provider/pkg/provider/kubeadm/config/images.go b/provider/pkg/provider/kubeadm/config/images.go index d4227b0a..c3b42adf 100644 --- a/provider/pkg/provider/kubeadm/config/images.go +++ b/provider/pkg/provider/kubeadm/config/images.go @@ -38,7 +38,7 @@ type ImagesArgs struct { Rootfs string `pulumi:"rootfs,optional"` } -func (a ImagesArgs) Cmd() *pb.Command { +func (a ImagesArgs) Cmd() (*pb.Command, error) { return builder(func(b *cmd.B) { b.Arg("images") b.Arg(string(a.Command)) @@ -48,7 +48,7 @@ func (a ImagesArgs) Cmd() *pb.Command { b.Opv(a.KubernetesVersion, "--kubernetes-version") b.Opv(a.Kubeconfig, "--kubeconfig") b.Opv(a.Rootfs, "--rootfs") - }) + }), nil } type Images struct{} diff --git a/provider/pkg/provider/kubeadm/config/images_test.go b/provider/pkg/provider/kubeadm/config/images_test.go index 6cb47220..9d6fd154 100644 --- a/provider/pkg/provider/kubeadm/config/images_test.go +++ b/provider/pkg/provider/kubeadm/config/images_test.go @@ -12,8 +12,9 @@ var _ = Describe("Images command", func() { It("should properly format arguments", func() { args := config.ImagesArgs{Command: config.Pull} - cmd := args.Cmd() + cmd, err := args.Cmd() + Expect(err).NotTo(HaveOccurred()) Expect(cmd.Bin).To(Equal(pb.Bin_BIN_KUBEADM)) Expect(cmd.Args).To(Equal([]string{ "config", diff --git a/provider/pkg/provider/kubeadm/kubeadm.go b/provider/pkg/provider/kubeadm/kubeadm.go index 5468418a..85fc5837 100644 --- a/provider/pkg/provider/kubeadm/kubeadm.go +++ b/provider/pkg/provider/kubeadm/kubeadm.go @@ -15,12 +15,12 @@ type KubeadmArgs struct { Commands []string `pulumi:"commands"` } -func (a KubeadmArgs) Cmd() *pb.Command { +func (a KubeadmArgs) Cmd() (*pb.Command, error) { return Builder(func(b *cmd.B) { for _, c := range a.Commands { b.Arg(c) } - }) + }), nil } type Kubeadm struct{} diff --git a/sdk/dotnet/Coreutils/Inputs/TeeArgsArgs.cs b/sdk/dotnet/Coreutils/Inputs/TeeArgsArgs.cs index 6d74e0db..21fa6056 100644 --- a/sdk/dotnet/Coreutils/Inputs/TeeArgsArgs.cs +++ b/sdk/dotnet/Coreutils/Inputs/TeeArgsArgs.cs @@ -16,8 +16,8 @@ public sealed class TeeArgsArgs : global::Pulumi.ResourceArgs [Input("append")] public Input? Append { get; set; } - [Input("content", required: true)] - public Input Content { get; set; } = null!; + [Input("content")] + public Input? Content { get; set; } [Input("files", required: true)] private InputList? _files; @@ -27,6 +27,9 @@ public InputList Files set => _files = value; } + [Input("stdin")] + public Input? Stdin { get; set; } + public TeeArgsArgs() { } diff --git a/sdk/dotnet/Coreutils/Outputs/TeeArgs.cs b/sdk/dotnet/Coreutils/Outputs/TeeArgs.cs index 36cd9be6..f94610e4 100644 --- a/sdk/dotnet/Coreutils/Outputs/TeeArgs.cs +++ b/sdk/dotnet/Coreutils/Outputs/TeeArgs.cs @@ -15,20 +15,24 @@ namespace UnMango.Baremetal.Coreutils.Outputs public sealed class TeeArgs { public readonly bool? Append; - public readonly AssetOrArchive Content; + public readonly AssetOrArchive? Content; public readonly ImmutableArray Files; + public readonly string? Stdin; [OutputConstructor] private TeeArgs( bool? append, - AssetOrArchive content, + AssetOrArchive? content, - ImmutableArray files) + ImmutableArray files, + + string? stdin) { Append = append; Content = content; Files = files; + Stdin = stdin; } } } diff --git a/sdk/go/baremetal/coreutils/pulumiTypes.go b/sdk/go/baremetal/coreutils/pulumiTypes.go index 20d7ee91..d7e1757e 100644 --- a/sdk/go/baremetal/coreutils/pulumiTypes.go +++ b/sdk/go/baremetal/coreutils/pulumiTypes.go @@ -876,6 +876,7 @@ type TeeArgsType struct { Append *bool `pulumi:"append"` Content pulumi.AssetOrArchive `pulumi:"content"` Files []string `pulumi:"files"` + Stdin *string `pulumi:"stdin"` } // TeeArgsTypeInput is an input type that accepts TeeArgsTypeArgs and TeeArgsTypeOutput values. @@ -893,6 +894,7 @@ type TeeArgsTypeArgs struct { Append pulumi.BoolPtrInput `pulumi:"append"` Content pulumi.AssetOrArchiveInput `pulumi:"content"` Files pulumi.StringArrayInput `pulumi:"files"` + Stdin pulumi.StringPtrInput `pulumi:"stdin"` } func (TeeArgsTypeArgs) ElementType() reflect.Type { @@ -945,6 +947,10 @@ func (o TeeArgsTypeOutput) Files() pulumi.StringArrayOutput { return o.ApplyT(func(v TeeArgsType) []string { return v.Files }).(pulumi.StringArrayOutput) } +func (o TeeArgsTypeOutput) Stdin() pulumi.StringPtrOutput { + return o.ApplyT(func(v TeeArgsType) *string { return v.Stdin }).(pulumi.StringPtrOutput) +} + type WgetArgsType struct { AppendOutput *string `pulumi:"appendOutput"` Background *bool `pulumi:"background"` diff --git a/sdk/go/baremetal/x/coreutils/pulumiTypes.go b/sdk/go/baremetal/x/coreutils/pulumiTypes.go index 76c2b5a0..01c5a492 100644 --- a/sdk/go/baremetal/x/coreutils/pulumiTypes.go +++ b/sdk/go/baremetal/x/coreutils/pulumiTypes.go @@ -801,15 +801,17 @@ func (o TarArgsTypeOutput) Zstd() pulumix.Output[*bool] { } type TeeArgsType struct { - Append *bool `pulumi:"append"` - Content pulumi.AssetOrArchive `pulumi:"content"` - Files []string `pulumi:"files"` + Append *bool `pulumi:"append"` + Content *pulumi.AssetOrArchive `pulumi:"content"` + Files []string `pulumi:"files"` + Stdin *string `pulumi:"stdin"` } type TeeArgsTypeArgs struct { - Append pulumix.Input[*bool] `pulumi:"append"` - Content pulumix.Input[pulumi.AssetOrArchive] `pulumi:"content"` - Files pulumix.Input[[]string] `pulumi:"files"` + Append pulumix.Input[*bool] `pulumi:"append"` + Content pulumix.Input[*pulumi.AssetOrArchive] `pulumi:"content"` + Files pulumix.Input[[]string] `pulumi:"files"` + Stdin pulumix.Input[*string] `pulumi:"stdin"` } func (TeeArgsTypeArgs) ElementType() reflect.Type { @@ -852,8 +854,8 @@ func (o TeeArgsTypeOutput) Append() pulumix.Output[*bool] { return pulumix.Apply[TeeArgsType](o, func(v TeeArgsType) *bool { return v.Append }) } -func (o TeeArgsTypeOutput) Content() pulumix.Output[pulumi.AssetOrArchive] { - return pulumix.Apply[TeeArgsType](o, func(v TeeArgsType) pulumi.AssetOrArchive { return v.Content }) +func (o TeeArgsTypeOutput) Content() pulumix.Output[*pulumi.AssetOrArchive] { + return pulumix.Apply[TeeArgsType](o, func(v TeeArgsType) *pulumi.AssetOrArchive { return v.Content }) } func (o TeeArgsTypeOutput) Files() pulumix.ArrayOutput[string] { @@ -861,6 +863,10 @@ func (o TeeArgsTypeOutput) Files() pulumix.ArrayOutput[string] { return pulumix.ArrayOutput[string]{OutputState: value.OutputState} } +func (o TeeArgsTypeOutput) Stdin() pulumix.Output[*string] { + return pulumix.Apply[TeeArgsType](o, func(v TeeArgsType) *string { return v.Stdin }) +} + type WgetArgsType struct { AppendOutput *string `pulumi:"appendOutput"` Background *bool `pulumi:"background"` diff --git a/sdk/nodejs/types/input.ts b/sdk/nodejs/types/input.ts index 48aa3a88..0bc849f4 100644 --- a/sdk/nodejs/types/input.ts +++ b/sdk/nodejs/types/input.ts @@ -114,8 +114,9 @@ export namespace coreutils { export interface TeeArgsArgs { append?: pulumi.Input; - content: pulumi.Input; + content?: pulumi.Input; files: pulumi.Input[]>; + stdin?: pulumi.Input; } export interface WgetArgsArgs { diff --git a/sdk/nodejs/types/output.ts b/sdk/nodejs/types/output.ts index f34bb0df..a54925c0 100644 --- a/sdk/nodejs/types/output.ts +++ b/sdk/nodejs/types/output.ts @@ -114,8 +114,9 @@ export namespace coreutils { export interface TeeArgs { append?: boolean; - content: pulumi.asset.Asset | pulumi.asset.Archive; + content?: pulumi.asset.Asset | pulumi.asset.Archive; files: string[]; + stdin?: string; } export interface WgetArgs { diff --git a/sdk/python/unmango_baremetal/coreutils/_inputs.py b/sdk/python/unmango_baremetal/coreutils/_inputs.py index c95a1690..49d3109f 100644 --- a/sdk/python/unmango_baremetal/coreutils/_inputs.py +++ b/sdk/python/unmango_baremetal/coreutils/_inputs.py @@ -1105,22 +1105,17 @@ def zstd(self, value: Optional[pulumi.Input[bool]]): @pulumi.input_type class TeeArgsArgs: def __init__(__self__, *, - 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) + append: Optional[pulumi.Input[bool]] = None, + content: Optional[pulumi.Input[Union[pulumi.Asset, pulumi.Archive]]] = None, + stdin: Optional[pulumi.Input[str]] = None): pulumi.set(__self__, "files", files) if append is not None: pulumi.set(__self__, "append", append) - - @property - @pulumi.getter - def content(self) -> pulumi.Input[Union[pulumi.Asset, pulumi.Archive]]: - return pulumi.get(self, "content") - - @content.setter - def content(self, value: pulumi.Input[Union[pulumi.Asset, pulumi.Archive]]): - pulumi.set(self, "content", value) + if content is not None: + pulumi.set(__self__, "content", content) + if stdin is not None: + pulumi.set(__self__, "stdin", stdin) @property @pulumi.getter @@ -1140,6 +1135,24 @@ def append(self) -> Optional[pulumi.Input[bool]]: def append(self, value: Optional[pulumi.Input[bool]]): pulumi.set(self, "append", value) + @property + @pulumi.getter + def content(self) -> Optional[pulumi.Input[Union[pulumi.Asset, pulumi.Archive]]]: + return pulumi.get(self, "content") + + @content.setter + def content(self, value: Optional[pulumi.Input[Union[pulumi.Asset, pulumi.Archive]]]): + pulumi.set(self, "content", value) + + @property + @pulumi.getter + def stdin(self) -> Optional[pulumi.Input[str]]: + return pulumi.get(self, "stdin") + + @stdin.setter + def stdin(self, value: Optional[pulumi.Input[str]]): + pulumi.set(self, "stdin", value) + @pulumi.input_type class WgetArgsArgs: diff --git a/sdk/python/unmango_baremetal/coreutils/outputs.py b/sdk/python/unmango_baremetal/coreutils/outputs.py index 74d3b96e..e8f9dd61 100644 --- a/sdk/python/unmango_baremetal/coreutils/outputs.py +++ b/sdk/python/unmango_baremetal/coreutils/outputs.py @@ -876,18 +876,17 @@ def zstd(self) -> Optional[bool]: @pulumi.output_type class TeeArgs(dict): def __init__(__self__, *, - content: Union[pulumi.Asset, pulumi.Archive], files: Sequence[str], - append: Optional[bool] = None): - pulumi.set(__self__, "content", content) + append: Optional[bool] = None, + content: Optional[Union[pulumi.Asset, pulumi.Archive]] = None, + stdin: Optional[str] = None): pulumi.set(__self__, "files", files) if append is not None: pulumi.set(__self__, "append", append) - - @property - @pulumi.getter - def content(self) -> Union[pulumi.Asset, pulumi.Archive]: - return pulumi.get(self, "content") + if content is not None: + pulumi.set(__self__, "content", content) + if stdin is not None: + pulumi.set(__self__, "stdin", stdin) @property @pulumi.getter @@ -899,6 +898,16 @@ def files(self) -> Sequence[str]: def append(self) -> Optional[bool]: return pulumi.get(self, "append") + @property + @pulumi.getter + def content(self) -> Optional[Union[pulumi.Asset, pulumi.Archive]]: + return pulumi.get(self, "content") + + @property + @pulumi.getter + def stdin(self) -> Optional[str]: + return pulumi.get(self, "stdin") + @pulumi.output_type class WgetArgs(dict): diff --git a/tests/lifecycle_test.go b/tests/lifecycle_test.go index be6e0b32..a1023e5f 100644 --- a/tests/lifecycle_test.go +++ b/tests/lifecycle_test.go @@ -431,16 +431,16 @@ var _ = Describe("Command Resources", func() { Describe("Tee", func() { var resource tokens.Type = "baremetal:coreutils:Tee" - It("should complete a full lifecycle", func(ctx context.Context) { + It("should complete a full lifecycle with content", func(ctx context.Context) { file := containerPath("create.txt") newFile := containerPath("update.txt") - By("creating the stdin asset") - stdin, err := asset.FromText("Test lifecycle stdin") + By("creating a string asset") + content, err := asset.FromText("Test lifecycle content") Expect(err).NotTo(HaveOccurred()) - By("creating the updated asset") - newStdin, err := asset.FromText("Updated stdin") + By("creating a different string asset") + newContent, err := asset.FromText("Updated content") Expect(err).NotTo(HaveOccurred()) run(server, integration.LifeCycleTest{ @@ -448,13 +448,13 @@ var _ = Describe("Command Resources", func() { Create: integration.Operation{ Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ "args": map[string]interface{}{ - "content": stdin, + "content": content, "files": []string{file}, }, }), Hook: func(inputs, output pr.PropertyMap) { Expect(output["stderr"]).To(HavePropertyValue("")) - Expect(output["stdout"]).To(HavePropertyValue(stdin.Text)) + Expect(output["stdout"]).To(HavePropertyValue(content.Text)) Expect(output["exitCode"]).To(HavePropertyValue(0)) Expect(output["createdFiles"].V).NotTo(BeEmpty()) // TODO: Make this better Expect(output["movedFiles"].V).To(BeEmpty()) @@ -462,20 +462,20 @@ var _ = Describe("Command Resources", func() { data, err := provisioner.ReadFile(ctx, file) Expect(err).NotTo(HaveOccurred()) - Expect(string(data)).To(Equal(stdin.Text)) + Expect(string(data)).To(Equal(content.Text)) }, }, Updates: []integration.Operation{ { Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ "args": map[string]interface{}{ - "content": stdin, + "content": content, "files": []string{newFile}, }, }), Hook: func(inputs, output pr.PropertyMap) { Expect(output["stderr"]).To(HavePropertyValue("")) - Expect(output["stdout"]).To(HavePropertyValue(stdin.Text)) + Expect(output["stdout"]).To(HavePropertyValue(content.Text)) Expect(output["exitCode"]).To(HavePropertyValue(0)) Expect(output["createdFiles"].V).NotTo(BeEmpty()) // TODO: Make this better Expect(output["movedFiles"].V).To(BeEmpty()) @@ -484,19 +484,19 @@ var _ = Describe("Command Resources", func() { data, err := provisioner.ReadFile(ctx, newFile) Expect(err).NotTo(HaveOccurred()) - Expect(string(data)).To(Equal(stdin.Text)) + Expect(string(data)).To(Equal(content.Text)) }, }, { Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ "args": map[string]interface{}{ - "content": newStdin, + "content": newContent, "files": []string{newFile}, }, }), Hook: func(inputs, output pr.PropertyMap) { Expect(output["stderr"]).To(HavePropertyValue("")) - Expect(output["stdout"]).To(HavePropertyValue(newStdin.Text)) + Expect(output["stdout"]).To(HavePropertyValue(newContent.Text)) Expect(output["exitCode"]).To(HavePropertyValue(0)) Expect(output["createdFiles"].V).NotTo(BeEmpty()) // TODO: Make this better Expect(output["movedFiles"].V).To(BeEmpty()) @@ -504,19 +504,120 @@ var _ = Describe("Command Resources", func() { data, err := provisioner.ReadFile(ctx, newFile) Expect(err).NotTo(HaveOccurred()) - Expect(string(data)).To(Equal(newStdin.Text)) + Expect(string(data)).To(Equal(newContent.Text)) }, }, { Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ "args": map[string]interface{}{ - "content": newStdin, + "content": newContent, "files": []string{file, newFile}, }, }), Hook: func(inputs, output pr.PropertyMap) { Expect(output["stderr"]).To(HavePropertyValue("")) - Expect(output["stdout"]).To(HavePropertyValue(newStdin.Text)) + Expect(output["stdout"]).To(HavePropertyValue(newContent.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"])) + + data, err := provisioner.ReadFile(ctx, file) + Expect(err).NotTo(HaveOccurred()) + Expect(string(data)).To(Equal(newContent.Text)) + + data, err = provisioner.ReadFile(ctx, newFile) + Expect(err).NotTo(HaveOccurred()) + Expect(string(data)).To(Equal(newContent.Text)) + }, + }, + }, + }) + + Expect(provisioner).NotTo(ContainFile(ctx, newFile)) + Expect(provisioner).NotTo(ContainFile(ctx, file)) + }) + + It("should complete a full lifecycle with stdin", func(ctx context.Context) { + file := containerPath("create.txt") + newFile := containerPath("update.txt") + stdin := "Test content stdin" + newStdin := "Updated stdin" + + run(server, integration.LifeCycleTest{ + Resource: resource, + Create: integration.Operation{ + Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ + "args": map[string]interface{}{ + "stdin": stdin, + "files": []string{file}, + }, + }), + Hook: func(inputs, output pr.PropertyMap) { + Expect(output["stderr"]).To(HavePropertyValue("")) + Expect(output["stdout"]).To(HavePropertyValue(stdin)) + 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)) + }, + }, + Updates: []integration.Operation{ + { + Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ + "args": map[string]interface{}{ + "stdin": stdin, + "files": []string{newFile}, + }, + }), + Hook: func(inputs, output pr.PropertyMap) { + Expect(output["stderr"]).To(HavePropertyValue("")) + Expect(output["stdout"]).To(HavePropertyValue(stdin)) + 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)) + }, + }, + { + Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ + "args": map[string]interface{}{ + "stdin": newStdin, + "files": []string{newFile}, + }, + }), + Hook: func(inputs, output pr.PropertyMap) { + Expect(output["stderr"]).To(HavePropertyValue("")) + Expect(output["stdout"]).To(HavePropertyValue(newStdin)) + 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)) + }, + }, + { + Inputs: pr.NewPropertyMapFromMap(map[string]interface{}{ + "args": map[string]interface{}{ + "stdin": newStdin, + "files": []string{file, newFile}, + }, + }), + Hook: func(inputs, output pr.PropertyMap) { + Expect(output["stderr"]).To(HavePropertyValue("")) + Expect(output["stdout"]).To(HavePropertyValue(newStdin)) Expect(output["exitCode"]).To(HavePropertyValue(0)) Expect(output["createdFiles"].V).To(HaveLen(2)) // TODO: Make this better Expect(output["movedFiles"].V).To(BeEmpty()) @@ -524,11 +625,11 @@ var _ = Describe("Command Resources", func() { data, err := provisioner.ReadFile(ctx, file) Expect(err).NotTo(HaveOccurred()) - Expect(string(data)).To(Equal(newStdin.Text)) + Expect(string(data)).To(Equal(newStdin)) data, err = provisioner.ReadFile(ctx, newFile) Expect(err).NotTo(HaveOccurred()) - Expect(string(data)).To(Equal(newStdin.Text)) + Expect(string(data)).To(Equal(newStdin)) }, }, },