Skip to content

Commit

Permalink
Instance state & fixes golint error
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshsonawane1372 committed May 2, 2023
1 parent b38a078 commit 426badb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
10 changes: 6 additions & 4 deletions cmd/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ func getEC2(cmd *cobra.Command, args []string) {
if Keys!="" && strings.Contains(Keys, "=") {
tags := strings.SplitN(Keys, "=", 2)
value := strings.Split(tags[1], ",")
ec2Instance = ec2.DescribeInstance(*&tags[0], value,cmd,args)
ec2Instance = ec2.DescribeInstance(tags[0], value,cmd,args)
} else if Keys!=""{
ec2Instance = ec2.DescribeInstance(*&Keys, nil,cmd,args)
ec2Instance = ec2.DescribeInstance(Keys, nil,cmd,args)
}else{
ec2Instance = ec2.DescribeInstance("", nil,cmd,args)
}

w := tabwriter.NewWriter(os.Stdout, 18, 5, 3, ' ', tabwriter.TabIndent)
defer w.Flush()

fmt.Fprintln(w, "NAME", "\t", "INSTANCE_ID", "\t", "INSTANCE_TYPE", "\t", "PRIVATE IP")
fmt.Fprintln(w, "NAME", "\t", "INSTANCE_ID", "\t", "INSTANCE_TYPE", "\t", "PRIVATE IP","\t", "INSTANCE_STATUS")
for _, i := range ec2Instance {
fmt.Fprintln(
w, i.InstanceName, "\t",
i.InstanceID, "\t",
i.InstanceType, "\t",
i.InstancePrivateIP)
i.InstancePrivateIP, "\t",
i.InstanceStatus,
)
}

}
Expand Down
10 changes: 0 additions & 10 deletions cmd/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,4 @@ func getS3(cmd *cobra.Command, args []string) error {

func init() {
getCmd.AddCommand(s3Cmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// s3Cmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// s3Cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
2 changes: 1 addition & 1 deletion cmd/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/spf13/cobra"
"github.com/surajincloud/awsctl/pkg/vpc"
"github.com/surajincloud/awsctl/pkg/VPC"
)

var vpcCmd = &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions pkg/VPC/getVPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func GetVPC() ([]Vpc, error) {
for _, i := range info.Vpcs {
for _, j := range i.Tags {
if *j.Key == "Name" {
vpcList = append(vpcList, Vp
getVpc = append(getVpc, Vpc{
Name: aws.String(*j.Value),
State: aws.String(string(*&i.State)),
State: aws.String(string(i.State)),
Ipv4Cidr: aws.String(*i.CidrBlock),
Default: *i.IsDefault,
VpcID: aws.String(*i.VpcId),
Expand All @@ -48,6 +48,6 @@ func GetVPC() ([]Vpc, error) {
}
}

return vpcList, err
return getVpc, err

}
11 changes: 7 additions & 4 deletions pkg/ec2/getEc2Info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type EC2Instance struct {
InstanceID string
InstanceType string
InstancePrivateIP string
InstanceStatus string
}

func DescribeInstance(tagName string, tagValue []string, cmd *cobra.Command, args []string) []EC2Instance {
Expand All @@ -39,17 +40,19 @@ func DescribeInstance(tagName string, tagValue []string, cmd *cobra.Command, arg
ec2Instance = append(ec2Instance, EC2Instance{
InstanceName: aws.ToString(j.Value),
InstanceID: aws.ToString(i.InstanceId),
InstanceType: *aws.String(string(*&i.InstanceType)),
InstancePrivateIP: aws.ToString(*&i.PrivateIpAddress),
InstanceType: *aws.String(string(i.InstanceType)),
InstancePrivateIP: aws.ToString(i.PrivateIpAddress),
InstanceStatus: aws.ToString((*string)(&i.State.Name)),
})
}
}
} else {
ec2Instance = append(ec2Instance, EC2Instance{
InstanceName: aws.ToString(j.Value),
InstanceID: aws.ToString(i.InstanceId),
InstanceType: *aws.String(string(*&i.InstanceType)),
InstancePrivateIP: aws.ToString(*&i.PrivateIpAddress),
InstanceType: *aws.String(string(i.InstanceType)),
InstancePrivateIP: aws.ToString(i.PrivateIpAddress),
InstanceStatus: aws.ToString((*string)(&i.State.Name)),
})
}
}
Expand Down

0 comments on commit 426badb

Please sign in to comment.