Skip to content

Commit

Permalink
feat: cost drift
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Aug 3, 2023
1 parent e644b31 commit a46ad4f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
70 changes: 70 additions & 0 deletions cmds/invoice/drift/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package drift

import (
"context"
"encoding/json"
"io"
"time"

"github.com/alphauslabs/blue-internal-go/tucp/v1"
"github.com/alphauslabs/bluectl/pkg/logger"
"github.com/alphauslabs/tucp/pkg/connection"
"github.com/spf13/cobra"
)

func ListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list <orgId:id|compId1[,compIdn]> [yyyymm]",
Short: "List cost drift information",
Long: `List cost drift information. If your id has an 'orgId:' prefix, id is
considered an orgId (mspId). If there's no prefix, it is considered
a single companyId or a comma-separated list of companyIds.
If [yyyymm] is not provided, it defaults to the current month.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
logger.Error("<id> is required. See -h for usage.")
return
}

ctx := context.Background()
con, err := connection.New(ctx)
if err != nil {
logger.Errorf("connection.New failed: %v", err)
return
}

month := time.Now().UTC().Format("200601")
if len(args) > 1 {
month = args[1]
}

defer con.Close()
client := tucp.NewTuControlPlaneClient(con)
req := tucp.ReadCostDriftRequest{Id: args[0], Month: month}
stream, err := client.ReadCostDrift(ctx, &req)
if err != nil {
logger.Errorf("ReadCostDrift failed: %v", err)
return
}

loop:
for {
v, err := stream.Recv()
switch {
case err == io.EOF:
break loop
case err != nil && err != io.EOF:
logger.Error(err)
break loop
}

b, _ := json.Marshal(v)
logger.Info(string(b))
}
},
}

cmd.Flags().SortFlags = false
return cmd
}
24 changes: 24 additions & 0 deletions cmds/invoice/drift/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package drift

import (
"github.com/alphauslabs/bluectl/pkg/logger"
"github.com/spf13/cobra"
)

func DriftCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "drift",
Short: "Subcommand for drift-related operations",
Long: `Subcommand for drift-related operations.`,
Run: func(cmd *cobra.Command, args []string) {
logger.Info("see -h for more information")
},
}

cmd.Flags().SortFlags = false
cmd.AddCommand(
ListCmd(),
)

return cmd
}
2 changes: 2 additions & 0 deletions cmds/invoice/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package invoice

import (
"github.com/alphauslabs/bluectl/pkg/logger"
"github.com/alphauslabs/tucp/cmds/invoice/drift"
"github.com/spf13/cobra"
)

Expand All @@ -19,6 +20,7 @@ func InvoiceCmd() *cobra.Command {
cmd.AddCommand(
StartCmd(),
PrioritizeCmd(),
drift.DriftCmd(),
)

return cmd
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/alphauslabs/tucp
go 1.20

require (
github.com/alphauslabs/blue-internal-go v0.12.1
github.com/alphauslabs/blue-internal-go v0.13.1
github.com/alphauslabs/bluectl v0.34.12
github.com/fatih/color v1.15.0
github.com/spf13/cobra v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdi
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/alphauslabs/blue-internal-go v0.12.1 h1:GtKFVNQfa4XJZfdrxqZKn0RxGi6CXSG+GK/O8SjDQnU=
github.com/alphauslabs/blue-internal-go v0.12.1/go.mod h1:vGxoJsulgwXfaeD8frjDQ8zdkcNle1Nly/kMeb+2g/U=
github.com/alphauslabs/blue-internal-go v0.13.1 h1:e4OMoacoJNSWkNyHkc7JVi0iqaKabGEE94QCMgwB2dk=
github.com/alphauslabs/blue-internal-go v0.13.1/go.mod h1:vGxoJsulgwXfaeD8frjDQ8zdkcNle1Nly/kMeb+2g/U=
github.com/alphauslabs/bluectl v0.34.12 h1:aoWpp/idpdzTWixSbcaEBXDCcykYxLZK1P+e/owTqE8=
github.com/alphauslabs/bluectl v0.34.12/go.mod h1:mV0slUtKni1oP6HeroZcw8Jb5BxeC5Ty4S3Ay6CcC34=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down

0 comments on commit a46ad4f

Please sign in to comment.