Skip to content
Open
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
57 changes: 4 additions & 53 deletions cmd/device-hub-cli/cmd_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,23 @@
package main

import (
"context"
"strings"

"github.com/fiorix/protoc-gen-cobra/iocodec"
"github.com/spf13/cobra"
"github.com/thingful/device-hub/describe"
"github.com/thingful/device-hub/endpoint"
"github.com/thingful/device-hub/listener"
"github.com/thingful/device-hub/proto"
"github.com/thingful/device-hub/registry"
)

var createCommand = &cobra.Command{
Use: "create",
Short: "Create listener, endpoint and profile resources",
RunE: func(cmd *cobra.Command, args []string) error {

/* TODO : add ability to generate examples */
sample := proto.CreateRequest{
Configuration: map[string]string{},
}

err := roundTrip(sample, func(cli proto.HubClient, in iocodec.Decoder, out iocodec.Encoder) error {

v := proto.CreateRequest{}

err := in.Decode(&v)
for _, r := range _resources.R {
err := r.SendCreate()

if err != nil {
return err
}

// validate the policy file before sending it over the wire
var params describe.Parameters

register := registry.Default

endpoint.Register(register)
listener.Register(register)

switch strings.ToLower(v.Type) {

case "listener":
params, err = register.DescribeListener(v.Kind)
case "endpoint":
params, err = register.DescribeEndpoint(v.Kind)
}

if err != nil {
return err
}

_, err = describe.NewValues(v.Configuration, params)

if err != nil {
return err
}
resp, err := cli.Create(context.Background(), &v)

if err != nil {
return err
}

return out.Encode(resp)
}

})
return err
return nil
},
}
32 changes: 9 additions & 23 deletions cmd/device-hub-cli/cmd_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,26 @@
package main

import (
"context"

"github.com/fiorix/protoc-gen-cobra/iocodec"
"github.com/spf13/cobra"
"github.com/thingful/device-hub/proto"
)

var deleteCommand = &cobra.Command{
Use: "delete",
Short: "Delete listener, profile and endpoint resources",
RunE: func(cmd *cobra.Command, args []string) error {
var uri string
if len(args) > 0 {
uri = args[0]
}

sample := proto.DeleteRequest{}

err := roundTrip(sample, func(cli proto.HubClient, in iocodec.Decoder, out iocodec.Encoder) error {

v := proto.DeleteRequest{}

err := in.Decode(&v)
if err != nil {
return err
}

resp, err := cli.Delete(context.Background(), &v)
_resources.Reverse()

for _, r := range _resources.R {
err := r.SendDelete(uri)
if err != nil {
return err
}

return out.Encode(resp)

})

return err

}
return nil
},
}
58 changes: 0 additions & 58 deletions cmd/device-hub-cli/cmd_describe.go

This file was deleted.

117 changes: 0 additions & 117 deletions cmd/device-hub-cli/cmd_pipe.go

This file was deleted.

15 changes: 5 additions & 10 deletions cmd/device-hub-cli/cmd_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ var showCommand = &cobra.Command{
Short: "Display one or many resources",
RunE: func(cmd *cobra.Command, args []string) error {

v := proto.ShowRequest{
Filter: strings.Join(args, ","),
}

err := roundTrip(v, func(cli proto.HubClient, in iocodec.Decoder, out iocodec.Encoder) error {

resp, err := cli.Show(context.Background(), &v)

err := roundTrip(func(cli proto.HubClient, in rawContent, out iocodec.Encoder) error {
req := proto.ShowRequest{
Filter: strings.Join(args, ","),
}
resp, err := cli.Show(context.Background(), &req)
if err != nil {
return err
}

return out.Encode(resp)

})

return err
Expand Down
Loading