diff --git a/cmd/sg.go b/cmd/sg.go index caae1d0..9d9cc2f 100644 --- a/cmd/sg.go +++ b/cmd/sg.go @@ -10,46 +10,41 @@ import ( "github.com/surajincloud/awsctl/pkg/ec2" ) - - var sgCmd = &cobra.Command{ - Use: "sgrp", + Use: "sg", Short: "Print Security Groups", Long: ` - For Example: $ awsctl get sgrp + For Example: $ awsctl get sg `, Run: getSG, - } -func getSG(cmd *cobra.Command, args[]string){ +func getSG(cmd *cobra.Command, args []string) { - var sgroup []ec2.SECURITYGRP + var sgroup []ec2.SecurityGroup - sgroup,err:= ec2.DescribeSecurityGroup(cmd,args) - if err!=nil{ + sgroup, err := ec2.DescribeSecurityGroup(cmd, args) + if err != nil { log.Fatal("Unable to get Security Group") } - w:= tabwriter.NewWriter(os.Stdout,18,5,3,' ',tabwriter.TabIndent) + w := tabwriter.NewWriter(os.Stdout, 18, 5, 3, ' ', tabwriter.TabIndent) defer w.Flush() - fmt.Fprintln(w,"NAME","\t","GROUP ID","\t","DESCRIPTION") + fmt.Fprintln(w, "NAME", "\t", "GROUP ID", "\t", "DESCRIPTION") - for _,i:= range sgroup{ + for _, i := range sgroup { - fmt.Fprintln(w,i.SGName,"\t", - i.SGId,"\t", - i.SGDescription,"\t", - ) + fmt.Fprintln(w, i.SGName, "\t", + i.SGId, "\t", + i.SGDescription, "\t", + ) } - - } -func init(){ +func init() { getCmd.AddCommand(sgCmd) } diff --git a/pkg/ec2/getSG.go b/pkg/ec2/getSG.go index 54bea75..68596b2 100644 --- a/pkg/ec2/getSG.go +++ b/pkg/ec2/getSG.go @@ -6,37 +6,29 @@ import ( "github.com/spf13/cobra" ) - - -type SECURITYGRP struct { - - SGName string - SGId string - SGDescription string - +type SecurityGroup struct { + SGName string + SGId string + SGDescription string } +func DescribeSecurityGroup(cmd *cobra.Command, args []string) ([]SecurityGroup, error) { -func DescribeSecurityGroup(cmd *cobra.Command, args []string) ([]SECURITYGRP,error){ + var securityGrp []SecurityGroup - var securityGrp []SECURITYGRP + ctx, client := Ec2Client(cmd, args) + input := &ec2.DescribeSecurityGroupsInput{} + info, err := client.DescribeSecurityGroups(ctx, input) - ctx,client:= Ec2Client(cmd,args) - input:= &ec2.DescribeSecurityGroupsInput{} - info,err:= client.DescribeSecurityGroups(ctx,input) - - - for _, i:= range info.SecurityGroups{ - securityGrp=append(securityGrp, SECURITYGRP{ - SGName: aws.ToString(i.GroupName), - SGId: aws.ToString(i.GroupId), + for _, i := range info.SecurityGroups { + securityGrp = append(securityGrp, SecurityGroup{ + SGName: aws.ToString(i.GroupName), + SGId: aws.ToString(i.GroupId), SGDescription: aws.ToString(i.Description), - }) } - return securityGrp,err + return securityGrp, err } -