|
| 1 | +// Copyright © 2018 Humio Ltd. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package cmd |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "os" |
| 20 | + |
| 21 | + "github.com/humio/cli/api" |
| 22 | + "github.com/olekukonko/tablewriter" |
| 23 | + "github.com/spf13/cobra" |
| 24 | +) |
| 25 | + |
| 26 | +func newViewsCmd() *cobra.Command { |
| 27 | + cmd := &cobra.Command{ |
| 28 | + Use: "views", |
| 29 | + Short: "Manage views", |
| 30 | + } |
| 31 | + |
| 32 | + cmd.AddCommand(newViewsShowCmd()) |
| 33 | + |
| 34 | + return cmd |
| 35 | +} |
| 36 | + |
| 37 | +func printViewTable(view api.View) { |
| 38 | + |
| 39 | + data := [][]string{ |
| 40 | + []string{"Name", view.Name}, |
| 41 | + } |
| 42 | + |
| 43 | + w := tablewriter.NewWriter(os.Stdout) |
| 44 | + w.AppendBulk(data) |
| 45 | + w.SetBorder(false) |
| 46 | + w.SetColumnSeparator(":") |
| 47 | + w.SetColumnAlignment([]int{tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT}) |
| 48 | + |
| 49 | + fmt.Println() |
| 50 | + w.Render() |
| 51 | + fmt.Println() |
| 52 | +} |
| 53 | + |
| 54 | +func printViewRoleTable(view api.View) { |
| 55 | + |
| 56 | + data := [][]string{} |
| 57 | + |
| 58 | + for _, role := range view.Roles { |
| 59 | + data = append(data, []string{role.Role.Name, role.QueryPrefix}) |
| 60 | + } |
| 61 | + |
| 62 | + w := tablewriter.NewWriter(os.Stdout) |
| 63 | + w.AppendBulk(data) |
| 64 | + w.SetBorder(true) |
| 65 | + w.SetHeader([]string{"Role", "Query Prefix"}) |
| 66 | + w.SetColumnSeparator(":") |
| 67 | + w.SetColumnAlignment([]int{tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT}) |
| 68 | + |
| 69 | + fmt.Println() |
| 70 | + w.Render() |
| 71 | + fmt.Println() |
| 72 | +} |
| 73 | + |
| 74 | +func viewRoleNames(user api.User) []string { |
| 75 | + names := make([]string, len(user.Roles)) |
| 76 | + for i, r := range user.Roles { |
| 77 | + names[i] = r.Name |
| 78 | + } |
| 79 | + return names |
| 80 | +} |
0 commit comments