Skip to content
Permalink
Browse files

Remove tokens from Logins

  • Loading branch information...
frioux committed Apr 6, 2019
1 parent 00a00f3 commit 10d64a420bfdc8974834d8d90c541a8d8f25ddb9
Showing with 22 additions and 19 deletions.
  1. +22 −19 pkg/netrc/netrc.go
@@ -17,14 +17,13 @@ var ErrInvalidNetrc = errors.New("Invalid netrc")
type Netrc struct {
Path string
logins []*Login
tokens []string
}

// Login from the netrc file
type Login struct {
Name string
IsDefault bool
tokens []string

Name, Login, Password, Account, Macdef string
}

// Parse the netrc file at the given path
@@ -126,28 +125,32 @@ func parse(tokens []string) (Netrc, error) {
machine.Name = tokens[i+2]
}
}
if machine == nil {
n.tokens = append(n.tokens, token)
} else {
machine.tokens = append(machine.tokens, token)
switch token {
case "login":
machine.Login = tokens[i+2]
case "password":
machine.Password = tokens[i+2]
case "account":
machine.Account = tokens[i+2]
case "macdef":
machine.Macdef = tokens[i+2]
}
}
return n, nil
}

// Get a property from a machine
func (m *Login) Get(name string) string {
i := 4
if m.IsDefault {
i = 2
}
for {
if i+2 >= len(m.tokens) {
return ""
}
if m.tokens[i] == name {
return m.tokens[i+2]
}
i = i + 4
switch name {
case "login":
return m.Login
case "password":
return m.Password
case "account":
return m.Account
case "macdef":
return m.Macdef
default:
return "???"
}
}

0 comments on commit 10d64a4

Please sign in to comment.
You can’t perform that action at this time.