Add device name to Keybase
This commit is contained in:
14
keybase.go
14
keybase.go
@ -29,6 +29,7 @@ func NewKeybase(path ...string) *Keybase {
|
|||||||
k.LoggedIn = k.loggedIn()
|
k.LoggedIn = k.loggedIn()
|
||||||
if k.LoggedIn {
|
if k.LoggedIn {
|
||||||
k.Username = k.username()
|
k.Username = k.username()
|
||||||
|
k.Device = k.device()
|
||||||
}
|
}
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
@ -78,6 +79,19 @@ func (k *Keybase) username() string {
|
|||||||
return s.Username
|
return s.Username
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// device returns the device name of the currently provisioned device.
|
||||||
|
func (k *Keybase) device() string {
|
||||||
|
cmdOut, err := k.Exec("status", "-j")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var s status
|
||||||
|
json.Unmarshal(cmdOut, &s)
|
||||||
|
|
||||||
|
return s.Device.Name
|
||||||
|
}
|
||||||
|
|
||||||
// loggedIn returns true if Keybase is currently logged in, otherwise returns false.
|
// loggedIn returns true if Keybase is currently logged in, otherwise returns false.
|
||||||
func (k *Keybase) loggedIn() bool {
|
func (k *Keybase) loggedIn() bool {
|
||||||
cmdOut, err := k.Exec("status", "-j")
|
cmdOut, err := k.Exec("status", "-j")
|
||||||
|
|||||||
7
types.go
7
types.go
@ -518,6 +518,7 @@ type Keybase struct {
|
|||||||
Username string
|
Username string
|
||||||
LoggedIn bool
|
LoggedIn bool
|
||||||
Version string
|
Version string
|
||||||
|
Device string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat holds basic information about a specific conversation
|
// Chat holds basic information about a specific conversation
|
||||||
@ -584,9 +585,15 @@ type keybase interface {
|
|||||||
loggedIn() bool
|
loggedIn() bool
|
||||||
username() string
|
username() string
|
||||||
version() string
|
version() string
|
||||||
|
device() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type status struct {
|
type status struct {
|
||||||
Username string `json:"Username"`
|
Username string `json:"Username"`
|
||||||
LoggedIn bool `json:"LoggedIn"`
|
LoggedIn bool `json:"LoggedIn"`
|
||||||
|
Device device `json:"Device"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type device struct {
|
||||||
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user