MCPcopy Create free account
hub / github.com/hashicorp/vault / Run

Method Run

command/operator_usage.go:85–152  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

83}
84
85func (c *OperatorUsageCommand) Run(args []string) int {
86 f := c.Flags()
87
88 if err := f.Parse(args); err != nil {
89 c.UI.Error(err.Error())
90 return 1
91 }
92
93 data := make(map[string][]string)
94 if !c.flagStartTime.IsZero() {
95 data["start_time"] = []string{c.flagStartTime.Format(time.RFC3339)}
96 }
97 if !c.flagEndTime.IsZero() {
98 data["end_time"] = []string{c.flagEndTime.Format(time.RFC3339)}
99 }
100
101 client, err := c.Client()
102 if err != nil {
103 c.UI.Error(err.Error())
104 return 2
105 }
106
107 resp, err := client.Logical().ReadWithData("sys/internal/counters/activity", data)
108 if err != nil {
109 c.UI.Error(fmt.Sprintf("Error retrieving client counts: %v", err))
110 return 2
111 }
112
113 if resp == nil || resp.Data == nil {
114 if c.noReportAvailable(client) {
115 c.UI.Warn("Vault does not have any usage data available. A report will be available\n" +
116 "after the first calendar month in which monitoring is enabled.")
117 } else {
118 c.UI.Warn("No data is available for the given time range.")
119 }
120 // No further output
121 return 0
122 }
123
124 switch Format(c.UI) {
125 case "table":
126 default:
127 // Handle JSON, YAML, etc.
128 return OutputData(c.UI, resp)
129 }
130
131 // Show this before the headers
132 c.outputTimestamps(resp.Data)
133
134 out := []string{
135 "Namespace path | Entity Clients | Non-Entity clients | Secret syncs | ACME clients | Active clients",
136 }
137
138 out = append(out, c.namespacesOutput(resp.Data)...)
139 out = append(out, c.totalOutput(resp.Data)...)
140
141 colConfig := columnize.DefaultConfig()
142 colConfig.Empty = " " // Do not show n/a on intentional blank lines

Callers

nothing calls this directly

Calls 15

FlagsMethod · 0.95
noReportAvailableMethod · 0.95
outputTimestampsMethod · 0.95
namespacesOutputMethod · 0.95
totalOutputMethod · 0.95
FormatFunction · 0.85
OutputDataFunction · 0.85
tableOutputFunction · 0.85
IsZeroMethod · 0.80
ReadWithDataMethod · 0.80
LogicalMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected