2024-03-20 19:23:31 +00:00
|
|
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
2024-03-22 17:39:06 +00:00
|
|
|
|
|
|
|
// The resource package handles CRUD operations on resources and YAML (de)serialization
|
2024-03-20 16:15:27 +00:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
2024-03-25 20:31:06 +00:00
|
|
|
"context"
|
2024-04-03 16:54:50 +00:00
|
|
|
_ "encoding/json"
|
2024-03-25 20:31:06 +00:00
|
|
|
_ "fmt"
|
|
|
|
_ "gopkg.in/yaml.v3"
|
|
|
|
_ "net/url"
|
2024-03-20 16:15:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Resource interface {
|
2024-03-25 20:31:06 +00:00
|
|
|
Type() string
|
|
|
|
URI() string
|
2024-04-19 07:52:10 +00:00
|
|
|
SetURI(string) error
|
2024-03-25 20:31:06 +00:00
|
|
|
ResolveId(context.Context) string
|
|
|
|
ResourceLoader
|
|
|
|
StateTransformer
|
|
|
|
ResourceReader
|
2024-04-09 19:30:05 +00:00
|
|
|
ResourceValidator
|
2024-04-19 07:52:10 +00:00
|
|
|
Clone() Resource
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:23:31 +00:00
|
|
|
type ResourceValidator interface {
|
2024-03-25 20:31:06 +00:00
|
|
|
Validate() error
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceCreator interface {
|
2024-03-25 20:31:06 +00:00
|
|
|
Create(context.Context) error
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceReader interface {
|
2024-03-25 20:31:06 +00:00
|
|
|
Read(context.Context) ([]byte, error)
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceUpdater interface {
|
2024-03-25 20:31:06 +00:00
|
|
|
Update() error
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceDeleter interface {
|
2024-03-25 20:31:06 +00:00
|
|
|
Delete() error
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:23:31 +00:00
|
|
|
type ResourceDecoder struct {
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:23:31 +00:00
|
|
|
func NewResource(uri string) Resource {
|
2024-03-25 20:31:06 +00:00
|
|
|
r, e := ResourceTypes.New(uri)
|
|
|
|
if e == nil {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
return nil
|
2024-03-20 16:15:27 +00:00
|
|
|
}
|
2024-04-21 06:13:17 +00:00
|
|
|
/*
|
|
|
|
func Machine() {
|
|
|
|
// start_destroy -> absent -> start_create -> present -> start_destroy
|
|
|
|
stater := machine.New("absent")
|
|
|
|
stater.AddStates("absent", "start_create", "present", "start_delete")
|
|
|
|
stater.AddTransition("creating", "absent", "start_create")
|
|
|
|
stater.AddTransition("created", "start_create", "present")
|
|
|
|
stater.AddTransition("deleting", "present", "start_delete")
|
|
|
|
stater.AddTransition("deleted", "start_delete", "absent")
|
|
|
|
}
|
|
|
|
*/
|