summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/admin.go105
1 files changed, 105 insertions, 0 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index e957860..f3af058 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -63,6 +63,24 @@ var adminStatsCmd = &cobra.Command{
RunE: runAdminStats,
}
+var adminUsageLogsCmd = &cobra.Command{
+ Use: "usage-logs",
+ Short: "Raw credit usage log entries",
+ RunE: runAdminUsageLogs,
+}
+
+var adminUsageByEndpointCmd = &cobra.Command{
+ Use: "usage-by-endpoint",
+ Short: "Credit usage aggregated by endpoint",
+ RunE: runAdminUsageByEndpoint,
+}
+
+var adminUsageByAccountCmd = &cobra.Command{
+ Use: "usage-by-account",
+ Short: "Credit usage aggregated by account",
+ RunE: runAdminUsageByAccount,
+}
+
var adminEditCmd = &cobra.Command{
Use: "edit [api_key]",
Short: "Edit account properties",
@@ -80,6 +98,17 @@ func init() {
adminCmd.AddCommand(adminDisableCmd)
adminCmd.AddCommand(adminStatsCmd)
adminCmd.AddCommand(adminEditCmd)
+ adminCmd.AddCommand(adminUsageLogsCmd)
+ adminCmd.AddCommand(adminUsageByEndpointCmd)
+ adminCmd.AddCommand(adminUsageByAccountCmd)
+
+ adminUsageLogsCmd.Flags().IntP("account-id", "a", 0, "Filter by account ID")
+ adminUsageLogsCmd.Flags().IntP("limit", "l", 100, "Max rows to return")
+ adminUsageByEndpointCmd.Flags().String("from", "", "Start time (RFC3339, e.g. 2026-01-01T00:00:00Z)")
+ adminUsageByEndpointCmd.Flags().String("to", "", "End time (RFC3339)")
+ adminUsageByAccountCmd.Flags().IntP("account-id", "a", 0, "Filter by account ID")
+ adminUsageByAccountCmd.Flags().String("from", "", "Start time (RFC3339)")
+ adminUsageByAccountCmd.Flags().String("to", "", "End time (RFC3339)")
adminCreateCmd.Flags().IntP("credits", "c", 0, "Initial credits")
adminCreateCmd.Flags().BoolP("unlimited", "u", false, "Unlimited credits")
@@ -361,3 +390,79 @@ func runAdminEdit(cmd *cobra.Command, args []string) error {
printOutput(output)
return nil
}
+
+func runAdminUsageLogs(cmd *cobra.Command, args []string) error {
+ c, err := getAdminClient(cmd)
+ if err != nil {
+ return err
+ }
+
+ accountID, _ := cmd.Flags().GetInt("account-id")
+ limit, _ := cmd.Flags().GetInt("limit")
+
+ response, err := c.GetCreditUsageLogs(accountID, limit)
+ if err != nil {
+ return err
+ }
+ if err := checkError(response.Error); err != nil {
+ return err
+ }
+
+ output, err := formatter.FormatCreditUsageLogs(response, IsJSONOutput())
+ if err != nil {
+ return err
+ }
+ printOutput(output)
+ return nil
+}
+
+func runAdminUsageByEndpoint(cmd *cobra.Command, args []string) error {
+ c, err := getAdminClient(cmd)
+ if err != nil {
+ return err
+ }
+
+ from, _ := cmd.Flags().GetString("from")
+ to, _ := cmd.Flags().GetString("to")
+
+ response, err := c.GetCreditUsageByEndpoint(from, to)
+ if err != nil {
+ return err
+ }
+ if err := checkError(response.Error); err != nil {
+ return err
+ }
+
+ output, err := formatter.FormatCreditUsageByEndpoint(response, IsJSONOutput())
+ if err != nil {
+ return err
+ }
+ printOutput(output)
+ return nil
+}
+
+func runAdminUsageByAccount(cmd *cobra.Command, args []string) error {
+ c, err := getAdminClient(cmd)
+ if err != nil {
+ return err
+ }
+
+ accountID, _ := cmd.Flags().GetInt("account-id")
+ from, _ := cmd.Flags().GetString("from")
+ to, _ := cmd.Flags().GetString("to")
+
+ response, err := c.GetCreditUsageByAccount(accountID, from, to)
+ if err != nil {
+ return err
+ }
+ if err := checkError(response.Error); err != nil {
+ return err
+ }
+
+ output, err := formatter.FormatCreditUsageByAccount(response, IsJSONOutput())
+ if err != nil {
+ return err
+ }
+ printOutput(output)
+ return nil
+}