-
Notifications
You must be signed in to change notification settings - Fork 38
/
get.go
41 lines (32 loc) · 890 Bytes
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package availability_zone
import (
"fmt"
"os"
"github.com/awslabs/eksdemo/pkg/aws"
"github.com/awslabs/eksdemo/pkg/printer"
"github.com/awslabs/eksdemo/pkg/resource"
)
type Getter struct {
ec2Client *aws.EC2Client
}
func NewGetter(ec2Client *aws.EC2Client) *Getter {
return &Getter{ec2Client}
}
func (g *Getter) Init() {
if g.ec2Client == nil {
g.ec2Client = aws.NewEC2Client()
}
}
func (g *Getter) Get(name string, output printer.Output, options resource.Options) error {
azOptions, ok := options.(*AvailabilityZoneOptions)
if !ok {
return fmt.Errorf("internal error, unable to cast options to AvailabilityZoneOptions")
}
// If getting by name, lookup all zones
allZones := azOptions.AllZones || name != ""
zones, err := g.ec2Client.DescribeAvailabilityZones(name, allZones)
if err != nil {
return err
}
return output.Print(os.Stdout, NewPrinter(zones))
}