Compare commits
No commits in common. "1fdc1fc456fb20dcb73825b4ffb5b93087e2488e" and "8910fced575f551f8b09c82cdb7e703ab4ce5b3c" have entirely different histories.
1fdc1fc456
...
8910fced57
29
README.md
29
README.md
@ -10,34 +10,7 @@ These tools work with YAML descriptions of resources (E.g. files, users, contain
|
|||||||
|
|
||||||
# Releases
|
# Releases
|
||||||
|
|
||||||
**v0 releases are unstable and changes may be made to interfaces and specifications.**
|
v0 releases are unstable and changes may be made to interfaces and specifications.
|
||||||
|
|
||||||
# JX Documents
|
|
||||||
|
|
||||||
The JX YAML specification is a simple way to describe system resources. The two main components are `configurations` and `resources`.
|
|
||||||
|
|
||||||
## Configurations
|
|
||||||
|
|
||||||
`
|
|
||||||
configurations:
|
|
||||||
- name: myhttpconfig
|
|
||||||
values:
|
|
||||||
http_user: jex
|
|
||||||
http_password: sample
|
|
||||||
- name: myhttptoken
|
|
||||||
values:
|
|
||||||
authorization_token: abcde123456789
|
|
||||||
`
|
|
||||||
|
|
||||||
## Resources
|
|
||||||
`
|
|
||||||
resources:
|
|
||||||
- type: http
|
|
||||||
config: myhttptoken
|
|
||||||
transition: read
|
|
||||||
attributes:
|
|
||||||
endpoint: https://myserver/v1/api
|
|
||||||
`
|
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
|
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
||||||
|
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/url"
|
|
||||||
"fmt"
|
|
||||||
"decl/internal/data"
|
|
||||||
"decl/internal/folio"
|
|
||||||
"runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Collects facts about the system
|
|
||||||
|
|
||||||
var (
|
|
||||||
buildValues = map[string]any{
|
|
||||||
"GOOS": runtime.GOOS,
|
|
||||||
"GOARCH": runtime.GOARCH,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
folio.DocumentRegistry.ConfigurationTypes.Register([]string{"system"}, func(u *url.URL) data.Configuration {
|
|
||||||
s := NewSystem()
|
|
||||||
return s
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type System Generic[any]
|
|
||||||
|
|
||||||
func NewSystem() *System {
|
|
||||||
s := make(System)
|
|
||||||
for k, v := range buildValues {
|
|
||||||
s[k] = v
|
|
||||||
}
|
|
||||||
return &s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) URI() string {
|
|
||||||
return fmt.Sprintf("%s://%s", s.Type(), "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) SetURI(uri string) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) SetParsedURI(uri *url.URL) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) Clone() data.Configuration {
|
|
||||||
jsonSystem, _ := json.Marshal(s)
|
|
||||||
clone := NewSystem()
|
|
||||||
if unmarshalErr := json.Unmarshal(jsonSystem, clone); unmarshalErr != nil {
|
|
||||||
panic(unmarshalErr)
|
|
||||||
}
|
|
||||||
return clone
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) Has(key string) (ok bool) {
|
|
||||||
_, ok = (*s)[key]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) Type() string {
|
|
||||||
return "system"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) Read(context.Context) ([]byte, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *System) GetValue(name string) (result any, err error) {
|
|
||||||
var ok bool
|
|
||||||
if result, ok = (*s)[name]; !ok {
|
|
||||||
err = ErrUnknownConfigurationKey
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
||||||
|
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewSystemConfig(t *testing.T) {
|
|
||||||
s := NewSystem()
|
|
||||||
assert.NotNil(t, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSystemConfig(t *testing.T) {
|
|
||||||
s := NewSystem()
|
|
||||||
assert.NotNil(t, s)
|
|
||||||
|
|
||||||
assert.True(t, s.Has("GOARCH"))
|
|
||||||
}
|
|
@ -10,11 +10,11 @@ import (
|
|||||||
type ReadFilter func([]byte, int, error) (int, error)
|
type ReadFilter func([]byte, int, error) (int, error)
|
||||||
|
|
||||||
type Reader struct {
|
type Reader struct {
|
||||||
input io.ReadCloser
|
input io.Reader
|
||||||
filter ReadFilter
|
filter ReadFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReader(reader io.ReadCloser, filter ReadFilter) *Reader {
|
func NewReader(reader io.Reader, filter ReadFilter) *Reader {
|
||||||
return &Reader{
|
return &Reader{
|
||||||
input: reader,
|
input: reader,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
@ -30,7 +30,3 @@ func (r *Reader) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) Close() error {
|
|
||||||
return r.input.Close()
|
|
||||||
}
|
|
||||||
|
@ -6,12 +6,11 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
"strings"
|
"strings"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewReader(t *testing.T) {
|
func TestNewReader(t *testing.T) {
|
||||||
buffer := make([]byte, 20)
|
buffer := make([]byte, 20)
|
||||||
reader := NewReader(io.NopCloser(strings.NewReader("testdata")), func(p []byte, in int, e error) (int, error) {
|
reader := NewReader(strings.NewReader("testdata"), func(p []byte, in int, e error) (int, error) {
|
||||||
copy(p, []byte("foo"))
|
copy(p, []byte("foo"))
|
||||||
return 3, nil
|
return 3, nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user