Skip to content

Commit

Permalink
Add mkdir and mktemp (#97)
Browse files Browse the repository at this point in the history
* Add mkdir and mktemp

* Get tests working

* Regen SDKs
  • Loading branch information
UnstoppableMango authored Aug 5, 2024
1 parent 82cb8f0 commit 887e995
Show file tree
Hide file tree
Showing 29 changed files with 2,388 additions and 33 deletions.
74 changes: 41 additions & 33 deletions gen/go/unmango/baremetal/v1alpha1/command.pb.go

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

2 changes: 2 additions & 0 deletions proto/unmango/baremetal/v1alpha1/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ enum Bin {
BIN_WGET = 3;
BIN_MV = 4;
BIN_TAR = 5;
BIN_MKDIR = 6;
BIN_MKTEMP = 7;
}
73 changes: 73 additions & 0 deletions provider/pkg/provider/cmd/mkdir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cmd

import (
"context"
"fmt"

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

type MkdirArgs struct {
DefaultFileManipulator
Directory []string `pulumi:"directory"`
Mode string `pulumi:"mode,optional"`
Parents bool `pulumi:"parents,optional"`
Verbose bool `pulumi:"verbose,optional"`
Help bool `pulumi:"help,optional"`
Version bool `pulumi:"version,optional"`
}

// Cmd implements CommandArgs.
func (m MkdirArgs) Cmd() *pb.Command {
b := builder{m.Directory}
b.opv(m.Mode, "--mode")
b.op(m.Parents, "--parents")
b.op(m.Verbose, "--verbose")
b.op(m.Help, "--help")
b.op(m.Version, "--version")

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

var _ CommandArgs = MkdirArgs{}

type Mkdir struct{}

type MkdirState = CommandState[MkdirArgs]

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

return name, state, nil
}

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

return state, nil
}

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

return nil
}

var _ = (infer.CustomCreate[MkdirArgs, MkdirState])((*Mkdir)(nil))
var _ = (infer.CustomUpdate[MkdirArgs, MkdirState])((*Mkdir)(nil))
var _ = (infer.CustomDelete[MkdirState])((*Mkdir)(nil))
85 changes: 85 additions & 0 deletions provider/pkg/provider/cmd/mktemp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package cmd

import (
"context"
"fmt"

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

type MktempArgs struct {
DefaultFileManipulator
Template string `pulumi:"template,optional"`
Directory bool `pulumi:"directory,optional"`
DryRun bool `pulumi:"dryRun,optional"`
Quiet bool `pulumi:"quiet,optional"`
Suffix string `pulumi:"suffix,optional"`
P string `pulumi:"p,optional"`
TmpDir bool `pulumi:"tmpdir,optional"`
T bool `pulumi:"t,optional"`
Help bool `pulumi:"help,optional"`
Version bool `pulumi:"version,optional"`
}

// Cmd implements CommandArgs.
func (m MktempArgs) Cmd() *pb.Command {
b := builder{}
b.op(m.Directory, "--directory")
b.op(m.DryRun, "--dry-run")
b.op(m.Quiet, "--quiet")
b.opv(m.Suffix, "--suffix")
b.opv(m.P, "-p")
b.op(m.TmpDir, "--tmpdir")
b.op(m.T, "-t")
b.op(m.Help, "--help")
b.op(m.Version, "--version")

if m.Template != "" {
b.arg(m.Template)
}

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

var _ CommandArgs = MktempArgs{}

type Mktemp struct{}

type MktempState = CommandState[MktempArgs]

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

return name, state, nil
}

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

return state, nil
}

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

return nil
}

var _ = (infer.CustomCreate[MktempArgs, MktempState])((*Mktemp)(nil))
var _ = (infer.CustomUpdate[MktempArgs, MktempState])((*Mktemp)(nil))
var _ = (infer.CustomDelete[MktempState])((*Mktemp)(nil))
4 changes: 4 additions & 0 deletions provider/pkg/provisioner/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func (s *service) Delete(ctx context.Context, req *pb.DeleteRequest) (*pb.Delete

func binPath(b pb.Bin) (string, error) {
switch b {
case pb.Bin_BIN_MKDIR:
return "mkdir", nil
case pb.Bin_BIN_MKTEMP:
return "mktemp", nil
case pb.Bin_BIN_MV:
return "mv", nil
case pb.Bin_BIN_RM:
Expand Down
2 changes: 2 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func Provider() p.Provider {
},
Config: infer.Config[provider.Config](),
Resources: []infer.InferredResource{
infer.Resource[cmd.Mkdir](),
infer.Resource[cmd.Mktemp](),
infer.Resource[cmd.Mv](),
infer.Resource[cmd.Rm](),
infer.Resource[cmd.Tar](),
Expand Down
Loading

0 comments on commit 887e995

Please sign in to comment.