From 2a843be96e48ba4fb15107b5c21891b33b52904d Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Tue, 6 Aug 2019 16:01:32 -0400 Subject: [PATCH 1/4] Add 'connection' command --- cmd/cca/cca.go | 2 ++ cmd/cca/connection/connection.go | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 cmd/cca/connection/connection.go diff --git a/cmd/cca/cca.go b/cmd/cca/cca.go index 00d7e6d..b8b9cbc 100644 --- a/cmd/cca/cca.go +++ b/cmd/cca/cca.go @@ -19,6 +19,7 @@ import ( "os" "github.com/cloud-ca/cca/cmd/cca/completion" + "github.com/cloud-ca/cca/cmd/cca/connection" "github.com/cloud-ca/cca/cmd/cca/version" "github.com/cloud-ca/cca/pkg/cli" "github.com/cloud-ca/cca/pkg/client" @@ -59,6 +60,7 @@ func NewCommand() *cobra.Command { cmd.PersistentFlags().StringVar(&flg.LogLevel, "loglevel", flags.DefaultLogLevel.String(), "log level "+logutil.LevelsString()) cmd.AddCommand(completion.NewCommand(cli)) + cmd.AddCommand(connection.NewCommand(cli)) cmd.AddCommand(version.NewCommand(cli)) return cmd diff --git a/cmd/cca/connection/connection.go b/cmd/cca/connection/connection.go new file mode 100644 index 0000000..a8c79df --- /dev/null +++ b/cmd/cca/connection/connection.go @@ -0,0 +1,38 @@ +// Copyright © 2019 cloud.ca 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 connection implements the `connection` command +package connection + +import ( + "github.com/cloud-ca/cca/pkg/cli" + "github.com/cloud-ca/cca/pkg/util" + "github.com/spf13/cobra" +) + +// NewCommand returns a new cobra.Command for connection +func NewCommand(cli *cli.Wrapper) *cobra.Command { + cmd := &cobra.Command{ + Args: cobra.NoArgs, + Use: "connection", + Short: "Manage service connections that you can create resources for", + Long: util.LongDescription(` + Service connections are the services that you can create resources for (e.g. compute, object + storage). Environments are created for a specific service which allows you to create and + manage resources within that service. + `), + } + + return cmd +} From 95ce741ab1e33c4d9071083c9631b8e2bef73975 Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Tue, 6 Aug 2019 16:29:44 -0400 Subject: [PATCH 2/4] Add 'connection list' subcommand --- cmd/cca/connection/connection.go | 3 +++ cmd/cca/connection/list/list.go | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 cmd/cca/connection/list/list.go diff --git a/cmd/cca/connection/connection.go b/cmd/cca/connection/connection.go index a8c79df..2c0d549 100644 --- a/cmd/cca/connection/connection.go +++ b/cmd/cca/connection/connection.go @@ -16,6 +16,7 @@ package connection import ( + "github.com/cloud-ca/cca/cmd/cca/connection/list" "github.com/cloud-ca/cca/pkg/cli" "github.com/cloud-ca/cca/pkg/util" "github.com/spf13/cobra" @@ -34,5 +35,7 @@ func NewCommand(cli *cli.Wrapper) *cobra.Command { `), } + cmd.AddCommand(list.NewCommand(cli)) + return cmd } diff --git a/cmd/cca/connection/list/list.go b/cmd/cca/connection/list/list.go new file mode 100644 index 0000000..235dae4 --- /dev/null +++ b/cmd/cca/connection/list/list.go @@ -0,0 +1,44 @@ +// Copyright © 2019 cloud.ca 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 list implements the `connection list` command +package list + +import ( + "github.com/cloud-ca/cca/pkg/cli" + "github.com/cloud-ca/cca/pkg/output" + "github.com/spf13/cobra" +) + +// NewCommand returns a new cobra.Command for connection list +func NewCommand(cli *cli.Wrapper) *cobra.Command { + cmd := &cobra.Command{ + Args: cobra.NoArgs, + Aliases: []string{"ls"}, + Use: "list", + Short: "List all service connections", + Long: "List all service connections", + RunE: func(cmd *cobra.Command, args []string) error { + connections, err := cli.CcaClient.ServiceConnections.List() + if err != nil { + return err + } + return cli.OutputBuilder.Build(func(formatter *output.Formatter) error { + return formatter.Format(connections) + }) + }, + } + + return cmd +} From cfebf066f957da245d1d5aeda460129b9b982ac6 Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Tue, 6 Aug 2019 16:37:23 -0400 Subject: [PATCH 3/4] Add 'connection get' command --- cmd/cca/connection/connection.go | 2 ++ cmd/cca/connection/get/get.go | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 cmd/cca/connection/get/get.go diff --git a/cmd/cca/connection/connection.go b/cmd/cca/connection/connection.go index 2c0d549..68fd926 100644 --- a/cmd/cca/connection/connection.go +++ b/cmd/cca/connection/connection.go @@ -16,6 +16,7 @@ package connection import ( + "github.com/cloud-ca/cca/cmd/cca/connection/get" "github.com/cloud-ca/cca/cmd/cca/connection/list" "github.com/cloud-ca/cca/pkg/cli" "github.com/cloud-ca/cca/pkg/util" @@ -35,6 +36,7 @@ func NewCommand(cli *cli.Wrapper) *cobra.Command { `), } + cmd.AddCommand(get.NewCommand(cli)) cmd.AddCommand(list.NewCommand(cli)) return cmd diff --git a/cmd/cca/connection/get/get.go b/cmd/cca/connection/get/get.go new file mode 100644 index 0000000..3478f02 --- /dev/null +++ b/cmd/cca/connection/get/get.go @@ -0,0 +1,52 @@ +// Copyright © 2019 cloud.ca 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 get implements the `connection get` command +package get + +import ( + "github.com/cloud-ca/cca/pkg/cli" + "github.com/cloud-ca/cca/pkg/output" + "github.com/spf13/cobra" +) + +type flag struct { + id string +} + +// NewCommand returns a new cobra.Command for connection get +func NewCommand(cli *cli.Wrapper) *cobra.Command { + flg := &flag{} + cmd := &cobra.Command{ + Args: cobra.NoArgs, + Use: "get", + Short: "Get service connection", + Long: "Get service connection", + RunE: func(cmd *cobra.Command, args []string) error { + connection, err := cli.CcaClient.ServiceConnections.Get(flg.id) + if err != nil { + return err + } + return cli.OutputBuilder.Build(func(formatter *output.Formatter) error { + return formatter.Format(connection) + }) + }, + } + + cmd.Flags().StringVar(&flg.id, "id", "", "environment id") + + cmd.MarkFlagRequired("id") + + return cmd +} From 5ac7e242f780fb837ccd16cb1a0e15285fa19518 Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Tue, 6 Aug 2019 16:42:46 -0400 Subject: [PATCH 4/4] Fix lint --- cmd/cca/connection/get/get.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/cca/connection/get/get.go b/cmd/cca/connection/get/get.go index 3478f02..54e4211 100644 --- a/cmd/cca/connection/get/get.go +++ b/cmd/cca/connection/get/get.go @@ -46,7 +46,10 @@ func NewCommand(cli *cli.Wrapper) *cobra.Command { cmd.Flags().StringVar(&flg.id, "id", "", "environment id") - cmd.MarkFlagRequired("id") + err := cmd.MarkFlagRequired("id") + if err != nil { + panic(err) + } return cmd }