Skip to content

Commit

Permalink
Add list/get bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Stoykov committed Jan 22, 2020
1 parent c922a86 commit f926835
Show file tree
Hide file tree
Showing 12 changed files with 899 additions and 106 deletions.
113 changes: 78 additions & 35 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ required = ["gopkg.in/fsnotify.v1"]

[[constraint]]
name = "github.com/Peripli/service-manager"
version = "=v0.9.0"
branch = "master-smaap"

# Refer to issue https://github.com/golang/dep/issues/1799
[[override]]
Expand Down
115 changes: 115 additions & 0 deletions internal/cmd/binding/get_binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright 2018 The Service Manager Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package binding

import (
"fmt"

"github.com/Peripli/service-manager-cli/pkg/types"

"github.com/Peripli/service-manager-cli/internal/cmd"
"github.com/Peripli/service-manager-cli/internal/output"
"github.com/Peripli/service-manager-cli/pkg/query"
"github.com/spf13/cobra"
)

// GetBindingCmd wraps the smctl list-brokers command
type GetBindingCmd struct {
*cmd.Context

bindingName string
prepare cmd.PrepareFunc
outputFormat output.Format
}

// NewGetBindingCmd returns new get status command with context
func NewGetBindingCmd(context *cmd.Context) *GetBindingCmd {
return &GetBindingCmd{Context: context}
}

// Run runs the command's logic
func (gb *GetBindingCmd) Run() error {
bindings, err := gb.Client.ListBindings(&query.Parameters{
FieldQuery: []string{
fmt.Sprintf("name eq '%s'", gb.bindingName),
},
})
if err != nil {
return err
}
if len(bindings.ServiceBindings) < 1 {
output.PrintMessage(gb.Output, "No binding found with name: %s", gb.bindingName)
return nil
}

resultBindings := &types.ServiceBindings{}
for _, binding := range bindings.ServiceBindings {
bd, err := gb.Client.GetBindingByID(binding.ID, &query.Parameters{
GeneralParams: []string{
"last_op=true",
},
})
if err != nil {
return err
}
resultBindings.ServiceBindings = append(resultBindings.ServiceBindings, *bd)
}

output.PrintServiceManagerObject(gb.Output, gb.outputFormat, resultBindings)
output.Println(gb.Output)

return nil
}

// Validate validates command's arguments
func (gb *GetBindingCmd) Validate(args []string) error {
if len(args) < 1 || len(args[0]) < 1 {
return fmt.Errorf("binding name is required")
}

gb.bindingName = args[0]

return nil
}

// SetOutputFormat set output format
func (gb *GetBindingCmd) SetOutputFormat(format output.Format) {
gb.outputFormat = format
}

// HideUsage hide command's usage
func (gb *GetBindingCmd) HideUsage() bool {
return true
}

// Prepare returns cobra command
func (gb *GetBindingCmd) Prepare(prepare cmd.PrepareFunc) *cobra.Command {
gb.prepare = prepare
result := &cobra.Command{
Use: "get-binding [name]",
Aliases: []string{"gsb"},
Short: "Get single binding",
Long: `Get single binding by its name`,
PreRunE: gb.prepare(gb, gb.Context),
RunE: cmd.RunE(gb),
}

cmd.AddFormatFlag(result.Flags())
cmd.AddCommonQueryFlag(result.Flags(), &gb.Parameters)

return result
}
Loading

0 comments on commit f926835

Please sign in to comment.