diff --git a/go.mod b/go.mod index ba86a92..6f66b3a 100644 --- a/go.mod +++ b/go.mod @@ -43,6 +43,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.11 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.10 // indirect + github.com/aws/aws-sdk-go-v2/service/ssm v1.44.7 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.14.1 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.1 // indirect github.com/aws/smithy-go v1.19.0 // indirect diff --git a/go.sum b/go.sum index cc087aa..9fd1e28 100644 --- a/go.sum +++ b/go.sum @@ -128,6 +128,8 @@ github.com/aws/aws-sdk-go-v2/service/sqs v1.24.5 h1:RyDpTOMEJO6ycxw1vU/6s0KLFaH3 github.com/aws/aws-sdk-go-v2/service/sqs v1.24.5/go.mod h1:RZBu4jmYz3Nikzpu/VuVvRnTEJ5a+kf36WT2fcl5Q+Q= github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7 h1:tRNrFDGRm81e6nTX5Q4CFblea99eAfm0dxXazGpLceU= github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7/go.mod h1:8GWUDux5Z2h6z2efAtr54RdHXtLm8sq7Rg85ZNY/CZM= +github.com/aws/aws-sdk-go-v2/service/ssm v1.44.7 h1:a8HvP/+ew3tKwSXqL3BCSjiuicr+XTU2eFYeogV9GJE= +github.com/aws/aws-sdk-go-v2/service/ssm v1.44.7/go.mod h1:Q7XIWsMo0JcMpI/6TGD6XXcXcV1DbTj6e9BKNntIMIM= github.com/aws/aws-sdk-go-v2/service/sso v1.14.1 h1:YkNzx1RLS0F5qdf9v1Q8Cuv9NXCL2TkosOxhzlUPV64= github.com/aws/aws-sdk-go-v2/service/sso v1.14.1/go.mod h1:fIAwKQKBFu90pBxx07BFOMJLpRUGu8VOzLJakeY+0K4= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.1 h1:8lKOidPkmSmfUtiTgtdXWgaKItCZ/g75/jEk6Ql6GsA= diff --git a/main.go b/main.go index 8a7a18f..20bb88a 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + // "os/exec" // "sort" "strings" @@ -26,6 +27,7 @@ import ( sq "github.com/aws/aws-sdk-go-v2/service/servicequotas" "github.com/aws/aws-sdk-go-v2/service/sns" "github.com/aws/aws-sdk-go-v2/service/sqs" + "github.com/aws/aws-sdk-go-v2/service/ssm" "github.com/aws/aws-sdk-go-v2/service/sts" "github.com/bporter816/aws-tui/repo" "github.com/bporter816/aws-tui/template" @@ -63,11 +65,12 @@ func NewApplication() *Application { lambdaClient := lambda.NewFromConfig(cfg) r53Client := r53.NewFromConfig(cfg) s3Client := s3.NewFromConfig(cfg) - stsClient := sts.NewFromConfig(cfg) - smClient := sm.NewFromConfig(cfg) snsClient := sns.NewFromConfig(cfg) + smClient := sm.NewFromConfig(cfg) sqClient := sq.NewFromConfig(cfg) sqsClient := sqs.NewFromConfig(cfg) + ssmClient := ssm.NewFromConfig(cfg) + stsClient := sts.NewFromConfig(cfg) a := &Application{} @@ -85,10 +88,11 @@ func NewApplication() *Application { r53Repo := repo.NewRoute53(r53Client) s3Repo := repo.NewS3(s3Client) snsRepo := repo.NewSNS(snsClient) - sqsRepo := repo.NewSQS(sqsClient) - stsRepo := repo.NewSTS(stsClient) smRepo := repo.NewSecretsManager(smClient) sqRepo := repo.NewServiceQuotas(sqClient) + sqsRepo := repo.NewSQS(sqsClient) + ssmRepo := repo.NewSSM(ssmClient) + stsRepo := repo.NewSTS(stsClient) repos := map[string]interface{}{ "ACM": acmRepo, @@ -108,6 +112,7 @@ func NewApplication() *Application { "SQS": sqsRepo, "STS": stsRepo, "Secrets Manager": smRepo, + "SSM": ssmRepo, "Service Quotas": sqRepo, } diff --git a/model/ssm.go b/model/ssm.go new file mode 100644 index 0000000..1ad5ee8 --- /dev/null +++ b/model/ssm.go @@ -0,0 +1,9 @@ +package model + +import ( + ssmTypes "github.com/aws/aws-sdk-go-v2/service/ssm/types" +) + +type ( + SSMParameter ssmTypes.ParameterMetadata +) diff --git a/repo/ssm.go b/repo/ssm.go new file mode 100644 index 0000000..edcbccc --- /dev/null +++ b/repo/ssm.go @@ -0,0 +1,36 @@ +package repo + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/bporter816/aws-tui/model" +) + +type SSM struct { + ssmClient *ssm.Client +} + +func NewSSM(ssmClient *ssm.Client) *SSM { + return &SSM{ + ssmClient: ssmClient, + } +} + +func (s SSM) ListParameters() ([]model.SSMParameter, error) { + pg := ssm.NewDescribeParametersPaginator( + s.ssmClient, + &ssm.DescribeParametersInput{}, + ) + var parameters []model.SSMParameter + for pg.HasMorePages() { + out, err := pg.NextPage(context.TODO()) + if err != nil { + return []model.SSMParameter{}, err + } + for _, v := range out.Parameters { + parameters = append(parameters, model.SSMParameter(v)) + } + } + return parameters, nil +} diff --git a/services.go b/services.go index 4596002..5d6ef3c 100644 --- a/services.go +++ b/services.go @@ -92,6 +92,9 @@ func NewServices(repos map[string]interface{}, app *Application) *Services { "Service Quotas": { "Services", }, + "Systems Manager": { + "Parameters", + }, "VPC": { "VPCs", "Subnets", @@ -227,6 +230,8 @@ func (s Services) selectHandler(n *tview.TreeNode) { item = NewSMSecrets(s.repos["Secrets Manager"].(*repo.SecretsManager), s.app) case "Service Quotas.Services": item = NewServiceQuotasServices(s.repos["Service Quotas"].(*repo.ServiceQuotas), s.app) + case "Systems Manager.Parameters": + item = NewSSMParameters(s.repos["SSM"].(*repo.SSM), s.app) case "VPC.VPCs": item = NewVPCVPCs(s.repos["EC2"].(*repo.EC2), s.app) case "VPC.Subnets": diff --git a/ssm_parameters.go b/ssm_parameters.go new file mode 100644 index 0000000..74efce8 --- /dev/null +++ b/ssm_parameters.go @@ -0,0 +1,69 @@ +package main + +import ( + "strconv" + + "github.com/bporter816/aws-tui/repo" + "github.com/bporter816/aws-tui/ui" + "github.com/bporter816/aws-tui/view" +) + +type SSMParameters struct { + *ui.Table + view.SSM + repo *repo.SSM + app *Application +} + +func NewSSMParameters(repo *repo.SSM, app *Application) *SSMParameters { + s := &SSMParameters{ + Table: ui.NewTable([]string{ + "NAME", + "TIER", + "TYPE", + "DATA TYPE", + }, 1, 0), + repo: repo, + app: app, + } + return s +} + +func (s SSMParameters) GetLabels() []string { + return []string{"Parameters"} +} + +func (s SSMParameters) GetKeyActions() []KeyAction { + return []KeyAction{} +} + +func (s SSMParameters) Render() { + model, err := s.repo.ListParameters() + if err != nil { + panic(err) + } + + var data [][]string + for _, v := range model { + var name, tier, parameterType, dataType, version, policies string + if v.Name != nil { + name = *v.Name + } + tier = string(v.Tier) + parameterType = string(v.Type) + if v.DataType != nil { + dataType = *v.DataType + } + version = strconv.FormatInt(v.Version, 10) + policies = strconv.Itoa(len(v.Policies)) + data = append(data, []string{ + name, + tier, + parameterType, + dataType, + version, + policies, + }) + } + s.SetData(data) +} diff --git a/view/ssm.go b/view/ssm.go new file mode 100644 index 0000000..9941603 --- /dev/null +++ b/view/ssm.go @@ -0,0 +1,8 @@ +package view + +type SSM struct { +} + +func (s SSM) GetService() string { + return "Systems Manager" +}