-
Notifications
You must be signed in to change notification settings - Fork 43
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
d8fb5f5
commit 396ae0e
Showing
7 changed files
with
154 additions
and
9 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
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,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 | ||
} |
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,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 | ||
} |
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,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, options resource.Options) error { | ||
fileSystems, err := g.efsClient.DescribeFileSystems(id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return output.Print(os.Stdout, NewPrinter(fileSystems)) | ||
} |
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,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) | ||
} |