-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure and add commands for endpoints and certificates (#94)
This PR achieves the following: * updates documentation (needs more work) * complete the rename from configure to auth (we left some artifacts behind) * adds support for downloading the root CA cert via cluster cert download * adds support for listing the cluster endpoints via cluster network endpoint list * moves NAL assign to cluster network allow-list assign/unassign * moves read-replica from top level to cluster read-replica * moves regions from cluster describe-regions to region list * moves instance-types from cluster describe-instances to region instance list * moves vpc-peering from top-level to vpc peering
- Loading branch information
Showing
23 changed files
with
505 additions
and
106 deletions.
There are no files selected for viewing
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
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,80 @@ | ||
// Licensed to Yugabyte, Inc. under one or more contributor license | ||
// agreements. See the NOTICE file distributed with this work for | ||
// additional information regarding copyright ownership. Yugabyte | ||
// licenses this file to you 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 cert | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
ybmAuthClient "github.com/yugabyte/ybm-cli/internal/client" | ||
) | ||
|
||
var CertCmd = &cobra.Command{ | ||
Use: "cert", | ||
Short: "Get the root CA certificate", | ||
Long: "Get the root CA certificate for your YBM clusters", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
} | ||
|
||
var downloadCertificate = &cobra.Command{ | ||
Use: "download", | ||
Short: "Download the root CA certificate", | ||
Long: `Download the root CA certificate`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
authApi, err := ybmAuthClient.NewAuthApiClient() | ||
if err != nil { | ||
logrus.Fatalf("Could not initiate api client: %s", err.Error()) | ||
} | ||
authApi.GetInfo("", "") | ||
certificate, err := authApi.GetConnectionCertificate() | ||
if err != nil { | ||
logrus.Fatal("Fail to retrieve connection certificate: ", err) | ||
} | ||
|
||
if output, _ := cmd.Flags().GetString("out"); output != "" { | ||
// check if the file exists | ||
if _, err := os.Stat(output); err == nil { | ||
// Only overwrite if force is set | ||
if !cmd.Flags().Changed("force") { | ||
logrus.Fatalf("File %s already exists", output) | ||
} | ||
} | ||
|
||
f, err := os.Create(output) | ||
if err != nil { | ||
logrus.Fatal("Fail to create output file: ", err) | ||
} | ||
defer f.Close() | ||
_, err = f.WriteString(certificate) | ||
if err != nil { | ||
logrus.Fatal("Fail to write to output file: ", err) | ||
} | ||
} else { | ||
fmt.Println(certificate) | ||
} | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
CertCmd.AddCommand(downloadCertificate) | ||
downloadCertificate.Flags().StringP("out", "", "", "[OPTIONAL] Output file name (default: stdout)") | ||
downloadCertificate.Flags().BoolP("force", "f", false, "[OPTIONAL] Overwrite the output file if it exists") | ||
} |
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
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,33 @@ | ||
// Licensed to Yugabyte, Inc. under one or more contributor license | ||
// agreements. See the NOTICE file distributed with this work for | ||
// additional information regarding copyright ownership. Yugabyte | ||
// licenses this file to you 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 endpoint | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var EndpointCmd = &cobra.Command{ | ||
Use: "endpoint", | ||
Short: "Manage endpoints for a cluster", | ||
Long: "Manage endpoints for a cluster", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
} | ||
|
||
func init() { | ||
EndpointCmd.AddCommand() | ||
} |
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,89 @@ | ||
// Licensed to Yugabyte, Inc. under one or more contributor license | ||
// agreements. See the NOTICE file distributed with this work for | ||
// additional information regarding copyright ownership. Yugabyte | ||
// licenses this file to you 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 endpoint | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/yugabyte/ybm-cli/cmd/util" | ||
ybmAuthClient "github.com/yugabyte/ybm-cli/internal/client" | ||
ybmclient "github.com/yugabyte/yugabytedb-managed-go-client-internal" | ||
|
||
"github.com/yugabyte/ybm-cli/internal/formatter" | ||
) | ||
|
||
var listEndpointCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List endpoints for a cluster", | ||
Long: "List endpoints for a cluster", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
authApi, err := ybmAuthClient.NewAuthApiClient() | ||
if err != nil { | ||
logrus.Fatalf("Could not initiate api client: %s", err.Error()) | ||
} | ||
authApi.GetInfo("", "") | ||
|
||
clusterName, _ := cmd.Flags().GetString("cluster-name") | ||
clusterListRequest := authApi.ListClusters() | ||
// if user filters by name, add it to the request | ||
clusterListRequest = clusterListRequest.Name(clusterName) | ||
|
||
resp, r, err := clusterListRequest.Execute() | ||
if err != nil { | ||
logrus.Debugf("Full HTTP response: %v", r) | ||
logrus.Fatalf("Error when calling `ClusterApi.ListClusters`: %s", ybmAuthClient.GetApiErrorDetails(err)) | ||
} | ||
|
||
if len(resp.GetData()) == 0 { | ||
logrus.Fatalf("Cluster not found") | ||
} | ||
|
||
clusterEndpoints := resp.GetData()[0].Info.ClusterEndpoints | ||
|
||
region, _ := cmd.Flags().GetString("region") | ||
if region != "" { | ||
clusterEndpoints = util.Filter(clusterEndpoints, func(endpoint ybmclient.Endpoint) bool { | ||
return endpoint.GetRegion() == region | ||
}) | ||
} | ||
|
||
accessibility, _ := cmd.Flags().GetString("accessibility") | ||
if accessibility != "" { | ||
clusterEndpoints = util.Filter(clusterEndpoints, func(endpoint ybmclient.Endpoint) bool { | ||
return string(endpoint.GetAccessibilityType()) == accessibility | ||
}) | ||
} | ||
|
||
if len(clusterEndpoints) == 0 { | ||
logrus.Fatalf("No endpoints found") | ||
} | ||
|
||
endpointsCtx := formatter.Context{ | ||
Output: os.Stdout, | ||
Format: formatter.NewEndpointFormat(viper.GetString("output")), | ||
} | ||
formatter.EndpointWrite(endpointsCtx, clusterEndpoints) | ||
}, | ||
} | ||
|
||
func init() { | ||
EndpointCmd.AddCommand(listEndpointCmd) | ||
listEndpointCmd.Flags().String("accessibility", "", "[OPTIONAL] Accessibility of the endpoint") | ||
listEndpointCmd.Flags().String("region", "", "[OPTIONAL] Region of the endpoint") | ||
} |
Oops, something went wrong.