Skip to content

Commit

Permalink
Add SSM parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
bporter816 committed Feb 2, 2024
1 parent 5a733b0 commit 0cc3b78
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"

// "os/exec"
// "sort"
"strings"
Expand All @@ -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"
Expand Down Expand Up @@ -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{}

Expand All @@ -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,
Expand All @@ -108,6 +112,7 @@ func NewApplication() *Application {
"SQS": sqsRepo,
"STS": stsRepo,
"Secrets Manager": smRepo,
"SSM": ssmRepo,
"Service Quotas": sqRepo,
}

Expand Down
9 changes: 9 additions & 0 deletions model/ssm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package model

import (
ssmTypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
)

type (
SSMParameter ssmTypes.ParameterMetadata
)
36 changes: 36 additions & 0 deletions repo/ssm.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func NewServices(repos map[string]interface{}, app *Application) *Services {
"Service Quotas": {
"Services",
},
"Systems Manager": {
"Parameters",
},
"VPC": {
"VPCs",
"Subnets",
Expand Down Expand Up @@ -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":
Expand Down
69 changes: 69 additions & 0 deletions ssm_parameters.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 8 additions & 0 deletions view/ssm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package view

type SSM struct {
}

func (s SSM) GetService() string {
return "Systems Manager"
}

0 comments on commit 0cc3b78

Please sign in to comment.