Skip to content

Commit

Permalink
Fixing vet and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinesh Kumar committed Aug 30, 2019
1 parent cbd2de8 commit c0f24e1
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func MapActions(ctx context.Context, db store.DB) {
login := InstanceLogin{ctx: ctx, f: db, lister: lister}
srch := searcher{ctx: ctx, lister: lister, finder: db}

actions[config.SshAccess] = AddSSHKeys
actions[config.SSHAccess] = AddSSHKeys
actions[config.RefreshInstances] = Refresher{ctx: ctx, store: db}.RefreshInstances
actions[config.SearchPrefix] = srch.SearchInstancesPrefix
actions[config.SearchRegex] = srch.SearchInstancesRegex
Expand Down
2 changes: 1 addition & 1 deletion actions/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func AddSSHKeys(c gcloud.Client, args config.Args) error {
fmt.Println(fmt.Errorf("describe instance errored %v", err))
return err
}
keys := desc.SshKeys()
keys := desc.SSHKeys()
newKey, err := readKey(args.User, args.SSHFile)
if err != nil {
fmt.Printf("Error adding key to instance %s err: %v\n", inst.Name, err)
Expand Down
1 change: 0 additions & 1 deletion actions/ssh_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type InstanceLogin struct {
lister
}

//TODO: login could be done as search instances and login, otherwise display
func (il InstanceLogin) Login(c gcloud.Client, args config.Args) error {
projs, err := il.lister.Projects(il.ctx, c)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
)

func AddSSHKeyCmd(inst, ssh_key_path string, cfg Config) gcloudCommand {
func AddSSHKeyCmd(inst, kp string, cfg Config) gcloudCommand {
return gcloudCommand{
name: "gcloud",
cmd: fmt.Sprintf("compute instances add-metadata %s --metadata-from-file ssh-keys=%s", inst, ssh_key_path),
cmd: fmt.Sprintf("compute instances add-metadata %s --metadata-from-file ssh-keys=%s", inst, kp),
config: cfg,
}
}
Expand Down
19 changes: 9 additions & 10 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ func loadDefaults(configFile string) (*Defaults, error) {
return nil, err
}
return &appConfig, err
} else {
f, err := os.Open(configFile)
if err != nil {
return nil, fmt.Errorf("config file %s open failed with error %v", configFile, err)
}
}
f, err := os.Open(configFile)
if err != nil {
return nil, fmt.Errorf("config file %s open failed with error %v", configFile, err)
}

err = json.NewDecoder(f).Decode(&appConfig)
if err != nil {
logger.Debugf("Try removing config file %s", configFile)
return nil, fmt.Errorf("reading config file %s failed with error %v", configFile, err)
}
err = json.NewDecoder(f).Decode(&appConfig)
if err != nil {
logger.Debugf("Try removing config file %s", configFile)
return nil, fmt.Errorf("reading config file %s failed with error %v", configFile, err)
}
return &appConfig, nil
}
Expand Down
4 changes: 2 additions & 2 deletions config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Args struct {

type CmdAction string

const SshAccess CmdAction = "ssh_access"
const SSHAccess CmdAction = "ssh_access"
const RefreshInstances CmdAction = "refresh"
const LoginInstances CmdAction = "login"
const SearchPrefix CmdAction = "prefix_search"
Expand Down Expand Up @@ -95,7 +95,7 @@ func MustLoad() {
if args.Filter == "" && args.InstanceName == "" {
log.Fatalf("[Config] mention instances search filter for access")
}
cmdAction = SshAccess
cmdAction = SSHAccess
} else if os.Args[1] == "instances" {
if len(os.Args) < 3 {
instanceCommand.Usage()
Expand Down
6 changes: 3 additions & 3 deletions gcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Client struct {
executor
}

//TODO: get project name as arg
func (c Client) GetInstances(cfg command.Config) ([]Instance, error) {
// TODO: get project name as arg
giCmd := command.GetInstancesCmd(cfg)
out, err := c.Execute(giCmd)
if err != nil {
Expand All @@ -36,8 +36,8 @@ func (c Client) GetInstances(cfg command.Config) ([]Instance, error) {
return insts, nil
}

//TODO: move this to instance
func (c Client) GetDescription(inst string, cfg command.Config) (Description, error) {
//TODO: move this to instance
out, err := c.Execute(command.DescribeCmd(inst, cfg))
if err != nil {
return Description{}, err
Expand Down Expand Up @@ -79,8 +79,8 @@ func (c Client) ListProjects(cfg command.Config) ([]Project, error) {
return projects, err
}

//TODO: move to separate as it doesn't deal with gcloud
func (c Client) Login(ctx context.Context, insts []Instance, cmd string, cfg command.TmuxConfig) (string, error) {
//TODO: move to separate as it doesn't deal with gcloud
var hosts []string
for _, inst := range insts {
if inst.Status != "RUNNING" {
Expand Down
2 changes: 1 addition & 1 deletion gcloud/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Description struct {
Metadata `json:"metadata"`
}

func (d Description) SshKeys() []SSHKey {
func (d Description) SSHKeys() []SSHKey {
for _, i := range d.Items {
if i.Key == "ssh-keys" {
return parseSSHKeys(i.Value)
Expand Down
12 changes: 6 additions & 6 deletions gcloud/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ type Instance struct {
Project string `json:"projectID"`
}

func (ins Instance) String() string {
res := fmt.Sprintf("%-30s : %-50s %-10s", ins.Project, ins.Name, ins.IP())
if ins.ExternalIP() != "" {
return fmt.Sprintf("%s External: %s", res, ins.ExternalIP())
func (i Instance) String() string {
res := fmt.Sprintf("%-30s : %-50s %-10s", i.Project, i.Name, i.IP())
if i.ExternalIP() != "" {
return fmt.Sprintf("%s External: %s", res, i.ExternalIP())
}
return res
}
Expand All @@ -43,8 +43,8 @@ type NetworkInterface struct {
}

type AccessConfig struct {
NatIP string `natIP`
Name string `name`
NatIP string `json:"natIP"`
Name string `json:"name"`
}

func createTempFile(keys []SSHKey) (*os.File, error) {
Expand Down
7 changes: 5 additions & 2 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ type SearchSuite struct {

func (s *SearchSuite) TestSetup() {
logger.SetLevel("error")
s.ctx, _ = context.WithTimeout(context.Background(), time.Second*3)
var canc context.CancelFunc
s.ctx, canc = context.WithTimeout(context.Background(), time.Second*3)
defer canc()
t := s.T()
var err error
s.db, err = store.NewDB("./testdata/search.db")
//TODOL should create the file and delete in teardown
s.db, err = store.NewDB("../testdata/search.db")
s.bucket = "search-instances"
s.instances = []gcloud.Instance{
{Name: "integration-01"},
Expand Down

0 comments on commit c0f24e1

Please sign in to comment.