Skip to content

Commit

Permalink
Add rm command (#92)
Browse files Browse the repository at this point in the history
* Add rm command

* Regen SDKs
  • Loading branch information
UnstoppableMango authored Aug 4, 2024
1 parent 9b8dfb5 commit 77e047f
Show file tree
Hide file tree
Showing 22 changed files with 1,132 additions and 23 deletions.
1 change: 0 additions & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ require (
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down
14 changes: 0 additions & 14 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys=
github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
Expand All @@ -91,12 +87,8 @@ github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=
github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 h1:hFhpt7CTmR3DX+b4R19ydQFtofxT0Sv3QsKNMVQYTMQ=
github.com/google/pprof v0.0.0-20230406165453-00490a63f317/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg=
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down Expand Up @@ -152,14 +144,8 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A=
github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM=
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/ginkgo/v2 v2.19.1 h1:QXgq3Z8Crl5EL1WBAC98A5sEBHARrAJNzAmMxzLcRF0=
github.com/onsi/ginkgo/v2 v2.19.1/go.mod h1:O3DtEWQkPa/F7fBMgmZQKKsluAy8pd3rEQdrjkPb9zA=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/onsi/gomega v1.34.0 h1:eSSPsPNp6ZpsG8X1OVmOTxig+CblTc4AxpPBykhe2Os=
github.com/onsi/gomega v1.34.0/go.mod h1:MIKI8c+f+QLWk+hxbePD4i0LMJSExPaZOVfkoex4cAo=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/opentracing/basictracer-go v1.1.0 h1:Oa1fTSBvAl8pa3U+IJYqrKm0NALwH9OsgwOqDv4xJW0=
Expand Down
13 changes: 5 additions & 8 deletions provider/pkg/provider/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"encoding/json"
"fmt"

pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1"
Expand Down Expand Up @@ -37,13 +36,6 @@ func (s *CommandState[T]) Create(ctx context.Context, inputs T, preview bool) er
return fmt.Errorf("creating provisioner: %w", err)
}

temp, err := json.Marshal(inputs.ExpectedFiles())
if err != nil {
return fmt.Errorf("failed marshalling json: %w", err)
}

log.Info(string(temp))

log.Debug("sending create request")
res, err := p.Create(ctx, &pb.CreateRequest{
Command: inputs.Cmd(),
Expand All @@ -53,6 +45,11 @@ func (s *CommandState[T]) Create(ctx context.Context, inputs T, preview bool) er
return fmt.Errorf("sending create request: %w", err)
}

if res.Files == nil {
log.Debug("files was empty, this is probably a bug somewhere else")
res.Files = []string{}
}

s.Args = inputs
s.ExitCode = int(res.Result.ExitCode)
s.Stdout = res.Result.Stdout
Expand Down
78 changes: 78 additions & 0 deletions provider/pkg/provider/cmd/rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cmd

import (
"context"
"fmt"

"github.com/pulumi/pulumi-go-provider/infer"
pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1"
)

type RmArgs struct {
Dir bool `pulumi:"dir,optional"`
Files []string `pulumi:"files"`
Force bool `pulumi:"force,optional"`
Help bool `pulumi:"help,optional"`
OneFileSystem bool `pulumi:"oneFileSystem,optional"`
Recursive bool `pulumi:"recursive,optional"`
Verbose bool `pulumi:"verbose,optional"`
}

// Cmd implements CommandArgs.
func (r RmArgs) Cmd() *pb.Command {
b := builder{r.Files}
b.op(r.Dir, "--dir")
b.op(r.Force, "--force")
b.op(r.Help, "--help")
b.op(r.OneFileSystem, "--one-file-system")
b.op(r.Verbose, "--verbose")

return &pb.Command{
Bin: pb.Bin_BIN_RM,
Args: b.args,
}
}

// ExpectedFiles implements CommandArgs.
func (r RmArgs) ExpectedFiles() []string {
return []string{}
}

var _ CommandArgs = RmArgs{}

type Rm struct{}

type RmState = CommandState[RmArgs]

// Create implements infer.CustomCreate.
func (Rm) Create(ctx context.Context, name string, inputs RmArgs, preview bool) (id string, output RmState, err error) {
state := RmState{}
if err := state.Create(ctx, inputs, preview); err != nil {
return name, state, fmt.Errorf("wget: %w", err)
}

return name, state, nil
}

// Update implements infer.CustomUpdate.
func (Rm) Update(ctx context.Context, id string, olds RmState, news RmArgs, preview bool) (RmState, error) {
state, err := olds.Update(ctx, news, preview)
if err != nil {
return olds, fmt.Errorf("wget: %w", err)
}

return state, nil
}

// Delete implements infer.CustomDelete.
func (Rm) Delete(ctx context.Context, id string, props RmState) error {
if err := props.Delete(ctx); err != nil {
return fmt.Errorf("wget: %w", err)
}

return nil
}

var _ = (infer.CustomCreate[RmArgs, RmState])((*Rm)(nil))
var _ = (infer.CustomUpdate[RmArgs, RmState])((*Rm)(nil))
var _ = (infer.CustomDelete[RmState])((*Rm)(nil))
1 change: 1 addition & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Provider() p.Provider {
},
Config: infer.Config[provider.Config](),
Resources: []infer.InferredResource{
infer.Resource[cmd.Rm](),
infer.Resource[cmd.Tee](),
infer.Resource[cmd.Wget](),
},
Expand Down
50 changes: 50 additions & 0 deletions sdk/dotnet/Cmd/Outputs/RmArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// *** WARNING: this file was generated by pulumi. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi.Serialization;
using Pulumi;

namespace UnMango.Baremetal.Cmd.Outputs
{

[OutputType]
public sealed class RmArgs
{
public readonly bool? Dir;
public readonly ImmutableArray<string> Files;
public readonly bool? Force;
public readonly bool? Help;
public readonly bool? OneFileSystem;
public readonly bool? Recursive;
public readonly bool? Verbose;

[OutputConstructor]
private RmArgs(
bool? dir,

ImmutableArray<string> files,

bool? force,

bool? help,

bool? oneFileSystem,

bool? recursive,

bool? verbose)
{
Dir = dir;
Files = files;
Force = force;
Help = help;
OneFileSystem = oneFileSystem;
Recursive = recursive;
Verbose = verbose;
}
}
}
108 changes: 108 additions & 0 deletions sdk/dotnet/Cmd/Rm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// *** WARNING: this file was generated by pulumi. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi.Serialization;
using Pulumi;

namespace UnMango.Baremetal.Cmd
{
[BaremetalResourceType("baremetal:cmd:Rm")]
public partial class Rm : global::Pulumi.CustomResource
{
[Output("args")]
public Output<Outputs.RmArgs> Args { get; private set; } = null!;

[Output("createdFiles")]
public Output<ImmutableArray<string>> CreatedFiles { get; private set; } = null!;

[Output("exitCode")]
public Output<int> ExitCode { get; private set; } = null!;

[Output("stderr")]
public Output<string> Stderr { get; private set; } = null!;

[Output("stdout")]
public Output<string> Stdout { get; private set; } = null!;


/// <summary>
/// Create a Rm resource with the given unique name, arguments, and options.
/// </summary>
///
/// <param name="name">The unique name of the resource</param>
/// <param name="args">The arguments used to populate this resource's properties</param>
/// <param name="options">A bag of options that control this resource's behavior</param>
public Rm(string name, RmArgs args, CustomResourceOptions? options = null)
: base("baremetal:cmd:Rm", name, args ?? new RmArgs(), MakeResourceOptions(options, ""))
{
}

private Rm(string name, Input<string> id, CustomResourceOptions? options = null)
: base("baremetal:cmd:Rm", name, null, MakeResourceOptions(options, id))
{
}

private static CustomResourceOptions MakeResourceOptions(CustomResourceOptions? options, Input<string>? id)
{
var defaultOptions = new CustomResourceOptions
{
Version = Utilities.Version,
PluginDownloadURL = "github://api.github.com/unmango",
};
var merged = CustomResourceOptions.Merge(defaultOptions, options);
// Override the ID if one was specified for consistency with other language SDKs.
merged.Id = id ?? merged.Id;
return merged;
}
/// <summary>
/// Get an existing Rm resource's state with the given name, ID, and optional extra
/// properties used to qualify the lookup.
/// </summary>
///
/// <param name="name">The unique name of the resulting resource.</param>
/// <param name="id">The unique provider ID of the resource to lookup.</param>
/// <param name="options">A bag of options that control this resource's behavior</param>
public static Rm Get(string name, Input<string> id, CustomResourceOptions? options = null)
{
return new Rm(name, id, options);
}
}

public sealed class RmArgs : global::Pulumi.ResourceArgs
{
[Input("dir")]
public Input<bool>? Dir { get; set; }

[Input("files", required: true)]
private InputList<string>? _files;
public InputList<string> Files
{
get => _files ?? (_files = new InputList<string>());
set => _files = value;
}

[Input("force")]
public Input<bool>? Force { get; set; }

[Input("help")]
public Input<bool>? Help { get; set; }

[Input("oneFileSystem")]
public Input<bool>? OneFileSystem { get; set; }

[Input("recursive")]
public Input<bool>? Recursive { get; set; }

[Input("verbose")]
public Input<bool>? Verbose { get; set; }

public RmArgs()
{
}
public static new RmArgs Empty => new RmArgs();
}
}
2 changes: 2 additions & 0 deletions sdk/go/baremetal/cmd/init.go

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

Loading

0 comments on commit 77e047f

Please sign in to comment.