Skip to content

Commit

Permalink
refactor: migrate to new configuration system and model definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
prnk28 committed Dec 11, 2024
1 parent 40f50bf commit 0502f52
Show file tree
Hide file tree
Showing 54 changed files with 155 additions and 444 deletions.
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,13 @@ sh-testnet: mod-tidy
###############################################################################
.PHONY: gen-pkl gen-templ

gen-pkl:
go install github.com/apple/pkl-go/cmd/pkl-gen-go@latest
pkl-gen-go pkl/sonr.motr/ATN.pkl
pkl-gen-go pkl/sonr.hway/Env.pkl
pkl-gen-go pkl/sonr.motr/DWN.pkl
pkl-gen-go pkl/sonr.hway/ORM.pkl

gen-templ:
@go install github.com/a-h/templ/cmd/templ@latest
gen-pkl: init-env
pkl-gen-go pkl/sonr.orm/UCAN.pkl
pkl-gen-go pkl/sonr.orm/Models.pkl
pkl-gen-go pkl/sonr.conf/Hway.pkl
pkl-gen-go pkl/sonr.conf/Motr.pkl

gen-templ: init-env
templ generate


Expand Down
8 changes: 4 additions & 4 deletions cmd/hway/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/labstack/echo/v4/middleware"
"github.com/onsonr/sonr/crypto/ucan"
"github.com/onsonr/sonr/internal/gateway"
"github.com/onsonr/sonr/internal/gateway/config"
"github.com/onsonr/sonr/pkg/common/ipfs"
config "github.com/onsonr/sonr/pkg/config/hway"
"github.com/onsonr/sonr/pkg/database/sessions"
"github.com/onsonr/sonr/pkg/didauth/producer"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -60,13 +60,13 @@ func rootCmd() *cobra.Command {
return cmd
}

func loadEnvImplFromArgs(args []string) (config.Env, error) {
func loadEnvImplFromArgs(args []string) (config.Hway, error) {
cmd := rootCmd()
if err := cmd.ParseFlags(args); err != nil {
return nil, err
}

env := &config.EnvImpl{
env := &config.HwayImpl{
ServePort: servePort,
ConfigDir: configDir,
SqliteFile: sqliteFile,
Expand All @@ -80,7 +80,7 @@ func loadEnvImplFromArgs(args []string) (config.Env, error) {
}

// setupServer sets up the server
func setupServer(env config.Env) (*echo.Echo, error) {
func setupServer(env config.Hway) (*echo.Echo, error) {
ipc, err := ipfs.NewClient()
if err != nil {
return nil, err
Expand Down
14 changes: 7 additions & 7 deletions crypto/ucan/attns/ATN.pkl.go → crypto/ucan/attns/UCAN.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crypto/ucan/attns/capability/Capability.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crypto/ucan/attns/init.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crypto/ucan/attns/policytype/PolicyType.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crypto/ucan/attns/resourcetype/ResourceType.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions internal/gateway/config/init.pkl.go

This file was deleted.

11 changes: 0 additions & 11 deletions internal/vault/config/init.pkl.go

This file was deleted.

6 changes: 3 additions & 3 deletions internal/vault/context/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand All @@ -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)

Expand Down
16 changes: 8 additions & 8 deletions internal/vault/config/fs.go → internal/vault/embed/fs.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package embed

import "encoding/json"

Expand Down
Original file line number Diff line number Diff line change
@@ -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{}),
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/models/Account.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/Asset.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/Chain.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/Credential.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/DID.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/Grant.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/JWK.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/Keyshare.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/common/models/ORM.pkl.go → pkg/common/models/Models.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/Profile.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/assettype/AssetType.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/didmethod/DIDMethod.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions pkg/common/models/init.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/keyalgorithm/KeyAlgorithm.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/keycurve/KeyCurve.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/keyencoding/KeyEncoding.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/common/models/keyrole/KeyRole.pkl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0502f52

Please sign in to comment.