mirror of https://github.com/hashicorp/boundary
parent
111dc87ead
commit
2e69d59dd2
@ -0,0 +1,35 @@
|
|||||||
|
// Code generated by "make api"; DO NOT EDIT.
|
||||||
|
// Copyright (c) HashiCorp, Inc.
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
package billing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/boundary/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ActiveUsers struct {
|
||||||
|
Count uint32 `json:"count"`
|
||||||
|
StartTime time.Time `json:"start_time,omitempty"`
|
||||||
|
EndTime time.Time `json:"end_time,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client is a client for this collection
|
||||||
|
type Client struct {
|
||||||
|
client *api.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates a new client for this collection. The submitted API client is cloned;
|
||||||
|
// modifications to it after generating this client will not have effect. If you
|
||||||
|
// need to make changes to the underlying API client, use ApiClient() to access
|
||||||
|
// it.
|
||||||
|
func NewClient(c *api.Client) *Client {
|
||||||
|
return &Client{client: c.Clone()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApiClient returns the underlying API client
|
||||||
|
func (c *Client) ApiClient() *api.Client {
|
||||||
|
return c.client
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
// Copyright (c) HashiCorp, Inc.
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
package billing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/hashicorp/boundary/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MonthlyActiveUsersResult struct {
|
||||||
|
Items []*ActiveUsers
|
||||||
|
response *api.Response
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r MonthlyActiveUsersResult) GetItems() any {
|
||||||
|
return r.Items
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r MonthlyActiveUsersResult) GetResponse() *api.Response {
|
||||||
|
return r.response
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) MonthlyActiveUsers(ctx context.Context, opt ...Option) (*MonthlyActiveUsersResult, error) {
|
||||||
|
opts, apiOpts := getOpts(opt...)
|
||||||
|
|
||||||
|
if c.client == nil {
|
||||||
|
return nil, fmt.Errorf("nil client")
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := c.client.NewRequest(ctx, "GET", "billing:monthly-active-users", nil, apiOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error creating MonthlyActiveUsers request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(opts.queryMap) > 0 {
|
||||||
|
q := url.Values{}
|
||||||
|
for k, v := range opts.queryMap {
|
||||||
|
q.Add(k, v)
|
||||||
|
}
|
||||||
|
req.URL.RawQuery = q.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := c.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error performing client request during MonthlyActiveUsers call: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mau := new(MonthlyActiveUsersResult)
|
||||||
|
mau.Items = []*ActiveUsers{}
|
||||||
|
apiErr, err := resp.Decode(mau)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decoding MonthlyActiveUsers response: %w", err)
|
||||||
|
}
|
||||||
|
if apiErr != nil {
|
||||||
|
return nil, apiErr
|
||||||
|
}
|
||||||
|
mau.response = resp
|
||||||
|
return mau, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,104 @@
|
|||||||
|
// Code generated by "make api"; DO NOT EDIT.
|
||||||
|
// Copyright (c) HashiCorp, Inc.
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
package billing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/boundary/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option is a func that sets optional attributes for a call. This does not need
|
||||||
|
// to be used directly, but instead option arguments are built from the
|
||||||
|
// functions in this package. WithX options set a value to that given in the
|
||||||
|
// argument; DefaultX options indicate that the value should be set to its
|
||||||
|
// default. When an API call is made options are processed in the order they
|
||||||
|
// appear in the function call, so for a given argument X, a succession of WithX
|
||||||
|
// or DefaultX calls will result in the last call taking effect.
|
||||||
|
type Option func(*options)
|
||||||
|
|
||||||
|
type options struct {
|
||||||
|
postMap map[string]interface{}
|
||||||
|
queryMap map[string]string
|
||||||
|
withAutomaticVersioning bool
|
||||||
|
withSkipCurlOutput bool
|
||||||
|
withFilter string
|
||||||
|
withListToken string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDefaultOptions() options {
|
||||||
|
return options{
|
||||||
|
postMap: make(map[string]interface{}),
|
||||||
|
queryMap: make(map[string]string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOpts(opt ...Option) (options, []api.Option) {
|
||||||
|
opts := getDefaultOptions()
|
||||||
|
for _, o := range opt {
|
||||||
|
if o != nil {
|
||||||
|
o(&opts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var apiOpts []api.Option
|
||||||
|
if opts.withSkipCurlOutput {
|
||||||
|
apiOpts = append(apiOpts, api.WithSkipCurlOutput(true))
|
||||||
|
}
|
||||||
|
if opts.withFilter != "" {
|
||||||
|
opts.queryMap["filter"] = opts.withFilter
|
||||||
|
}
|
||||||
|
if opts.withListToken != "" {
|
||||||
|
opts.queryMap["list_token"] = opts.withListToken
|
||||||
|
}
|
||||||
|
return opts, apiOpts
|
||||||
|
}
|
||||||
|
|
||||||
|
// If set, and if the version is zero during an update, the API will perform a
|
||||||
|
// fetch to get the current version of the resource and populate it during the
|
||||||
|
// update call. This is convenient but opens up the possibility for subtle
|
||||||
|
// order-of-modification issues, so use carefully.
|
||||||
|
func WithAutomaticVersioning(enable bool) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.withAutomaticVersioning = enable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSkipCurlOutput tells the API to not use the current call for cURL output.
|
||||||
|
// Useful for when we need to look up versions.
|
||||||
|
func WithSkipCurlOutput(skip bool) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.withSkipCurlOutput = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithListToken tells the API to use the provided list token
|
||||||
|
// for listing operations on this resource.
|
||||||
|
func WithListToken(listToken string) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.withListToken = listToken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithFilter tells the API to filter the items returned using the provided
|
||||||
|
// filter term. The filter should be in a format supported by
|
||||||
|
// hashicorp/go-bexpr.
|
||||||
|
func WithFilter(filter string) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.withFilter = strings.TrimSpace(filter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithEndTime(inEndTime string) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.queryMap["end_time"] = fmt.Sprintf("%v", inEndTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithStartTime(inStartTime string) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.queryMap["start_time"] = fmt.Sprintf("%v", inStartTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,201 @@
|
|||||||
|
// Code generated by "make cli"; DO NOT EDIT.
|
||||||
|
// Copyright (c) HashiCorp, Inc.
|
||||||
|
// SPDX-License-Identifier: BUSL-1.1
|
||||||
|
|
||||||
|
package billingcmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hashicorp/boundary/api"
|
||||||
|
"github.com/hashicorp/boundary/api/billing"
|
||||||
|
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||||
|
"github.com/hashicorp/boundary/internal/cmd/common"
|
||||||
|
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||||
|
"github.com/mitchellh/cli"
|
||||||
|
"github.com/posener/complete"
|
||||||
|
)
|
||||||
|
|
||||||
|
func initFlags() {
|
||||||
|
flagsOnce.Do(func() {
|
||||||
|
extraFlags := extraActionsFlagsMapFunc()
|
||||||
|
for k, v := range extraFlags {
|
||||||
|
flagsMap[k] = append(flagsMap[k], v...)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ cli.Command = (*Command)(nil)
|
||||||
|
_ cli.CommandAutocomplete = (*Command)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
|
type Command struct {
|
||||||
|
*base.Command
|
||||||
|
|
||||||
|
Func string
|
||||||
|
|
||||||
|
plural string
|
||||||
|
|
||||||
|
extraCmdVars
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) AutocompleteArgs() complete.Predictor {
|
||||||
|
initFlags()
|
||||||
|
return complete.PredictAnything
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) AutocompleteFlags() complete.Flags {
|
||||||
|
initFlags()
|
||||||
|
return c.Flags().Completions()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) Synopsis() string {
|
||||||
|
if extra := extraSynopsisFunc(c); extra != "" {
|
||||||
|
return extra
|
||||||
|
}
|
||||||
|
|
||||||
|
synopsisStr := "billing"
|
||||||
|
|
||||||
|
return common.SynopsisFunc(c.Func, synopsisStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) Help() string {
|
||||||
|
initFlags()
|
||||||
|
|
||||||
|
var helpStr string
|
||||||
|
helpMap := common.HelpMap("billing")
|
||||||
|
|
||||||
|
switch c.Func {
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
helpStr = c.extraHelpFunc(helpMap)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep linter from complaining if we don't actually generate code using it
|
||||||
|
_ = helpMap
|
||||||
|
return helpStr
|
||||||
|
}
|
||||||
|
|
||||||
|
var flagsMap = map[string][]string{}
|
||||||
|
|
||||||
|
func (c *Command) Flags() *base.FlagSets {
|
||||||
|
if len(flagsMap[c.Func]) == 0 {
|
||||||
|
return c.FlagSet(base.FlagSetNone)
|
||||||
|
}
|
||||||
|
|
||||||
|
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
|
||||||
|
f := set.NewFlagSet("Command Options")
|
||||||
|
common.PopulateCommonFlags(c.Command, f, "billing", flagsMap, c.Func)
|
||||||
|
|
||||||
|
extraFlagsFunc(c, set, f)
|
||||||
|
|
||||||
|
return set
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) Run(args []string) int {
|
||||||
|
initFlags()
|
||||||
|
|
||||||
|
switch c.Func {
|
||||||
|
case "":
|
||||||
|
return cli.RunResultHelp
|
||||||
|
|
||||||
|
case "create":
|
||||||
|
return cli.RunResultHelp
|
||||||
|
|
||||||
|
case "update":
|
||||||
|
return cli.RunResultHelp
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
c.plural = "billing"
|
||||||
|
switch c.Func {
|
||||||
|
case "list":
|
||||||
|
c.plural = "billing"
|
||||||
|
}
|
||||||
|
|
||||||
|
f := c.Flags()
|
||||||
|
|
||||||
|
if err := f.Parse(args); err != nil {
|
||||||
|
c.PrintCliError(err)
|
||||||
|
return base.CommandUserError
|
||||||
|
}
|
||||||
|
|
||||||
|
var opts []billing.Option
|
||||||
|
|
||||||
|
if strutil.StrListContains(flagsMap[c.Func], "-id") {
|
||||||
|
switch c.Func {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := c.Client()
|
||||||
|
if c.WrapperCleanupFunc != nil {
|
||||||
|
defer func() {
|
||||||
|
if err := c.WrapperCleanupFunc(); err != nil {
|
||||||
|
c.PrintCliError(fmt.Errorf("Error cleaning kms wrapper: %w", err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
c.PrintCliError(fmt.Errorf("Error creating API client: %w", err))
|
||||||
|
return base.CommandCliError
|
||||||
|
}
|
||||||
|
billingClient := billing.NewClient(client)
|
||||||
|
|
||||||
|
if c.FlagFilter != "" {
|
||||||
|
opts = append(opts, billing.WithFilter(c.FlagFilter))
|
||||||
|
}
|
||||||
|
|
||||||
|
var version uint32
|
||||||
|
|
||||||
|
if ok := extraFlagsHandlingFunc(c, f, &opts); !ok {
|
||||||
|
return base.CommandUserError
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp *api.Response
|
||||||
|
|
||||||
|
resp, err = executeExtraActions(c, resp, err, billingClient, version, opts)
|
||||||
|
if exitCode := c.checkFuncError(err); exitCode > 0 {
|
||||||
|
return exitCode
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := printCustomActionOutput(c)
|
||||||
|
if err != nil {
|
||||||
|
c.PrintCliError(err)
|
||||||
|
return base.CommandUserError
|
||||||
|
}
|
||||||
|
if output {
|
||||||
|
return base.CommandSuccess
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.CommandSuccess
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) checkFuncError(err error) int {
|
||||||
|
if err == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||||
|
c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural))
|
||||||
|
return base.CommandApiError
|
||||||
|
}
|
||||||
|
c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error()))
|
||||||
|
return base.CommandCliError
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
flagsOnce = new(sync.Once)
|
||||||
|
|
||||||
|
extraActionsFlagsMapFunc = func() map[string][]string { return nil }
|
||||||
|
extraSynopsisFunc = func(*Command) string { return "" }
|
||||||
|
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||||
|
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]billing.Option) bool { return true }
|
||||||
|
executeExtraActions = func(_ *Command, inResp *api.Response, inErr error, _ *billing.Client, _ uint32, _ []billing.Option) (*api.Response, error) {
|
||||||
|
return inResp, inErr
|
||||||
|
}
|
||||||
|
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||||
|
)
|
||||||
@ -0,0 +1,156 @@
|
|||||||
|
// Copyright (c) HashiCorp, Inc.
|
||||||
|
// SPDX-License-Identifier: BUSL-1.1
|
||||||
|
|
||||||
|
package billingcmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/boundary/api"
|
||||||
|
"github.com/hashicorp/boundary/api/billing"
|
||||||
|
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||||
|
"github.com/mitchellh/go-wordwrap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extraActionsFlagsMapFunc = extraActionsFlagsMapFuncImpl
|
||||||
|
extraSynopsisFunc = extraSynopsisFuncImpl
|
||||||
|
extraFlagsFunc = extraFlagsFuncImpl
|
||||||
|
extraFlagsHandlingFunc = extraFlagsHandlingFuncImpl
|
||||||
|
executeExtraActions = executeExtraActionsImpl
|
||||||
|
printCustomActionOutput = printCustomActionOutputImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
type extraCmdVars struct {
|
||||||
|
flagStartTime string
|
||||||
|
flagEndTime string
|
||||||
|
monthlyActiveUsers *billing.MonthlyActiveUsersResult
|
||||||
|
}
|
||||||
|
|
||||||
|
func extraActionsFlagsMapFuncImpl() map[string][]string {
|
||||||
|
return map[string][]string{
|
||||||
|
"monthly-active-users": {"start-time", "end-time"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extraSynopsisFuncImpl(c *Command) string {
|
||||||
|
switch c.Func {
|
||||||
|
case "monthly-active-users":
|
||||||
|
var in string
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(c.Func, "start-time"):
|
||||||
|
in = "Get monthly active users, starting from this time (YYYY-MM format)."
|
||||||
|
case strings.HasPrefix(c.Func, "end-time"):
|
||||||
|
in = "Get monthly active users, ending at this time (YYYY-MM format)."
|
||||||
|
}
|
||||||
|
return wordwrap.WrapString(in, base.TermWidth)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extraFlagsFuncImpl(c *Command, _ *base.FlagSets, f *base.FlagSet) {
|
||||||
|
flagsMap[c.Func] = append(flagsMap[c.Func], "start-time", "end-time")
|
||||||
|
f.StringVar(&base.StringVar{
|
||||||
|
Name: "start-time",
|
||||||
|
Target: &c.flagStartTime,
|
||||||
|
Usage: "Get monthly active users, starting from this time (YYYY-MM format).",
|
||||||
|
})
|
||||||
|
f.StringVar(&base.StringVar{
|
||||||
|
Name: "end-time",
|
||||||
|
Target: &c.flagEndTime,
|
||||||
|
Usage: "Get monthly active users, ending at this time (YYYY-MM format).",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]billing.Option) bool {
|
||||||
|
switch c.Func {
|
||||||
|
case "monthly-active-users":
|
||||||
|
if len(c.flagStartTime) != 0 {
|
||||||
|
*opts = append(*opts, billing.WithStartTime(c.flagStartTime))
|
||||||
|
}
|
||||||
|
if len(c.flagEndTime) != 0 {
|
||||||
|
*opts = append(*opts, billing.WithEndTime(c.flagEndTime))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeExtraActionsImpl(c *Command, origResp *api.Response, origError error, billingClient *billing.Client, _ uint32, opts []billing.Option) (*api.Response, error) {
|
||||||
|
switch c.Func {
|
||||||
|
case "monthly-active-users":
|
||||||
|
var err error
|
||||||
|
c.monthlyActiveUsers, err = billingClient.MonthlyActiveUsers(c.Context, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return origResp, origError
|
||||||
|
}
|
||||||
|
|
||||||
|
func printCustomActionOutputImpl(c *Command) (bool, error) {
|
||||||
|
switch c.Func {
|
||||||
|
case "monthly-active-users":
|
||||||
|
switch base.Format(c.UI) {
|
||||||
|
case "table":
|
||||||
|
items := c.monthlyActiveUsers.GetItems().([]*billing.ActiveUsers)
|
||||||
|
var ret []string
|
||||||
|
|
||||||
|
ret = append(ret, "Billing information:")
|
||||||
|
ret = append(ret, "")
|
||||||
|
for i := range items {
|
||||||
|
ret = append(ret,
|
||||||
|
fmt.Sprintf(" Count: %d", items[i].Count),
|
||||||
|
fmt.Sprintf(" Start Time: %s", items[i].StartTime),
|
||||||
|
fmt.Sprintf(" End Time: %s", items[i].EndTime),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.UI.Output(base.WrapForHelpText(ret))
|
||||||
|
return true, nil
|
||||||
|
|
||||||
|
case "json":
|
||||||
|
if ok := c.PrintJsonItem(c.monthlyActiveUsers.GetResponse()); !ok {
|
||||||
|
return false, fmt.Errorf("error formatting as JSON")
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||||
|
var helpStr string
|
||||||
|
switch c.Func {
|
||||||
|
case "":
|
||||||
|
helpStr = base.WrapForHelpText([]string{
|
||||||
|
"Usage: boundary billing [sub command] [options] [args]",
|
||||||
|
"",
|
||||||
|
" This command allows for collecting Boundary billing reports. Example:",
|
||||||
|
"",
|
||||||
|
" Monthly active users:",
|
||||||
|
"",
|
||||||
|
` $ boundary billing monthly-active-users`,
|
||||||
|
"",
|
||||||
|
" Please see the billing subcommand help for detailed usage information.",
|
||||||
|
})
|
||||||
|
case "monthly-active-users":
|
||||||
|
helpStr = base.WrapForHelpText([]string{
|
||||||
|
"Usage: boundary billing monthly-active-users [options]",
|
||||||
|
"",
|
||||||
|
" This command allows for collecting active Boundary user reports, by month. Example:",
|
||||||
|
"",
|
||||||
|
" Monthly active users between September 2023 and February 2024:",
|
||||||
|
"",
|
||||||
|
` $ boundary billing monthly-active-users -start-time="2023-09" -end-time="2024-02"`,
|
||||||
|
"",
|
||||||
|
" Please see the billing subcommand help for detailed usage information.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return helpStr + c.Flags().Help()
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
# Copyright (c) HashiCorp, Inc.
|
||||||
|
# SPDX-License-Identifier: BUSL-1.1
|
||||||
|
|
||||||
|
function active_users_last_two_months() {
|
||||||
|
boundary billing monthly-active-users -format json
|
||||||
|
}
|
||||||
|
|
||||||
|
function active_users_start_time() {
|
||||||
|
boundary billing monthly-active-users -start-time=$1 -format json
|
||||||
|
}
|
||||||
|
|
||||||
|
function active_users_start_time_and_end_time() {
|
||||||
|
boundary billing monthly-active-users -start-time=$1 -end-time=$2 -format json
|
||||||
|
}
|
||||||
|
|
||||||
|
function active_users_end_time() {
|
||||||
|
boundary billing monthly-active-users -end-time=$1 -format json
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load _auth
|
||||||
|
load _billing
|
||||||
|
load _helpers
|
||||||
|
|
||||||
|
@test "boundary/billing: can login as admin user" {
|
||||||
|
run login $DEFAULT_LOGIN
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: admin user can get last two months" {
|
||||||
|
run active_users_last_two_months
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
run has_status_code "$output" "200"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: admin user can get report with start time" {
|
||||||
|
run active_users_start_time "2023-09"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
run has_status_code "$output" "200"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: admin user can get report with start and end times" {
|
||||||
|
run active_users_start_time_and_end_time "2023-09" "2023-12"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
run has_status_code "$output" "200"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: cannot get report with end time before start time" {
|
||||||
|
run active_users_start_time_and_end_time "2023-09" "2023-08"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: cannot get report with only end time" {
|
||||||
|
run active_users_end_time "2023-09"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
# unpriv tests
|
||||||
|
@test "boundary/billing: can login as unpriv user" {
|
||||||
|
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: default user cannot get last two months" {
|
||||||
|
run active_users_last_two_months
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: default user cannot get report with start time" {
|
||||||
|
run active_users_start_time "2023-09"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
run has_status_code "$output" "200"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "boundary/billing: default user cannot get report with start and end times" {
|
||||||
|
run active_users_start_time_and_end_time "2023-09" "2023-12"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
run has_status_code "$output" "200"
|
||||||
|
}
|
||||||
Loading…
Reference in new issue