-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlist.go
48 lines (35 loc) · 1.07 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2017 Josh Komoroske. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE.txt file.
package ykman
import (
"os/exec"
)
// List returns all currently configured OATH slot names
func List() ([]string, error) {
cmd := exec.Command("ykman", "oath", "list")
output, err := cmd.CombinedOutput()
return parseList(string(output), err)
}
func parseList(body string, err error) ([]string, error) {
lines := process(body)
if err != nil {
// Check if this is an exec.Error stating that the ykman executable was not found
if execErr, ok := err.(*exec.Error); ok {
if execErr.Err == exec.ErrNotFound {
return nil, ErrorYkmanNotFound
}
}
// Check the case where a YubiKey isn't plugged in
if linesContain(lines, "No YubiKey detected") {
return nil, ErrorYubikeyNotDetected
}
// Case where a YubiKey isn't plugged in
if linesContain(lines, "Failed connecting to the YubiKey") {
return nil, ErrorYubikeyNotDetected
}
// Generic catch-all
return nil, err
}
return lines, nil
}