-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikolay Stoykov
committed
Jan 22, 2020
1 parent
c922a86
commit f926835
Showing
12 changed files
with
899 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.