Skip to content

Commit

Permalink
Parse provider attributes from yaml file
Browse files Browse the repository at this point in the history
fixes #183
  • Loading branch information
aastein authored Apr 23, 2018
1 parent 2c45ebb commit 112934a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions _docs/attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: region
value: us-west
- name: tier
value: "5"
4 changes: 4 additions & 0 deletions _integration/attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: region
value: us-west
- name: tier
value: "5"
2 changes: 1 addition & 1 deletion _integration/cmp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
23 changes: 15 additions & 8 deletions cmd/akash/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"strconv"

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ import:
- require
- assert
- mock

- package: gopkg.in/yaml.v2
version: v2.2.1

0 comments on commit 112934a

Please sign in to comment.