This commit is contained in:
parent
b57de00464
commit
e71d177984
8
examples/file.yaml
Normal file
8
examples/file.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
resources:
|
||||
- type: file
|
||||
attributes:
|
||||
path: /tmp/foo.txt
|
||||
owner: nobody
|
||||
group: nobody
|
||||
mode: 0644
|
||||
state: present
|
7
examples/user.yaml
Normal file
7
examples/user.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
resources:
|
||||
- type: user
|
||||
attributes:
|
||||
name: "testuser"
|
||||
uid: "12001"
|
||||
home: "/home/testuser"
|
||||
state: present
|
65
internal/resource/exec.go
Normal file
65
internal/resource/exec.go
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. 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)
|
||||
}
|
||||
|
49
internal/resource/exec_text.go
Normal file
49
internal/resource/exec_text.go
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. 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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user