Skip to content

Commit

Permalink
Add chmod resource (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnstoppableMango authored Aug 5, 2024
1 parent 887e995 commit 82067d4
Show file tree
Hide file tree
Showing 24 changed files with 1,432 additions and 11 deletions.
22 changes: 13 additions & 9 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.

1 change: 1 addition & 0 deletions proto/unmango/baremetal/v1alpha1/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ enum Bin {
BIN_TAR = 5;
BIN_MKDIR = 6;
BIN_MKTEMP = 7;
BIN_CHMOD = 8;
}
90 changes: 90 additions & 0 deletions provider/pkg/provider/cmd/chmod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package cmd

import (
"context"
"fmt"
"strings"

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

type ChmodArgs struct {
DefaultFileManipulator
Files []string `pulumi:"files"`
Mode []string `pulumi:"mode,optional"`
OctalMode string `pulumi:"octalMode,optional"`
Changes bool `pulumi:"changes,optional"`
NoPreserveRoot bool `pulumi:"noPreserveRoot,optional"`
PreserveRoot bool `pulumi:"preserveRoot,optional"`
Quiet bool `pulumi:"quiet,optional"`
Reference string `pulumi:"reference,optional"`
Recursive bool `pulumi:"recursive,optional"`
Verbose bool `pulumi:"verbose,optional"`
Help bool `pulumi:"help,optional"`
Version bool `pulumi:"version,optional"`
}

// Cmd implements CommandArgs.
func (m ChmodArgs) Cmd() *pb.Command {
b := builder{}
b.op(m.Changes, "--changes")
b.op(m.NoPreserveRoot, "--no-preserve-root")
b.op(m.PreserveRoot, "--preserve-root")
b.op(m.Quiet, "--quiet")
b.opv(m.Reference, "--reference")
b.op(m.Recursive, "--recursive")
b.op(m.Verbose, "--verbose")
b.op(m.Help, "--help")
b.op(m.Version, "--version")

b.arg(strings.Join(m.Mode, ","))
b.arg(m.OctalMode)

for _, f := range m.Files {
b.arg(f)
}

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

var _ CommandArgs = ChmodArgs{}

type Chmod struct{}

type ChmodState = CommandState[ChmodArgs]

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

return name, state, nil
}

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

return state, nil
}

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

return nil
}

var _ = (infer.CustomCreate[ChmodArgs, ChmodState])((*Chmod)(nil))
var _ = (infer.CustomUpdate[ChmodArgs, ChmodState])((*Chmod)(nil))
1 change: 0 additions & 1 deletion provider/pkg/provider/cmd/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@ func (Mkdir) Delete(ctx context.Context, id string, props MkdirState) error {

var _ = (infer.CustomCreate[MkdirArgs, MkdirState])((*Mkdir)(nil))
var _ = (infer.CustomUpdate[MkdirArgs, MkdirState])((*Mkdir)(nil))
var _ = (infer.CustomDelete[MkdirState])((*Mkdir)(nil))
1 change: 0 additions & 1 deletion provider/pkg/provider/cmd/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,3 @@ func (Mv) Delete(ctx context.Context, id string, props MvState) error {

var _ = (infer.CustomCreate[MvArgs, MvState])((*Mv)(nil))
var _ = (infer.CustomUpdate[MvArgs, MvState])((*Mv)(nil))
var _ = (infer.CustomDelete[MvState])((*Mv)(nil))
2 changes: 2 additions & 0 deletions provider/pkg/provisioner/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ 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_CHMOD:
return "chmod", nil
case pb.Bin_BIN_MKDIR:
return "mkdir", nil
case pb.Bin_BIN_MKTEMP:
Expand Down
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.Chmod](),
infer.Resource[cmd.Mkdir](),
infer.Resource[cmd.Mktemp](),
infer.Resource[cmd.Mv](),
Expand Down
131 changes: 131 additions & 0 deletions sdk/dotnet/Cmd/Chmod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// *** 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:Chmod")]
public partial class Chmod : global::Pulumi.CustomResource
{
[Output("args")]
public Output<Outputs.ChmodArgs> 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("movedFiles")]
public Output<ImmutableDictionary<string, string>> MovedFiles { 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 Chmod 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 Chmod(string name, ChmodArgs args, CustomResourceOptions? options = null)
: base("baremetal:cmd:Chmod", name, args ?? new ChmodArgs(), MakeResourceOptions(options, ""))
{
}

private Chmod(string name, Input<string> id, CustomResourceOptions? options = null)
: base("baremetal:cmd:Chmod", 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 Chmod 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 Chmod Get(string name, Input<string> id, CustomResourceOptions? options = null)
{
return new Chmod(name, id, options);
}
}

public sealed class ChmodArgs : global::Pulumi.ResourceArgs
{
[Input("changes")]
public Input<bool>? Changes { get; set; }

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

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

[Input("mode")]
private InputList<string>? _mode;
public InputList<string> Mode
{
get => _mode ?? (_mode = new InputList<string>());
set => _mode = value;
}

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

[Input("octalMode")]
public Input<string>? OctalMode { get; set; }

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

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

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

[Input("reference")]
public Input<string>? Reference { get; set; }

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

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

public ChmodArgs()
{
}
public static new ChmodArgs Empty => new ChmodArgs();
}
}
70 changes: 70 additions & 0 deletions sdk/dotnet/Cmd/Outputs/ChmodArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// *** 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 ChmodArgs
{
public readonly bool? Changes;
public readonly ImmutableArray<string> Files;
public readonly bool? Help;
public readonly ImmutableArray<string> Mode;
public readonly bool? NoPreserveRoot;
public readonly string? OctalMode;
public readonly bool? PreserveRoot;
public readonly bool? Quiet;
public readonly bool? Recursive;
public readonly string? Reference;
public readonly bool? Verbose;
public readonly bool? Version;

[OutputConstructor]
private ChmodArgs(
bool? changes,

ImmutableArray<string> files,

bool? help,

ImmutableArray<string> mode,

bool? noPreserveRoot,

string? octalMode,

bool? preserveRoot,

bool? quiet,

bool? recursive,

string? reference,

bool? verbose,

bool? version)
{
Changes = changes;
Files = files;
Help = help;
Mode = mode;
NoPreserveRoot = noPreserveRoot;
OctalMode = octalMode;
PreserveRoot = preserveRoot;
Quiet = quiet;
Recursive = recursive;
Reference = reference;
Verbose = verbose;
Version = version;
}
}
}
Loading

0 comments on commit 82067d4

Please sign in to comment.