From c1b3a90b99974282e192e902329eccb99231a7ed Mon Sep 17 00:00:00 2001 From: Mik Iwanowski Date: Tue, 5 Jul 2022 14:54:47 +0200 Subject: [PATCH] handle return ldap providers via internal service --- cmd/internal.go | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 cmd/internal.go diff --git a/cmd/internal.go b/cmd/internal.go new file mode 100644 index 0000000..62a7364 --- /dev/null +++ b/cmd/internal.go @@ -0,0 +1,79 @@ +/* +Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz + +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 cmd + +import ( + "context" + "os" + + pb "github.com/infinimesh/proto/node" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" +) + +func makeInternalServiceClient(ctx context.Context) (pb.InternalServiceClient, error) { + conn, err := makeConnection(ctx) + if err != nil { + return nil, err + } + return pb.NewInternalServiceClient(conn), nil +} + +var interalServiceCmd = &cobra.Command{ + Use: "internal", + Aliases: []string{"int", "i"}, + Short: "Platform internals helper commands", +} + +var ldapProvidersCmd = &cobra.Command{ + Use: "ldap", + Short: "Get LDAP Providers registered", + RunE: func(cmd *cobra.Command, args []string) error { + ctx := makeContextWithBearerToken() + client, err := makeInternalServiceClient(ctx) + if err != nil { + return err + } + + r, err := client.GetLDAPProviders(ctx, &pb.EmptyMessage{}) + if err != nil { + return err + } + + if printJson, _ := cmd.Flags().GetBool("json"); printJson { + return printJsonResponse(r) + } + + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.AppendHeader(table.Row{"Key", "Title"}) + + for key, title := range r.Providers { + t.AppendRow(table.Row{key, title}) + } + + t.Render() + + return nil + }, +} + +func init() { + + interalServiceCmd.AddCommand(ldapProvidersCmd) + + rootCmd.AddCommand(interalServiceCmd) +} diff --git a/go.mod b/go.mod index 1fa3ec6..a0d7f2f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/eclipse/paho.mqtt.golang v1.4.1 - github.com/infinimesh/proto v0.0.0-20220628104557-2b6d8d2a4477 + github.com/infinimesh/proto v0.0.0-20220705122747-41a5f2e158ba github.com/jedib0t/go-pretty/v6 v6.3.3 github.com/spf13/cobra v1.5.0 github.com/spf13/viper v1.12.0 diff --git a/go.sum b/go.sum index 8b30aea..590159c 100644 --- a/go.sum +++ b/go.sum @@ -166,6 +166,8 @@ github.com/infinimesh/proto v0.0.0-20220517220014-9da35b014803 h1:gL3/pQ6xYPq/mE github.com/infinimesh/proto v0.0.0-20220517220014-9da35b014803/go.mod h1:xufYx2D9SioCq9myG5QZg4UyXcG/jKIROJvwBbjG9q4= github.com/infinimesh/proto v0.0.0-20220628104557-2b6d8d2a4477 h1:5nXFzTxKLThhRghtEaWrhOr/1Kaae9yp++YBcq7OkUw= github.com/infinimesh/proto v0.0.0-20220628104557-2b6d8d2a4477/go.mod h1:uSUoHkh8XcLLbIuhFD34gzBwh6ncD3TT49A0kZuHfZI= +github.com/infinimesh/proto v0.0.0-20220705122747-41a5f2e158ba h1:KLMY1itFHLEhVCO7cLzV/xrCfH0K1goibviFIWknHvE= +github.com/infinimesh/proto v0.0.0-20220705122747-41a5f2e158ba/go.mod h1:uSUoHkh8XcLLbIuhFD34gzBwh6ncD3TT49A0kZuHfZI= github.com/jedib0t/go-pretty/v6 v6.3.1 h1:aOXiD9oqiuLH8btPQW6SfgtQN5zwhyfzZls8a6sPJ/I= github.com/jedib0t/go-pretty/v6 v6.3.1/go.mod h1:FMkOpgGD3EZ91cW8g/96RfxoV7bdeJyzXPYgz1L1ln0= github.com/jedib0t/go-pretty/v6 v6.3.3 h1:shEWoyXqldeP54byATY3IczSfMC1b/UziOISaSxcvMQ=