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

First step of simplifaction of task output - update importer package #963

Merged
merged 13 commits into from
May 20, 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
2 changes: 1 addition & 1 deletion api/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestDeployInvalidService(t *testing.T) {

func TestDeployServiceFromURL(t *testing.T) {
var (
url = "https://github.com/mesg-foundation/service-webhook.git"
url = "git://github.com/mesg-foundation/service-webhook#single-outputs"
a, at = newTesting(t)
)
defer at.close()
Expand Down
35 changes: 15 additions & 20 deletions api/inject_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,22 @@ func defTasksToService(tasks map[string]*importer.Task) []*service.Task {
return ts
}

func defOutputsToService(outputs map[string]*importer.Output) []*service.Output {
var (
keys []string
ots = make([]*service.Output, len(outputs))
)

for key := range outputs {
keys = append(keys, key)
}
sort.Strings(keys)

for key, output := range outputs {
i := xstrings.SliceIndex(keys, key)
ots[i] = &service.Output{
Key: key,
Name: output.Name,
Description: output.Description,
Data: defParametersToService(output.Data),
}
func defOutputsToService(outputs map[string]*importer.Parameter) []*service.Output {
return []*service.Output{
{
Key: "success",
Data: defParametersToService(outputs),
},
{
Key: "error",
Data: []*service.Parameter{
{
Key: "message",
Type: "String",
},
},
},
}
return ots
}

func defEventsToService(events map[string]*importer.Event) []*service.Event {
Expand Down
2 changes: 1 addition & 1 deletion interface/grpc/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestGetService(t *testing.T) {
}

func TestListServices(t *testing.T) {
url := "https://github.com/mesg-foundation/service-webhook"
url := "git://github.com/mesg-foundation/service-webhook#single-outputs"
server, closer := newServer(t)
defer closer()

Expand Down
2 changes: 1 addition & 1 deletion interface/grpc/core/deploy_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestIntegrationDeployService(t *testing.T) {
url := "https://github.com/mesg-foundation/service-webhook"
url := "git://github.com/mesg-foundation/service-webhook#single-outputs"

server, closer := newServer(t)
defer closer()
Expand Down
2 changes: 1 addition & 1 deletion interface/grpc/core/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestDeployService(t *testing.T) {
url := "https://github.com/mesg-foundation/service-webhook"
url := "git://github.com/mesg-foundation/service-webhook#single-outputs"

server, dt, closer := newServerAndDockerTest(t)
defer closer()
Expand Down
4 changes: 2 additions & 2 deletions interface/grpc/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestSubmit(t *testing.T) {
"data": map[string]interface{}{},
"headers": map[string]interface{}{},
}
outputKey = "result"
outputKey = "success"
outputData = `{"foo":{}}`
server, closer = newServer(t)
)
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestSubmitWithInvalidTaskOutputs(t *testing.T) {
"data": map[string]interface{}{},
"headers": map[string]interface{}{},
}
outputKey = "result"
outputKey = "success"
outputData = `{"foo":1}`
server, closer = newServer(t)
)
Expand Down
6 changes: 2 additions & 4 deletions service-test/env/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ tasks:
bar:
type: String
outputs:
bar:
data:
baz:
type: Object
baz:
type: Object
6 changes: 2 additions & 4 deletions service-test/task/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ tasks:
headers:
type: Object
outputs:
result:
data:
foo:
type: Object
foo:
type: Object
14 changes: 1 addition & 13 deletions service/importer/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,7 @@ type Task struct {
Inputs map[string]*Parameter `yaml:"inputs" json:"inputs,omitempty" validate:"dive,keys,printascii,endkeys,required"`

// Outputs are the definition of the execution results of task.
Outputs map[string]*Output `yaml:"outputs" json:"outputs,omitempty" validate:"required,dive,keys,printascii,endkeys,required"`
}

// Output describes task output.
type Output struct {
// Name is the name of task output.
Name string `yaml:"name" json:"name,omitempty" validate:"printascii"`

// Description is the description of task output.
Description string `yaml:"description" json:"description,omitempty" validate:"printascii"`

// Data holds the output parameters of a task output.
Data map[string]*Parameter `yaml:"data" json:"data,omitempty" validate:"required,dive,keys,printascii,endkeys,required"`
Outputs map[string]*Parameter `yaml:"outputs" json:"outputs,omitempty" validate:"dive,keys,printascii,endkeys,required"`
}

// Parameter describes task input parameters, output parameters of a task
Expand Down
12 changes: 5 additions & 7 deletions service/importer/tests/service-docker-missing/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ tasks:
argB:
type: String
outputs:
outputX:
data:
resX:
type: String
resY:
type: String
resX:
type: String
resY:
type: String
dependencies:
app:
image: my-docker-image
image: my-docker-image
25 changes: 11 additions & 14 deletions service/importer/tests/service-names-valid/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ events:
type: String

tasks:
Name1-_:
inputs:
Name1-_:
name: "name"
type: String

outputs:
Name1-_:
name: "name"
data:
Name1-_:
name: "name"
type: String
Name1-_:
inputs:
Name1-_:
name: "name"
type: String

outputs:
Name1-_:
name: "name"
type: String

dependencies:
Name1-_:
image: nginx
image: nginx
12 changes: 5 additions & 7 deletions service/importer/tests/service-valid/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ tasks:
argB:
type: String
outputs:
outputX:
data:
resX:
type: String
resY:
type: String
resX:
type: String
resY:
type: String
dependencies:
app:
image: my-docker-image
ports:
- 80:80
- 80:80
10 changes: 4 additions & 6 deletions service/importer/tests/sid-too-long/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ tasks:
argB:
type: String
outputs:
outputX:
data:
resX:
type: String
resY:
type: String
resX:
type: String
resY:
type: String
dependencies:
app:
image: my-docker-image
102 changes: 30 additions & 72 deletions systemservices/ethwallet/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,11 @@ tasks:
name: "List accounts"
description: "Return the addresses of existing account."
outputs:
success:
name: "Success"
description: "Output when the task executes successfully."
data:
addresses:
name: "Addresses"
description: "List of addresses."
type: String
repeated: true
error: &outputError
name: "Error"
description: "Output when an error occurs."
data:
message:
name: "Message"
description: "The error message."
type: String
addresses:
name: "Addresses"
description: "List of addresses."
type: String
repeated: true
create:
name: "Create a new account"
description: "Create a new account with a passphrase. Make sure to backup the passphrase."
Expand All @@ -37,53 +25,38 @@ tasks:
description: "Passphrase to use with the account."
type: String
outputs:
success:
name: "Success"
description: "Output when the task executes successfully."
data:
address: &address
name: "Address"
description: "The public address of the account."
type: String
error: *outputError
address: &address
name: "Address"
description: "The public address of the account."
type: String
delete:
name: "Delete an account"
description: "Delete an account from the wallet. Need the address and its associated passphrase."
inputs:
address: *address
passphrase: *passphrase
outputs:
success:
name: "Success"
description: "Output when the task executes successfully."
data:
address: *address
error: *outputError
address: *address
export:
name: "Export an account"
description: "Export an existing account in order to backup it and import it in an other wallet. Respect the Web3 Secret Storage specification. See https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition for more information."
inputs:
address: *address
passphrase: *passphrase
outputs:
success:
name: "Success"
description: "Output when the task executes successfully."
data: &account
address: *address
id:
name: "ID"
description: "The id of the account."
type: String
version:
name: "Version"
description: "The version used to export the account."
type: Number
crypto:
name: "Crypto"
description: "The encrypted account."
type: Object
error: *outputError
outputs: &account
address: *address
id:
name: "ID"
description: "The id of the account."
type: String
version:
name: "Version"
description: "The version used to export the account."
type: Number
crypto:
name: "Crypto"
description: "The encrypted account."
type: Object
import:
name: "Import an account"
description: "Import an account. The account have to respect the Web3 Secret Storage specification. See https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition for more information."
Expand All @@ -95,12 +68,7 @@ tasks:
object: *account
passphrase: *passphrase
outputs:
success:
name: "Success"
description: "Output when the task executes successfully."
data:
address: *address
error: *outputError
address: *address
sign:
name: "Sign transaction"
description: "Sign a transaction with the specified account."
Expand Down Expand Up @@ -141,15 +109,10 @@ tasks:
description: "The data of the transaction."
type: String
outputs:
success:
name: "Success"
description: "Output when the task executes successfully."
data:
signedTransaction:
name: "Signed transaction"
description: "The signed transaction."
type: String
error: *outputError
signedTransaction:
name: "Signed transaction"
description: "The signed transaction."
type: String
importFromPrivateKey:
name: "Import an account from a private key"
description: "Import an account from a private key."
Expand All @@ -160,9 +123,4 @@ tasks:
type: String
passphrase: *passphrase
outputs:
success:
name: "Success"
description: "Output when the task executes successfully."
data:
address: *address
error: *outputError
address: *address
Loading