-
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
1 parent
199fe9b
commit 765de27
Showing
24 changed files
with
268 additions
and
6,348 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,16 @@ | ||
package describe | ||
|
||
import ( | ||
"github.com/dream11/odin/cmd" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var describeCmd = &cobra.Command{ | ||
Use: "describe", | ||
Short: "Describe resources", | ||
Long: `Describe resources`, | ||
} | ||
|
||
func init() { | ||
cmd.RootCmd.AddCommand(describeCmd) | ||
} |
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,167 @@ | ||
package describe | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/dream11/odin/internal/service" | ||
"github.com/dream11/odin/pkg/constant" | ||
"github.com/dream11/odin/pkg/table" | ||
environment "github.com/dream11/odin/proto/gen/go/dream11/od/environment/v1" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var name string | ||
var serviceName string | ||
var component string | ||
|
||
var environmentClient = service.Environment{} | ||
var environmentCmd = &cobra.Command{ | ||
Use: "env", | ||
Short: "Describe environments", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
return cobra.NoArgs(cmd, args) | ||
}, | ||
Long: `Describe environment details`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
execute(cmd) | ||
}, | ||
} | ||
|
||
func init() { | ||
environmentCmd.Flags().StringVar(&name, "name", "", "name of the env") | ||
environmentCmd.Flags().StringVar(&serviceName, "service", "", "provisioning type of the environment") | ||
environmentCmd.Flags().StringVar(&component, "component", "", "cloud provider account name") | ||
describeCmd.AddCommand(environmentCmd) | ||
} | ||
|
||
func execute(cmd *cobra.Command) { | ||
ctx := cmd.Context() | ||
params := map[string]string{} | ||
|
||
if serviceName != "" { | ||
params["service"] = serviceName | ||
} | ||
if component != "" { | ||
params["component"] = component | ||
} | ||
response, err := environmentClient.DescribeEnvironment(&ctx, &environment.DescribeEnvironmentRequest{ | ||
Params: params, | ||
EnvName: name, | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal("Failed to describe environment ", err) | ||
} | ||
|
||
outputFormat, err := cmd.Flags().GetString("output") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
writeOutput(response, outputFormat) | ||
} | ||
|
||
func writeOutput(response *environment.DescribeEnvironmentResponse, format string) { | ||
|
||
switch format { | ||
case constant.TEXT: | ||
writeAsText(response) | ||
case constant.JSON: | ||
writeAsJSON(response) | ||
default: | ||
log.Fatal("Unknown output format: ", format) | ||
} | ||
} | ||
|
||
func writeAsText(response *environment.DescribeEnvironmentResponse) { | ||
|
||
tableHeaders := []string{"Name", | ||
"team", | ||
"state", | ||
"autoDeletionTime", | ||
"cloudProviderAccounts", | ||
"createdBy", | ||
"updatedBy", | ||
"createdAt", | ||
"updatedAt", | ||
"services"} | ||
var tableData [][]interface{} | ||
env := response.Environment | ||
var accountInfoList []string | ||
for _, accountInfo := range env.AccountInformation { | ||
accountInfoList = append(accountInfoList, accountInfo.ProviderAccountName) | ||
} | ||
accountInfoListJSON, err := json.Marshal(accountInfoList) | ||
if err != nil { | ||
log.Fatal("Failed to marshal account info list: ", err) | ||
} | ||
|
||
var servicesSummary []map[string]interface{} | ||
for _, svc := range env.Services { | ||
serviceMap := map[string]interface{}{ | ||
"name": svc.Name, | ||
"version": svc.Version, | ||
} | ||
if len(svc.Components) > 0 { | ||
serviceMap["components"] = svc.Components | ||
} | ||
servicesSummary = append(servicesSummary, serviceMap) | ||
} | ||
servicesSummaryJSON, err := json.Marshal(servicesSummary) | ||
if err != nil { | ||
log.Fatal("Failed to marshal services summary: ", err) | ||
} | ||
|
||
tableData = append(tableData, []interface{}{ | ||
*env.Name, | ||
"TODO", | ||
*env.Status, | ||
env.AutoDeletionTime.AsTime().String(), | ||
string(accountInfoListJSON), | ||
*env.CreatedBy, | ||
*env.UpdatedBy, | ||
env.CreatedAt.AsTime().String(), | ||
env.UpdatedAt.AsTime().String(), | ||
string(servicesSummaryJSON), | ||
}) | ||
|
||
table.Write(tableHeaders, tableData) | ||
} | ||
|
||
func writeAsJSON(response *environment.DescribeEnvironmentResponse) { | ||
var environments []map[string]interface{} | ||
env := response.Environment | ||
var accountInfoList []string | ||
for _, accountInfo := range env.AccountInformation { | ||
accountInfoList = append(accountInfoList, accountInfo.ProviderAccountName) | ||
} | ||
|
||
var servicesSummary []map[string]interface{} | ||
for _, svc := range env.Services { | ||
serviceMap := map[string]interface{}{ | ||
"name": svc.Name, | ||
"version": svc.Version, | ||
} | ||
if len(svc.Components) > 0 { | ||
serviceMap["components"] = svc.Components | ||
} | ||
servicesSummary = append(servicesSummary, serviceMap) | ||
} | ||
|
||
environments = append(environments, map[string]interface{}{ | ||
"name": env.Name, | ||
"team": "TODO", | ||
"state": env.Status, | ||
"autoDeletionTime": env.AutoDeletionTime.AsTime().String(), | ||
"cloudProviderAccounts": accountInfoList, | ||
"createdBy": env.CreatedBy, | ||
"updatedBy": env.UpdatedBy, | ||
"createdAt": env.CreatedAt.AsTime().String(), | ||
"updatedAt": env.UpdatedAt.AsTime().String(), | ||
"services": servicesSummary, | ||
}) | ||
|
||
output, _ := json.MarshalIndent(environments, "", " ") | ||
fmt.Print(string(output)) | ||
} |
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
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,29 @@ | ||
syntax = "proto3"; | ||
package dream11.oam.dto.v1; | ||
|
||
import "google/protobuf/struct.proto"; | ||
|
||
option go_package = "github.com/dream11/odin/proto/gen/go/dream11/oam/dto/v1"; | ||
|
||
message ProviderAccount { | ||
string name = 1; | ||
string provider = 2; | ||
string category = 3; | ||
google.protobuf.Struct data = 4; | ||
repeated ProviderServiceAccount services = 5; | ||
bool default = 6; | ||
int64 id = 7; | ||
repeated int64 linked_provider_account_ids = 8; | ||
} | ||
|
||
message ProviderServiceAccountEnriched { | ||
ProviderServiceAccount service = 1; | ||
ProviderAccount account = 2; | ||
} | ||
|
||
message ProviderServiceAccount { | ||
string name = 1; | ||
string category = 2; | ||
google.protobuf.Struct data = 3; | ||
int64 id = 4; | ||
} |
31 changes: 31 additions & 0 deletions
31
proto/dream11/oam/provideraccount/v1/provider_account.proto
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,31 @@ | ||
syntax = "proto3"; | ||
package dream11.oam.provideraccount.v1; | ||
import "dream11/oam/dto/v1/provider_account.proto"; | ||
|
||
option go_package = "github.com/dream11/odin/proto/gen/go/dream11/oam/provideraccount/v1"; | ||
|
||
service ProviderAccountService { | ||
rpc GetProviderAccount(GetProviderAccountRequest) returns (GetProviderAccountResponse) {} | ||
rpc GetProviderAccounts(GetProviderAccountsRequest) returns (GetProviderAccountsResponse) {} | ||
} | ||
|
||
message GetProviderAccountRequest { | ||
map<string, string> headers = 1; | ||
string name = 2; | ||
bool fetch_linked_account_details = 3; | ||
} | ||
|
||
message GetProviderAccountResponse { | ||
dream11.oam.dto.v1.ProviderAccount account = 1; | ||
repeated dream11.oam.dto.v1.ProviderAccount linked_accounts = 2; | ||
} | ||
|
||
message GetProviderAccountsRequest { | ||
map<string, string> headers = 1; | ||
repeated string name = 2; | ||
bool fetch_linked_account_details = 3; | ||
} | ||
|
||
message GetProviderAccountsResponse { | ||
repeated GetProviderAccountResponse accounts = 1; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,4 @@ message DeleteEnvironmentRequest { | |
message DeleteEnvironmentResponse { | ||
string message = 1; | ||
} | ||
|
Oops, something went wrong.