-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
flowerinthenight
committed
Aug 3, 2023
1 parent
e644b31
commit a46ad4f
Showing
5 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters