refactor: migrate to new configuration system and model definitions

This commit is contained in:
Prad Nukala
2024-12-11 12:21:52 -05:00
parent 40f50bf37a
commit 0502f52ec0
54 changed files with 154 additions and 443 deletions
+46
View File
@@ -0,0 +1,46 @@
package config
import (
"context"
"github.com/apple/pkl-go/pkl"
hwayconfig "github.com/onsonr/sonr/pkg/config/hway"
)
// LoadFromBytes loads the environment from the given bytes
func LoadHwayFromBytes(data []byte) (hwayconfig.Hway, error) {
text := string(data)
return LoadHwayFromString(text)
}
// LoadFromString loads the environment from the given string
func LoadHwayFromString(text string) (hwayconfig.Hway, error) {
evaluator, err := pkl.NewEvaluator(context.Background(), pkl.PreconfiguredOptions)
if err != nil {
return nil, err
}
defer func() {
cerr := evaluator.Close()
if err == nil {
err = cerr
}
}()
ret, err := hwayconfig.Load(context.Background(), evaluator, pkl.TextSource(text))
return ret, err
}
// LoadFromURL loads the environment from the given URL
func LoadFromURL(url string) (hwayconfig.Hway, error) {
evaluator, err := pkl.NewEvaluator(context.Background(), pkl.PreconfiguredOptions)
if err != nil {
return nil, err
}
defer func() {
cerr := evaluator.Close()
if err == nil {
err = cerr
}
}()
ret, err := hwayconfig.Load(context.Background(), evaluator, pkl.UriSource(url))
return ret, err
}
+103
View File
@@ -0,0 +1,103 @@
// Code generated from Pkl module `sonr.conf.Hway`. DO NOT EDIT.
package hway
import (
"context"
"github.com/apple/pkl-go/pkl"
)
type Hway interface {
GetServePort() int
GetConfigDir() string
GetSqliteFile() string
GetChainId() string
GetIpfsGatewayUrl() string
GetSonrApiUrl() string
GetSonrGrpcUrl() string
GetSonrRpcUrl() string
}
var _ Hway = (*HwayImpl)(nil)
type HwayImpl struct {
ServePort int `pkl:"servePort"`
ConfigDir string `pkl:"configDir"`
SqliteFile string `pkl:"sqliteFile"`
ChainId string `pkl:"chainId"`
IpfsGatewayUrl string `pkl:"ipfsGatewayUrl"`
SonrApiUrl string `pkl:"sonrApiUrl"`
SonrGrpcUrl string `pkl:"sonrGrpcUrl"`
SonrRpcUrl string `pkl:"sonrRpcUrl"`
}
func (rcv *HwayImpl) GetServePort() int {
return rcv.ServePort
}
func (rcv *HwayImpl) GetConfigDir() string {
return rcv.ConfigDir
}
func (rcv *HwayImpl) GetSqliteFile() string {
return rcv.SqliteFile
}
func (rcv *HwayImpl) GetChainId() string {
return rcv.ChainId
}
func (rcv *HwayImpl) GetIpfsGatewayUrl() string {
return rcv.IpfsGatewayUrl
}
func (rcv *HwayImpl) GetSonrApiUrl() string {
return rcv.SonrApiUrl
}
func (rcv *HwayImpl) GetSonrGrpcUrl() string {
return rcv.SonrGrpcUrl
}
func (rcv *HwayImpl) GetSonrRpcUrl() string {
return rcv.SonrRpcUrl
}
// LoadFromPath loads the pkl module at the given path and evaluates it into a Hway
func LoadFromPath(ctx context.Context, path string) (ret Hway, err error) {
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
if err != nil {
return nil, err
}
defer func() {
cerr := evaluator.Close()
if err == nil {
err = cerr
}
}()
ret, err = Load(ctx, evaluator, pkl.FileSource(path))
return ret, err
}
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Hway
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Hway, error) {
var ret HwayImpl
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
return nil, err
}
return &ret, nil
}
+8
View File
@@ -0,0 +1,8 @@
// Code generated from Pkl module `sonr.conf.Hway`. DO NOT EDIT.
package hway
import "github.com/apple/pkl-go/pkl"
func init() {
pkl.RegisterMapping("sonr.conf.Hway", HwayImpl{})
}
+18
View File
@@ -0,0 +1,18 @@
// Code generated from Pkl module `sonr.conf.Motr`. DO NOT EDIT.
package motr
type Config struct {
IpfsGatewayUrl string `pkl:"ipfsGatewayUrl" json:"ipfsGatewayUrl,omitempty"`
MotrToken string `pkl:"motrToken" json:"motrToken,omitempty"`
MotrAddress string `pkl:"motrAddress" json:"motrAddress,omitempty"`
SonrApiUrl string `pkl:"sonrApiUrl" json:"sonrApiUrl,omitempty"`
SonrRpcUrl string `pkl:"sonrRpcUrl" json:"sonrRpcUrl,omitempty"`
SonrChainId string `pkl:"sonrChainId" json:"sonrChainId,omitempty"`
VaultSchema *Schema `pkl:"vaultSchema" json:"vaultSchema,omitempty"`
}
+14
View File
@@ -0,0 +1,14 @@
// Code generated from Pkl module `sonr.conf.Motr`. DO NOT EDIT.
package motr
type Environment struct {
IsDevelopment bool `pkl:"isDevelopment" json:"isDevelopment,omitempty"`
CacheVersion string `pkl:"cacheVersion" json:"cacheVersion,omitempty"`
HttpserverPath string `pkl:"httpserverPath" json:"httpserverPath,omitempty"`
WasmExecPath string `pkl:"wasmExecPath" json:"wasmExecPath,omitempty"`
WasmPath string `pkl:"wasmPath" json:"wasmPath,omitempty"`
}
+36
View File
@@ -0,0 +1,36 @@
// Code generated from Pkl module `sonr.conf.Motr`. DO NOT EDIT.
package motr
import (
"context"
"github.com/apple/pkl-go/pkl"
)
type Motr struct {
}
// LoadFromPath loads the pkl module at the given path and evaluates it into a Motr
func LoadFromPath(ctx context.Context, path string) (ret *Motr, err error) {
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
if err != nil {
return nil, err
}
defer func() {
cerr := evaluator.Close()
if err == nil {
err = cerr
}
}()
ret, err = Load(ctx, evaluator, pkl.FileSource(path))
return ret, err
}
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Motr
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Motr, error) {
var ret Motr
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
return nil, err
}
return &ret, nil
}
+22
View File
@@ -0,0 +1,22 @@
// Code generated from Pkl module `sonr.conf.Motr`. DO NOT EDIT.
package motr
type Schema struct {
Version int `pkl:"version"`
Account string `pkl:"account" json:"account,omitempty"`
Asset string `pkl:"asset" json:"asset,omitempty"`
Chain string `pkl:"chain" json:"chain,omitempty"`
Credential string `pkl:"credential" json:"credential,omitempty"`
Jwk string `pkl:"jwk" json:"jwk,omitempty"`
Grant string `pkl:"grant" json:"grant,omitempty"`
Keyshare string `pkl:"keyshare" json:"keyshare,omitempty"`
Profile string `pkl:"profile" json:"profile,omitempty"`
}
+11
View File
@@ -0,0 +1,11 @@
// Code generated from Pkl module `sonr.conf.Motr`. DO NOT EDIT.
package motr
import "github.com/apple/pkl-go/pkl"
func init() {
pkl.RegisterMapping("sonr.conf.Motr", Motr{})
pkl.RegisterMapping("sonr.conf.Motr#Config", Config{})
pkl.RegisterMapping("sonr.conf.Motr#Schema", Schema{})
pkl.RegisterMapping("sonr.conf.Motr#Environment", Environment{})
}