Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marketplace publish service raw data #845

Merged
merged 6 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions commands/marketplace_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/mesg-foundation/core/commands/provider"
"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/protobuf/coreapi"
"github.com/mesg-foundation/core/utils/pretty"
"github.com/mesg-foundation/core/utils/readme"
"github.com/spf13/cobra"
Expand All @@ -19,9 +19,8 @@ const (
type marketplacePublishCmd struct {
baseMarketplaceCmd

path string
sid string
hash string
path string
service *coreapi.Service

e Executor
}
Expand All @@ -48,15 +47,19 @@ func (c *marketplacePublishCmd) preRunE(cmd *cobra.Command, args []string) error
c.path = getFirstOrCurrentPath(args)

var err error
c.sid, c.hash, err = deployService(c.e, c.path, map[string]string{})
_, hash, err := deployService(c.e, c.path, map[string]string{})
if err != nil {
return err
}
fmt.Printf("%s Service deployed with sid %s and hash %s\n", pretty.SuccessSign, pretty.Success(c.sid), pretty.Success(c.hash))
c.service, err = c.e.ServiceByID(hash)
if err != nil {
return err
}
fmt.Printf("%s Service deployed with sid %s and hash %s\n", pretty.SuccessSign, pretty.Success(c.service.Definition.Sid), pretty.Success(c.service.Definition.Hash))
Copy link
Contributor

@ilgooz ilgooz Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be better to explicitly use hash got from deployService() here. because in future, we'll make service sids to have one-to-many relationships with service hashes.

thus, ServiceByID() may return multiple versions and maybe in desc order on deploy time but it's not guaranteed that the first hash in the array will be belong to the last publish because two publish commands may run in parallel for the different versions of same service.

Copy link
Contributor

@ilgooz ilgooz Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ServiceByID(**sid**) is only going to return the last service version and ServiceByID(**hash**) will only return the same version with hash, then all ok.

Copy link
Contributor

@ilgooz ilgooz Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway, we're also using c.service.Definition so we have to make this call. let's make sure that ServiceByID(hash) will return the version for hash in future too and ServiceByID(sid) may return the latest hash.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ServiceByID(**sid**) is only going to return the last service version and ServiceByID(**hash**) will only return the same version with hash, then all ok.

Yeah, that's the case.

anyway, we're also using c.service.Definition so we have to make this call. let's make sure that ServiceByID(hash) will return the version for hash in future too and ServiceByID(sid) may return the latest hash.

Yep


var confirmed bool
if err := survey.AskOne(&survey.Confirm{
Message: fmt.Sprintf("Are you sure to publish a new version of service %q from path %q using account %q?", c.sid, c.path, c.account),
Message: fmt.Sprintf("Are you sure to publish a new version of service %q from path %q using account %q?", c.service.Definition.Sid, c.path, c.account),
}, &confirmed, nil); err != nil {
return err
}
Expand All @@ -83,18 +86,14 @@ func (c *marketplacePublishCmd) runE(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
definition, err := importer.From(c.path)
if err != nil {
return err
}
readme, err := readme.Lookup(c.path)
if err != nil {
return err
}
pretty.Progress("Publishing service on the marketplace...", func() {
if tx, err = c.e.PreparePublishServiceVersion(provider.MarketplaceManifestServiceData{
Definition: *definition,
Hash: c.hash,
Definition: c.service.Definition,
Hash: c.service.Definition.Hash,
HashVersion: marketplaceServiceHashVersion,
Readme: readme,
Deployment: deployment,
Expand Down
12 changes: 6 additions & 6 deletions commands/provider/marketplace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"time"

"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/protobuf/definition"
)

const (
Expand Down Expand Up @@ -55,11 +55,11 @@ type MarketplaceDeployedSource struct {

// MarketplaceManifestServiceData is the data present to the manifest and sent to create a new service's version
type MarketplaceManifestServiceData struct {
Definition importer.ServiceDefinition `json:"definition"`
Readme string `json:"readme,omitempty"`
Hash string `json:"hash"`
HashVersion string `json:"hashVersion"`
Deployment MarketplaceDeployedSource `json:"deployment"`
Definition *definition.Service `json:"definition"`
Readme string `json:"readme,omitempty"`
Hash string `json:"hash"`
HashVersion string `json:"hashVersion"`
Deployment MarketplaceDeployedSource `json:"deployment"`
}

// MarketplaceManifestData struct {
Expand Down