From afd23809a1b46a527b369ae1a7726841ab876fc8 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Mon, 8 Apr 2019 22:40:51 +1000 Subject: [PATCH 1/3] use raw data to send to the marketplace --- commands/marketplace_publish.go | 29 +++++++++++++------------- commands/provider/marketplace_types.go | 12 +++++------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/commands/marketplace_publish.go b/commands/marketplace_publish.go index 9eec25206..b8e46b690 100644 --- a/commands/marketplace_publish.go +++ b/commands/marketplace_publish.go @@ -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" @@ -19,9 +19,8 @@ const ( type marketplacePublishCmd struct { baseMarketplaceCmd - path string - sid string - hash string + path string + service *coreapi.Service e Executor } @@ -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.Sid), pretty.Success(c.service.Hash)) 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.Sid, c.path, c.account), }, &confirmed, nil); err != nil { return err } @@ -81,18 +84,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() { tx, err = c.e.PublishServiceVersion(provider.MarketplaceManifestServiceData{ - Definition: *definition, - Hash: c.hash, + Definition: c.service, + Hash: c.service.Hash, HashVersion: marketplaceServiceHashVersion, Readme: readme, Deployment: deployment, @@ -106,9 +105,9 @@ func (c *marketplacePublishCmd) runE(cmd *cobra.Command, args []string) error { return err } fmt.Printf("%s Service published with success\n", pretty.SuccessSign) - fmt.Printf("%s See it on the marketplace: https://marketplace.mesg.com/services/%s\n", pretty.SuccessSign, c.sid) + fmt.Printf("%s See it on the marketplace: https://marketplace.mesg.com/services/%s\n", pretty.SuccessSign, c.service.Sid) - fmt.Printf("%s To create a service offer, execute the command:\n\tmesg-core marketplace create-offer %s\n", pretty.SuccessSign, c.sid) + fmt.Printf("%s To create a service offer, execute the command:\n\tmesg-core marketplace create-offer %s\n", pretty.SuccessSign, c.service.Sid) return nil } diff --git a/commands/provider/marketplace_types.go b/commands/provider/marketplace_types.go index c34f00994..16348d9ff 100644 --- a/commands/provider/marketplace_types.go +++ b/commands/provider/marketplace_types.go @@ -3,7 +3,7 @@ package provider import ( "encoding/json" - "github.com/mesg-foundation/core/service/importer" + "github.com/mesg-foundation/core/protobuf/coreapi" ) const ( @@ -54,11 +54,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 *coreapi.Service `json:"definition"` + Readme string `json:"readme,omitempty"` + Hash string `json:"hash"` + HashVersion string `json:"hashVersion"` + Deployment MarketplaceDeployedSource `json:"deployment"` } // MarketplaceManifestData struct { From 9b653074a5ae12808b91807134d366e0da2aef1f Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Mon, 8 Apr 2019 23:38:10 +1000 Subject: [PATCH 2/3] commit service definition on the marketplace --- commands/marketplace_publish.go | 12 ++++++------ commands/provider/marketplace_types.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/commands/marketplace_publish.go b/commands/marketplace_publish.go index b8e46b690..f51ea0f90 100644 --- a/commands/marketplace_publish.go +++ b/commands/marketplace_publish.go @@ -55,11 +55,11 @@ func (c *marketplacePublishCmd) preRunE(cmd *cobra.Command, args []string) error if err != nil { return err } - fmt.Printf("%s Service deployed with sid %s and hash %s\n", pretty.SuccessSign, pretty.Success(c.service.Sid), pretty.Success(c.service.Hash)) + 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)) 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.service.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 } @@ -90,8 +90,8 @@ func (c *marketplacePublishCmd) runE(cmd *cobra.Command, args []string) error { } pretty.Progress("Publishing service on the marketplace...", func() { tx, err = c.e.PublishServiceVersion(provider.MarketplaceManifestServiceData{ - Definition: c.service, - Hash: c.service.Hash, + Definition: c.service.Definition, + Hash: c.service.Definition.Hash, HashVersion: marketplaceServiceHashVersion, Readme: readme, Deployment: deployment, @@ -105,9 +105,9 @@ func (c *marketplacePublishCmd) runE(cmd *cobra.Command, args []string) error { return err } fmt.Printf("%s Service published with success\n", pretty.SuccessSign) - fmt.Printf("%s See it on the marketplace: https://marketplace.mesg.com/services/%s\n", pretty.SuccessSign, c.service.Sid) + fmt.Printf("%s See it on the marketplace: https://marketplace.mesg.com/services/%s\n", pretty.SuccessSign, c.service.Definition.Sid) - fmt.Printf("%s To create a service offer, execute the command:\n\tmesg-core marketplace create-offer %s\n", pretty.SuccessSign, c.service.Sid) + fmt.Printf("%s To create a service offer, execute the command:\n\tmesg-core marketplace create-offer %s\n", pretty.SuccessSign, c.service.Definition.Sid) return nil } diff --git a/commands/provider/marketplace_types.go b/commands/provider/marketplace_types.go index 16348d9ff..2975b6dbe 100644 --- a/commands/provider/marketplace_types.go +++ b/commands/provider/marketplace_types.go @@ -3,7 +3,7 @@ package provider import ( "encoding/json" - "github.com/mesg-foundation/core/protobuf/coreapi" + "github.com/mesg-foundation/core/protobuf/definition" ) const ( @@ -54,7 +54,7 @@ type MarketplaceDeployedSource struct { // MarketplaceManifestServiceData is the data present to the manifest and sent to create a new service's version type MarketplaceManifestServiceData struct { - Definition *coreapi.Service `json:"definition"` + Definition *definition.Service `json:"definition"` Readme string `json:"readme,omitempty"` Hash string `json:"hash"` HashVersion string `json:"hashVersion"` From 05ba84e52817a7e649edb98828c2c3fb55effbb9 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Tue, 9 Apr 2019 20:59:04 +1000 Subject: [PATCH 3/3] remove wrong commit --- xxx-service/.dockerignore | 1 - xxx-service/.gitignore | 1 - xxx-service/Dockerfile | 6 ------ xxx-service/index.js | 11 ----------- xxx-service/mesg.yml | 24 ------------------------ xxx-service/package.json | 8 -------- xxx-service/tasks/taskX.js | 7 ------- 7 files changed, 58 deletions(-) delete mode 100644 xxx-service/.dockerignore delete mode 100644 xxx-service/.gitignore delete mode 100644 xxx-service/Dockerfile delete mode 100644 xxx-service/index.js delete mode 100644 xxx-service/mesg.yml delete mode 100644 xxx-service/package.json delete mode 100644 xxx-service/tasks/taskX.js diff --git a/xxx-service/.dockerignore b/xxx-service/.dockerignore deleted file mode 100644 index 3c3629e64..000000000 --- a/xxx-service/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/xxx-service/.gitignore b/xxx-service/.gitignore deleted file mode 100644 index 3c3629e64..000000000 --- a/xxx-service/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/xxx-service/Dockerfile b/xxx-service/Dockerfile deleted file mode 100644 index 3ce62ef34..000000000 --- a/xxx-service/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM node:10.15 -WORKDIR /app -COPY ./package* ./ -RUN npm install -COPY . . -CMD [ "node", "index.js" ] diff --git a/xxx-service/index.js b/xxx-service/index.js deleted file mode 100644 index 3ba50d467..000000000 --- a/xxx-service/index.js +++ /dev/null @@ -1,11 +0,0 @@ -const mesg = require('mesg-js').service() - -mesg.listenTask({ - taskX: require('./tasks/taskX') -}) - .on('error', (error) => console.error(error)) - -mesg.emitEvent('started', { x: true }) - .catch((error) => console.error(error)) - -console.log('gnarf gnarf') diff --git a/xxx-service/mesg.yml b/xxx-service/mesg.yml deleted file mode 100644 index db47f6da3..000000000 --- a/xxx-service/mesg.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: myservice -sid: myservice -description: "Description of my service" -tasks: - taskX: - inputs: - foo: - type: String - bar: - type: String - outputs: - success: - data: - message: - type: String - error: - data: - error: - type: String -events: - started: - data: - x: - type: Boolean diff --git a/xxx-service/package.json b/xxx-service/package.json deleted file mode 100644 index c26252831..000000000 --- a/xxx-service/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "your-package-name", - "version": "1.0.0", - "main": "index.js", - "dependencies": { - "mesg-js": "^2.0.0" - } -} diff --git a/xxx-service/tasks/taskX.js b/xxx-service/tasks/taskX.js deleted file mode 100644 index 58045b94f..000000000 --- a/xxx-service/tasks/taskX.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = ({ foo, bar }, { success, error }) => { - if (foo === 'hello' && bar === 'world') { - success({ message: 'Hello world is valid' }) - } else { - error({ error: 'invalid inputs' }) - } -}