Skip to content

Commit

Permalink
add: get efs-filesystem (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroniscode authored Sep 4, 2024
1 parent d8fb5f5 commit 0ce9a0b
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/awslabs/eksdemo/pkg/resource/ec2/ami"
"github.com/awslabs/eksdemo/pkg/resource/ec2/instance"
"github.com/awslabs/eksdemo/pkg/resource/ecr_repository"
efsfilesystem "github.com/awslabs/eksdemo/pkg/resource/efs/filesystem"
"github.com/awslabs/eksdemo/pkg/resource/eks/accessentry"
"github.com/awslabs/eksdemo/pkg/resource/elastic_ip"
"github.com/awslabs/eksdemo/pkg/resource/event_rule"
Expand Down Expand Up @@ -91,6 +92,7 @@ func NewGetCmd() *cobra.Command {
cmd.AddCommand(NewGetAliasCmds(cognitoResources, "cognito-")...)
cmd.AddCommand(dns_record.NewResource().NewGetCmd())
cmd.AddCommand(instance.NewResource().NewGetCmd())
cmd.AddCommand(efsfilesystem.NewResource().NewGetCmd())
cmd.AddCommand(ecr_repository.NewResource().NewGetCmd())
cmd.AddCommand(elastic_ip.NewResource().NewGetCmd())
cmd.AddCommand(event_rule.NewResource().NewGetCmd())
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.21.10
require (
github.com/Masterminds/goutils v1.1.1
github.com/Masterminds/sprig/v3 v3.2.3
github.com/aws/aws-sdk-go-v2 v1.30.4
github.com/aws/aws-sdk-go-v2 v1.30.5
github.com/aws/aws-sdk-go-v2/config v1.27.4
github.com/aws/aws-sdk-go-v2/service/acm v1.25.1
github.com/aws/aws-sdk-go-v2/service/amp v1.25.1
Expand All @@ -19,6 +19,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.35.1
github.com/aws/aws-sdk-go-v2/service/ec2 v1.149.2
github.com/aws/aws-sdk-go-v2/service/ecr v1.27.1
github.com/aws/aws-sdk-go-v2/service/efs v1.31.5
github.com/aws/aws-sdk-go-v2/service/eks v1.41.0
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.24.1
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.30.1
Expand All @@ -36,6 +37,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.7.1
github.com/aws/session-manager-plugin v0.0.0-20221012155945-c523002ee02c
github.com/aws/smithy-go v1.20.4
github.com/dustin/go-humanize v1.0.1
github.com/go-resty/resty/v2 v2.7.0
github.com/google/uuid v1.3.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
Expand Down Expand Up @@ -69,8 +71,8 @@ require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 h1:4daAzAu0
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
github.com/aws/aws-sdk-go v1.34.9 h1:cUGBW9CVdi0mS7K1hDzxIqTpfeWhpoQiguq81M1tjK0=
github.com/aws/aws-sdk-go v1.34.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go-v2 v1.30.4 h1:frhcagrVNrzmT95RJImMHgabt99vkXGslubDaDagTk8=
github.com/aws/aws-sdk-go-v2 v1.30.4/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0=
github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g=
github.com/aws/aws-sdk-go-v2 v1.30.5/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 h1:gTK2uhtAPtFcdRRJilZPx8uJLL2J85xK11nKtWL0wfU=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1/go.mod h1:sxpLb+nZk7tIfCWChfd+h4QwHNUR57d8hA1cleTkjJo=
github.com/aws/aws-sdk-go-v2/config v1.27.4 h1:AhfWb5ZwimdsYTgP7Od8E9L1u4sKmDW2ZVeLcf2O42M=
Expand All @@ -81,10 +81,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.17.4 h1:h5Vztbd8qLppiPwX+y0Q6WiwMZgp
github.com/aws/aws-sdk-go-v2/credentials v1.17.4/go.mod h1:+30tpwrkOgvkJL1rUZuRLoxcJwtI/OkeBLYnHxJtVe0=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 h1:AK0J8iYBFeUk2Ax7O8YpLtFsfhdOByh2QIkHmigpRYk=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2/go.mod h1:iRlGzMix0SExQEviAyptRWRGdYNo3+ufW/lCzvKVTUc=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 h1:TNyt/+X43KJ9IJJMjKfa3bNTiZbUP7DeCxfbTROESwY=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16/go.mod h1:2DwJF39FlNAUiX5pAc0UNeiz16lK2t7IaFcm0LFHEgc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 h1:jYfy8UPmd+6kJW5YhY0L1/KftReOGxI/4NtVSTh9O/I=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16/go.mod h1:7ZfEPZxkW42Afq4uQB8H2E2e6ebh6mXTueEpYzjCzcs=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 h1:pI7Bzt0BJtYA0N/JEC6B8fJ4RBrEMi1LBrkMdFYNSnQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17/go.mod h1:Dh5zzJYMtxfIjYW+/evjQ8uj2OyR/ve2KROHGHlSFqE=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 h1:Mqr/V5gvrhA2gvgnF42Zh5iMiQNcOYthFYwCyrnuWlc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17/go.mod h1:aLJpZlCmjE+V+KtN1q1uyZkfnUWpQGpbsn89XPKyzfU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.2 h1:en92G0Z7xlksoOylkUhuBSfJgijC7rHVLRdnIlHEs0E=
Expand All @@ -109,6 +109,8 @@ github.com/aws/aws-sdk-go-v2/service/ec2 v1.149.2 h1:fkyeLQZoBqfchqru+hDTfioQohQ
github.com/aws/aws-sdk-go-v2/service/ec2 v1.149.2/go.mod h1:XxJNg7fIkR8cbm89i0zVZSxKpcPYsC8BWRwMIJOWbnk=
github.com/aws/aws-sdk-go-v2/service/ecr v1.27.1 h1:GFt/4yMrCuMDi4YzKy0HCW9NhwbxoYZUMqIWqWJFsqE=
github.com/aws/aws-sdk-go-v2/service/ecr v1.27.1/go.mod h1:ydHfHlVpaydWdStDKNcV6BnI0fD+ZwlPWvDgVG2fLt0=
github.com/aws/aws-sdk-go-v2/service/efs v1.31.5 h1:McOTl1R1sTdZx57Q7CaeLFgDnhEMOT/adK8sCpprrjM=
github.com/aws/aws-sdk-go-v2/service/efs v1.31.5/go.mod h1:XGcTOlJ2nuj3KemxjGAGc/fpl2Cb8Z0DE+cTnKHmBGU=
github.com/aws/aws-sdk-go-v2/service/eks v1.41.0 h1:/bitqsA6wgIS2vgjtHJi1JG3SOTbobs1mCdeJBLOacY=
github.com/aws/aws-sdk-go-v2/service/eks v1.41.0/go.mod h1:GFqWNwDLyuSevADun69Dg5aurANpv8KNrz2vxYPEqmw=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.24.1 h1:jdxeIGg32hhpOQSRVokquRVh5f6eh3/NChPJmEQ0O9Y=
Expand Down Expand Up @@ -218,6 +220,8 @@ github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQ
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1 h1:ZClxb8laGDf5arXfYcAtECDFgAgHklGI8CxgjHnXKJ4=
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 h1:XBBHcIb256gUJtLmY22n99HaZTz+r2Z51xUPi01m3wg=
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203/go.mod h1:E1jcSv8FaEny+OP/5k9UxZVw9YFWGj7eI4KR/iOBqCg=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
Expand Down
32 changes: 32 additions & 0 deletions pkg/aws/efs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package aws

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/efs"
"github.com/aws/aws-sdk-go-v2/service/efs/types"
)

type EFSClient struct {
*efs.Client
}

func NewEFSClient() *EFSClient {
return &EFSClient{efs.NewFromConfig(GetConfig())}
}

func (c *EFSClient) DescribeFileSystems(fileSystemID string) ([]types.FileSystemDescription, error) {
input := efs.DescribeFileSystemsInput{}

if fileSystemID != "" {
input.FileSystemId = aws.String(fileSystemID)
}

result, err := c.Client.DescribeFileSystems(context.Background(), &input)
if err != nil {
return nil, err
}

return result.FileSystems, nil
}
25 changes: 25 additions & 0 deletions pkg/resource/efs/filesystem/efs_filesystem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package filesystem

import (
"github.com/awslabs/eksdemo/pkg/cmd"
"github.com/awslabs/eksdemo/pkg/resource"
)

func NewResource() *resource.Resource {
res := &resource.Resource{
Command: cmd.Command{
Name: "efs-filesystem",
Description: "EFS File Systems",
Aliases: []string{"efs"},
Args: []string{"ID"},
},

Getter: &Getter{},

Options: &resource.CommonOptions{
ClusterFlagDisabled: true,
},
}

return res
}
32 changes: 32 additions & 0 deletions pkg/resource/efs/filesystem/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package filesystem

import (
"os"

"github.com/awslabs/eksdemo/pkg/aws"
"github.com/awslabs/eksdemo/pkg/printer"
"github.com/awslabs/eksdemo/pkg/resource"
)

type Getter struct {
efsClient *aws.EFSClient
}

func NewGetter(efsClient *aws.EFSClient) *Getter {
return &Getter{efsClient}
}

func (g *Getter) Init() {
if g.efsClient == nil {
g.efsClient = aws.NewEFSClient()
}
}

func (g *Getter) Get(id string, output printer.Output, _ resource.Options) error {
fileSystems, err := g.efsClient.DescribeFileSystems(id)
if err != nil {
return err
}

return output.Print(os.Stdout, NewPrinter(fileSystems))
}
48 changes: 48 additions & 0 deletions pkg/resource/efs/filesystem/printer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package filesystem

import (
"io"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/efs/types"
"github.com/awslabs/eksdemo/pkg/printer"
"github.com/dustin/go-humanize"
"github.com/hako/durafmt"
)

type Printer struct {
fileSystems []types.FileSystemDescription
}

func NewPrinter(fileSystems []types.FileSystemDescription) *Printer {
return &Printer{fileSystems}
}

func (p *Printer) PrintTable(writer io.Writer) error {
table := printer.NewTablePrinter()
table.SetHeader([]string{"Age", "Status", "Id", "Name", "Size"})

for _, fs := range p.fileSystems {
age := durafmt.ParseShort(time.Since(aws.ToTime(fs.CreationTime)))

table.AppendRow([]string{
age.String(),
string(fs.LifeCycleState),
aws.ToString(fs.FileSystemId),
aws.ToString(fs.Name),
humanize.IBytes(uint64(fs.SizeInBytes.Value)),
})
}
table.Print(writer)

return nil
}

func (p *Printer) PrintJSON(writer io.Writer) error {
return printer.EncodeJSON(writer, p.fileSystems)
}

func (p *Printer) PrintYAML(writer io.Writer) error {
return printer.EncodeYAML(writer, p.fileSystems)
}

0 comments on commit 0ce9a0b

Please sign in to comment.