Skip to content

Commit

Permalink
feat: explicit spec environment
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Jan 7, 2025
1 parent dd540fc commit b1433c7
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Try a basic HTTP request handler using [ping.yaml](./examples/ping.yaml):
out:
- name: router
port: in
env:
PORT:
- data: '{{ .PORT }}'

- kind: router
name: router
Expand Down
3 changes: 3 additions & 0 deletions README_kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ make build
out:
- name: router
port: in
env:
PORT:
- data: "{{ .PORT }}"

- kind: router
name: router
Expand Down
3 changes: 3 additions & 0 deletions examples/helloworld.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
init:
- name: hello_world
port: in
env:
PORT:
- data: '{{ .PORT }}'

- kind: step
name: good_bye
Expand Down
3 changes: 3 additions & 0 deletions examples/httpproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
out:
- name: proxy
port: in
env:
PORT:
- data: '{{ .PORT }}'

- kind: http
name: proxy
Expand Down
3 changes: 3 additions & 0 deletions examples/loopback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
out:
- name: loopback
port: in
env:
PORT:
- data: '{{ .PORT }}'

- kind: snippet
name: loopback
Expand Down
3 changes: 3 additions & 0 deletions examples/ping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
out:
- name: router
port: in
env:
PORT:
- data: '{{ .PORT }}'

- kind: router
name: router
Expand Down
3 changes: 3 additions & 0 deletions examples/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
error:
- name: catch
port: in
env:
PORT:
- data: '{{ .PORT }}'

- kind: router
name: router
Expand Down
3 changes: 3 additions & 0 deletions examples/wsproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
out:
- name: router
port: in
env:
PORT:
- data: '{{ .PORT }}'

- kind: router
name: router
Expand Down
30 changes: 6 additions & 24 deletions pkg/symbol/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package symbol
import (
"context"
"errors"
"github.com/iancoleman/strcase"
"reflect"

"github.com/iancoleman/strcase"
"github.com/siyul-park/uniflow/pkg/resource"
"github.com/siyul-park/uniflow/pkg/scheme"
"github.com/siyul-park/uniflow/pkg/spec"
Expand All @@ -32,8 +32,12 @@ type Loader struct {

// NewLoader creates a new Loader instance with the provided configuration.
func NewLoader(config LoaderConfig) *Loader {
env := map[string]string{}
for k, v := range config.Environment {
env[strcase.ToScreamingSnake(k)] = v
}
return &Loader{
environment: config.Environment,
environment: env,
table: config.Table,
scheme: config.Scheme,
specStore: config.SpecStore,
Expand All @@ -50,28 +54,6 @@ func (l *Loader) Load(ctx context.Context, specs ...spec.Spec) error {
return err
}

for i, sp := range specs {
unstructured := &spec.Unstructured{}
if err := spec.As(sp, unstructured); err != nil {
return err
}

env := unstructured.GetEnv()
if env == nil {
env = map[string][]spec.Value{}
}

for k, v := range l.environment {
k = strcase.ToScreamingSnake(k)
if _, ok := env[k]; !ok {
env[k] = append(env[k], spec.Value{Data: v})
}
}

unstructured.SetEnv(env)
specs[i] = unstructured
}

var values []*value.Value
for _, sp := range specs {
for _, vals := range sp.GetEnv() {
Expand Down

0 comments on commit b1433c7

Please sign in to comment.