Skip to content

Commit

Permalink
handle return ldap providers via internal service
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp committed Jul 5, 2022
1 parent e4eea1f commit c1b3a90
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
79 changes: 79 additions & 0 deletions cmd/internal.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit c1b3a90

Please sign in to comment.