mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
refactor: migrate to new configuration system and model definitions
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
// Code generated from Pkl module `sonr.motr.DWN`. DO NOT EDIT.
|
||||
package config
|
||||
|
||||
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"`
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Code generated from Pkl module `sonr.motr.DWN`. DO NOT EDIT.
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/apple/pkl-go/pkl"
|
||||
)
|
||||
|
||||
type DWN struct {
|
||||
}
|
||||
|
||||
// LoadFromPath loads the pkl module at the given path and evaluates it into a DWN
|
||||
func LoadFromPath(ctx context.Context, path string) (ret *DWN, 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 DWN
|
||||
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*DWN, error) {
|
||||
var ret DWN
|
||||
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Code generated from Pkl module `sonr.motr.DWN`. DO NOT EDIT.
|
||||
package config
|
||||
|
||||
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"`
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// Code generated from Pkl module `sonr.motr.DWN`. DO NOT EDIT.
|
||||
package config
|
||||
|
||||
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"`
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Code generated from Pkl module `sonr.motr.DWN`. DO NOT EDIT.
|
||||
package config
|
||||
|
||||
import "github.com/apple/pkl-go/pkl"
|
||||
|
||||
func init() {
|
||||
pkl.RegisterMapping("sonr.motr.DWN", DWN{})
|
||||
pkl.RegisterMapping("sonr.motr.DWN#Config", Config{})
|
||||
pkl.RegisterMapping("sonr.motr.DWN#Schema", Schema{})
|
||||
pkl.RegisterMapping("sonr.motr.DWN#Environment", Environment{})
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
config "github.com/onsonr/sonr/pkg/config/motr"
|
||||
|
||||
"github.com/onsonr/sonr/internal/vault/types"
|
||||
"github.com/onsonr/sonr/pkg/common"
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ func Get(c echo.Context) (SessionCtx, error) {
|
||||
}
|
||||
|
||||
// WebNodeMiddleware establishes a Session Cookie.
|
||||
func Middleware(config *types.Config) echo.MiddlewareFunc {
|
||||
func Middleware(config *config.Config) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
err := injectConfig(c, config)
|
||||
@@ -46,7 +46,7 @@ func Middleware(config *types.Config) echo.MiddlewareFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func injectConfig(c echo.Context, config *types.Config) error {
|
||||
func injectConfig(c echo.Context, config *config.Config) error {
|
||||
common.HeaderWrite(c, common.SonrAPIURL, config.SonrApiUrl)
|
||||
common.HeaderWrite(c, common.SonrRPCURL, config.SonrRpcUrl)
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package config
|
||||
package embed
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ipfs/boxo/files"
|
||||
"github.com/onsonr/sonr/internal/vault/embed"
|
||||
config "github.com/onsonr/sonr/pkg/config/motr"
|
||||
)
|
||||
|
||||
const SchemaVersion = 1
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
)
|
||||
|
||||
// spawnVaultDirectory creates a new directory with the default files
|
||||
func NewVaultFS(cfg *Config) (files.Directory, error) {
|
||||
func NewVaultFS(cfg *config.Config) (files.Directory, error) {
|
||||
manifestBz, err := newWebManifestBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -29,15 +29,15 @@ func NewVaultFS(cfg *Config) (files.Directory, error) {
|
||||
return files.NewMapDirectory(map[string]files.Node{
|
||||
AppManifestFileName: files.NewBytesFile(manifestBz),
|
||||
DWNConfigFileName: files.NewBytesFile(cnfBz),
|
||||
IndexHTMLFileName: files.NewBytesFile(embed.IndexHTML),
|
||||
MainJSFileName: files.NewBytesFile(embed.MainJS),
|
||||
ServiceWorkerFileName: files.NewBytesFile(embed.WorkerJS),
|
||||
IndexHTMLFileName: files.NewBytesFile(IndexHTML),
|
||||
MainJSFileName: files.NewBytesFile(MainJS),
|
||||
ServiceWorkerFileName: files.NewBytesFile(WorkerJS),
|
||||
}), nil
|
||||
}
|
||||
|
||||
// NewVaultConfig returns the default vault config
|
||||
func NewVaultConfig(addr string, ucanCID string) *Config {
|
||||
return &Config{
|
||||
func NewVaultConfig(addr string, ucanCID string) *config.Config {
|
||||
return &config.Config{
|
||||
MotrToken: ucanCID,
|
||||
MotrAddress: addr,
|
||||
IpfsGatewayUrl: "http://localhost:80",
|
||||
@@ -1,4 +1,4 @@
|
||||
package config
|
||||
package embed
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package config
|
||||
package embed
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/onsonr/sonr/pkg/common/models"
|
||||
config "github.com/onsonr/sonr/pkg/config/motr"
|
||||
)
|
||||
|
||||
// DefaultSchema returns the default schema
|
||||
func DefaultSchema() *Schema {
|
||||
return &Schema{
|
||||
func DefaultSchema() *config.Schema {
|
||||
return &config.Schema{
|
||||
Version: SchemaVersion,
|
||||
Account: getSchema(&models.Account{}),
|
||||
Asset: getSchema(&models.Asset{}),
|
||||
Reference in New Issue
Block a user