Skip to content

Commit

Permalink
camel case sg
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshsonawane1372 committed Jul 1, 2023
1 parent 4b5ccfd commit 0f7ff9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 41 deletions.
33 changes: 14 additions & 19 deletions cmd/sg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
36 changes: 14 additions & 22 deletions pkg/ec2/getSG.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}


0 comments on commit 0f7ff9c

Please sign in to comment.