From 112934a87243aa5e3e7b3a6b85a23288bd88a1c0 Mon Sep 17 00:00:00 2001 From: Aaron Stein Date: Mon, 23 Apr 2018 10:55:01 -0700 Subject: [PATCH] Parse provider attributes from yaml file fixes #183 --- _docs/attributes.yaml | 4 ++++ _integration/attributes.yaml | 4 ++++ _integration/cmp/provider.go | 2 +- cmd/akash/provider.go | 23 +++++++++++++++-------- glide.yaml | 3 +++ 5 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 _docs/attributes.yaml create mode 100644 _integration/attributes.yaml diff --git a/_docs/attributes.yaml b/_docs/attributes.yaml new file mode 100644 index 0000000000..4e0c800da3 --- /dev/null +++ b/_docs/attributes.yaml @@ -0,0 +1,4 @@ +- name: region + value: us-west +- name: tier + value: "5" diff --git a/_integration/attributes.yaml b/_integration/attributes.yaml new file mode 100644 index 0000000000..4e0c800da3 --- /dev/null +++ b/_integration/attributes.yaml @@ -0,0 +1,4 @@ +- name: region + value: us-west +- name: tier + value: "5" diff --git a/_integration/cmp/provider.go b/_integration/cmp/provider.go index 53669fa56d..e546811ca1 100644 --- a/_integration/cmp/provider.go +++ b/_integration/cmp/provider.go @@ -14,7 +14,7 @@ func providerCreate(root vars.Ref, key vars.Ref, paddr vars.Ref) gestalt.Compone return g.Group("provider-create"). Run( - akash_(root, "create", "provider", "create", "unused.yml", "-k", key.Name()). + akash_(root, "create", "provider", "create", "attributes.yaml", "-k", key.Name()). FN(g.Capture(paddr.Name())). WithMeta(g.Export(paddr.Name()))). Run(g.Retry(5).Run(check)). diff --git a/cmd/akash/provider.go b/cmd/akash/provider.go index b53af004ea..50f196010e 100644 --- a/cmd/akash/provider.go +++ b/cmd/akash/provider.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "io/ioutil" "math/rand" "strconv" @@ -14,12 +15,12 @@ import ( "github.com/ovrclk/akash/marketplace" qp "github.com/ovrclk/akash/query" "github.com/ovrclk/akash/state" - "github.com/ovrclk/akash/testutil" "github.com/ovrclk/akash/txutil" "github.com/ovrclk/akash/types" "github.com/ovrclk/akash/types/base" . "github.com/ovrclk/akash/util" "github.com/spf13/cobra" + "gopkg.in/yaml.v2" ) func providerCommand() *cobra.Command { @@ -101,7 +102,7 @@ func doCreateProviderCommand(ctx context.Context, cmd *cobra.Command, args []str tx, err := txutil.BuildTx(signer, nonce, &types.TxCreateProvider{ Owner: key.Address(), - Attributes: attributes, + Attributes: *attributes, Nonce: nonce, }) if err != nil { @@ -126,14 +127,20 @@ func doCreateProviderCommand(ctx context.Context, cmd *cobra.Command, args []str return nil } -func parseProvider(file string, nonce uint64) ([]types.ProviderAttribute, error) { - // todo: read and parse deployment yaml file +func parseProvider(file string, nonce uint64) (*[]types.ProviderAttribute, error) { - /* begin stub data */ - provider := testutil.Provider(*new(base.Bytes), nonce) - /* end stub data */ + contents, err := ioutil.ReadFile(file) + if err != nil { + return nil, err + } + + attributes := &[]types.ProviderAttribute{} + err = yaml.Unmarshal([]byte(contents), attributes) + if err != nil { + return nil, err + } - return provider.Attributes, nil + return attributes, nil } func runCommand() *cobra.Command { diff --git a/glide.yaml b/glide.yaml index 8fd8687b46..0788727ca5 100644 --- a/glide.yaml +++ b/glide.yaml @@ -34,3 +34,6 @@ import: - require - assert - mock + +- package: gopkg.in/yaml.v2 + version: v2.2.1