Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkhahn committed Nov 17, 2017
0 parents commit 00a7f49
Show file tree
Hide file tree
Showing 9,938 changed files with 3,050,741 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/broker/broker
bin/class/class
Empty file added .gitmodules
Empty file.
10 changes: 10 additions & 0 deletions bin/broker/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "broker"
shortDesc: "This command interacts with Cluster Service Brokers"
command: "./broker"
tree:
- name: "list"
shortDesc: "Lists all Cluster Service Brokers"
command: "./broker list"
- name: "get"
shortDesc: "Gets a particular Cluster Service Broker"
command: "./broker get"
10 changes: 10 additions & 0 deletions bin/class/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "class"
shortDesc: "This command interacts with Cluster Service Classes"
command: "./class"
tree:
- name: "list"
shortDesc: "Lists all Cluster Service Classes"
command: "./class list"
- name: "get"
shortDesc: "Gets a particular Cluster Service Class"
command: "./class get"
79 changes: 79 additions & 0 deletions cmd/broker/broker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2016 The Kubernetes 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 main

import (
"fmt"
"os"

"github.com/jberkhahn/service-catalog-plugins/pkg/utils"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const usage = `Usage:
kubectl plugin broker SUBCOMMAND
Available subcommands:
list
get
`

const getUsage = `Usage:
kubectl plugin broker get BROKERNAME
`

func main() {
if len(os.Args) < 2 {
utils.Exit1(usage)
}

scClient, _ := utils.NewClient()
if os.Args[1] == "list" {
ListBroker()
} else if os.Args[1] == "get" {
if len(os.Args) != 3 {
utils.Exit1(getUsage)
}
brokerName := os.Args[2]
broker, err := scClient.ServicecatalogV1beta1().ClusterServiceBrokers().Get(brokerName, v1.GetOptions{})
if err != nil {
utils.Exit1(fmt.Sprintf("Unable to find broker %s (%s)", brokerName, err))
}
table := utils.NewTable("BROKER NAME", "NAMESPACE", "URL")
table.AddRow(broker.Name, broker.Namespace, broker.Spec.URL)
err = table.Print()
} else {
utils.Exit1(usage)
}
}

func ListBroker() {
scClient, _ := utils.NewClient()
brokers, err := scClient.ServicecatalogV1beta1().ClusterServiceBrokers().List(v1.ListOptions{})
if err != nil {
utils.Exit1(fmt.Sprintf("Unable to list brokers (%s)", err))
}

table := utils.NewTable("BROKER NAME", "NAMESPACE", "URL")
for _, v := range brokers.Items {
table.AddRow(v.Name, v.Namespace, v.Spec.URL)
err = table.Print()
}
if err != nil {
utils.Exit1(fmt.Sprintf("Error printing result (%s)", err))
}
}
74 changes: 74 additions & 0 deletions cmd/class/class.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2016 The Kubernetes 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 main

import (
"fmt"
"os"

"github.com/jberkhahn/service-catalog-plugins/pkg/utils"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const usage = `Usage:
kubectl plugin class SUBCOMMAND
Available subcommands:
list
get
`

const getUsage = `Usage:
kubectl plugin class get CLASSNAME
`

func main() {
if len(os.Args) < 2 {
utils.Exit1(usage)
}

scClient, _ := utils.NewClient()
if os.Args[1] == "list" {
classes, err := scClient.ServicecatalogV1beta1().ClusterServiceClasses().List(v1.ListOptions{})
if err != nil {
utils.Exit1(fmt.Sprintf("Unable to list classes (%s)", err))
}

table := utils.NewTable("CLASS NAME", "NAMESPACE", "BROKER NAME")
for _, v := range classes.Items {
table.AddRow(v.Name, v.Namespace, v.Spec.ClusterServiceBrokerName)
err = table.Print()
}
if err != nil {
utils.Exit1(fmt.Sprintf("Error printing result (%s)", err))
}
} else if os.Args[1] == "get" {
if len(os.Args) != 3 {
utils.Exit1(getUsage)
}
className := os.Args[2]
class, err := scClient.ServicecatalogV1beta1().ClusterServiceClasses().Get(className, v1.GetOptions{})
if err != nil {
utils.Exit1(fmt.Sprintf("Unable to find class %s (%s)", className, err))
}
table := utils.NewTable("CLASS NAME", "NAMESPACE", "BROKER NAME")
table.AddRow(class.Name, class.Namespace, class.Spec.ClusterServiceBrokerName)
err = table.Print()
} else {
utils.Exit1(usage)
}
}
67 changes: 67 additions & 0 deletions pkg/utils/table_printer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2016 The Kubernetes 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 utils

import (
"fmt"
"os"
"text/tabwriter"
)

// Table defines a tabular output - obviously in table format
type Table struct {
headers []string
rows [][]string
}

// NewTable creates a new table based on the passed in header names
func NewTable(headers ...string) *Table {
return &Table{
headers: headers,
}
}

// AddRow will append the specified row to the table
func (t *Table) AddRow(row ...string) {
t.rows = append(t.rows, row)
}

// Print prints the table to the screen
func (t *Table) Print() error {
padding := 3

w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', 0)

//Print header
printStr := ""
for _, h := range t.headers {
printStr = printStr + h + "\t"
}
fmt.Fprintln(w, printStr)

//Print rows
for _, rows := range t.rows {
printStr = ""
for _, row := range rows {
printStr = printStr + row + "\t"
}
fmt.Fprintln(w, printStr)
}
fmt.Fprintln(w)

return w.Flush()
}
44 changes: 44 additions & 0 deletions pkg/utils/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2016 The Kubernetes 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 utils

import "fmt"

// Green will print the specified string in green text
func Green(str string) string {
return fmt.Sprintf("\x1b[32;1m%s\x1b[0m", str)
}

// Red will print the specified string in red text
func Red(str string) string {
return fmt.Sprintf("\x1b[31;1m%s\x1b[0m", str)
}

// Entity will print the specified string in bold text
func Entity(str string) string {
return fmt.Sprintf("\x1b[36;1m%s\x1b[0m", str)
}

// Error will print the specified error string in red text
func Error(msg string) {
fmt.Printf("%s\n\n%s\n\n", Red("ERROR"), msg)
}

// Ok will print "OK" in green
func Ok() {
fmt.Printf("%s\n\n", Green("OK"))
}
Loading

0 comments on commit 00a7f49

Please sign in to comment.