diff --git a/examples/file.yaml b/examples/file.yaml new file mode 100644 index 0000000..336327a --- /dev/null +++ b/examples/file.yaml @@ -0,0 +1,8 @@ +resources: +- type: file + attributes: + path: /tmp/foo.txt + owner: nobody + group: nobody + mode: 0644 + state: present diff --git a/examples/user.yaml b/examples/user.yaml new file mode 100644 index 0000000..14e3a42 --- /dev/null +++ b/examples/user.yaml @@ -0,0 +1,7 @@ +resources: +- type: user + attributes: + name: "testuser" + uid: "12001" + home: "/home/testuser" + state: present diff --git a/internal/resource/exec.go b/internal/resource/exec.go new file mode 100644 index 0000000..9148719 --- /dev/null +++ b/internal/resource/exec.go @@ -0,0 +1,65 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +// +package resource + +import ( + "context" + "fmt" +_ "os" + "gopkg.in/yaml.v3" +_ "os/exec" +_ "strings" +_ "log" + "net/url" +) + +type Exec struct { + loader YamlLoader + Id string `yaml:"id"` + // create command + // read command + // update command + // delete command + + // state attributes + State string `yaml:"state"` +} + +func init() { + ResourceTypes.Register("exec", func(u *url.URL) Resource { + x := NewExec() + return x + }) +} + +func NewExec() *Exec { + return &Exec { loader: YamlLoadDecl } +} + +func (x *Exec) URI() string { + return fmt.Sprintf("exec://%s", x.Id) +} + +func (x *Exec) SetURI(uri string) error { + return nil +} + +func (x *Exec) ResolveId(ctx context.Context) string { + return "" +} + +func (x *Exec) Apply() error { + return nil +} + +func (x *Exec) LoadDecl(yamlFileResourceDeclaration string) error { + return x.loader(yamlFileResourceDeclaration, x) +} + +func (x *Exec) Type() string { return "exec" } + +func (x *Exec) Read(ctx context.Context) ([]byte, error) { + return yaml.Marshal(x) +} + diff --git a/internal/resource/exec_text.go b/internal/resource/exec_text.go new file mode 100644 index 0000000..c1a7026 --- /dev/null +++ b/internal/resource/exec_text.go @@ -0,0 +1,49 @@ +// Copyright 2024 Matthew Rich . All rights reserved +package resource + +import ( + _ "context" + _ "encoding/json" + _ "fmt" + "github.com/stretchr/testify/assert" + _ "gopkg.in/yaml.v3" + _ "io" + _ "log" + _ "net/http" + _ "net/http/httptest" + _ "net/url" + _ "os" + _ "strings" + "testing" +) + +func TestNewExecResource(t *testing.T) { + x := NewExec() + assert.NotEqual(t, nil, x) +} + +func TestExecApplyResourceTransformation(t *testing.T) { + x := NewExec() + assert.NotEqual(t, nil, x) + + //e := f.Apply() + //assert.Equal(t, nil, e) +} + +func TestReadExec(t *testing.T) { + +} + +func TestReadExecError(t *testing.T) { +} + +func TestCreateExec(t *testing.T) { +} + +func TestExecSetURI(t *testing.T) { + x := NewExec() + assert.NotNil(t, x) + x.SetURI("exec://" + "12345_key") + assert.Equal(t, "exec", x.Type()) + assert.Equal(t, "12345_key", x.Id) +} diff --git a/internal/resource/file_test.go b/internal/resource/file_test.go index 7d1294c..b1169fe 100644 --- a/internal/resource/file_test.go +++ b/internal/resource/file_test.go @@ -179,3 +179,12 @@ func TestFileTimes(t *testing.T) { assert.Equal(t, "nobody", f.Owner) assert.True(t, f.Mtime.Equal(expectedTime)) } + +func TestFileSetURI(t *testing.T) { + file, _ := filepath.Abs(filepath.Join(TempDir, "testuri.txt")) + f := NewFile() + assert.NotNil(t, f) + f.SetURI("file://" + file) + assert.Equal(t, "file", f.Type()) + assert.Equal(t, file, f.Path) +}