Skip to content

Commit

Permalink
refactor AutodetectYubiKey to IsYubiKeyAutoDetected to reflect the na…
Browse files Browse the repository at this point in the history
…ture of the symbol
  • Loading branch information
bitte-ein-bit committed Dec 17, 2024
1 parent ed1e800 commit 71c8077
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions onelogin/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (

type DeviceOptions struct {
// Detect if a YubiKey is inserted and automatically select the device
AutodetectYubiKey bool
IsYubiKeyAutoDetected bool

// Override all other choices and select this device name if available
MfaDevice string
Expand All @@ -55,25 +55,26 @@ type DeviceOptions struct {
// NewDeviceOptions returns a configured pointer to a DeviceOptions type
func NewDeviceOptions() *DeviceOptions {
d := new(DeviceOptions)
d.setAutodetectYubiKey()
d.detectYubiKey()
d.setMfaDevice()

log.WithFields(log.Fields{
"autodetectYubiKey": d.AutodetectYubiKey,
"MfaDevice": d.MfaDevice,
"IsYubiKeyAutoDetected": d.IsYubiKeyAutoDetected,
"MfaDevice": d.MfaDevice,
}).Debug("created device options configuration")

return d
}

// setAutodetectYubiKey sets the AutodetectYubiKey parameter
func (d *DeviceOptions) setAutodetectYubiKey() {
// detectYubiKey sets the IsYubiKeyAutoDetected parameter
func (d *DeviceOptions) detectYubiKey() {
var a bool
if viper.IsSet("global.autodetect-yubikey") {
a = viper.GetBool("global.autodetect-yubikey")
log.WithField("autodetect-yubikey", a).Trace("global.autodetect-yubikey is set in config")
}
if a && yubikey.IsAttached() {
d.AutodetectYubiKey = true
d.IsYubiKeyAutoDetected = true
return
}
}
Expand Down Expand Up @@ -323,7 +324,7 @@ func getDevice(devices []Device, opts *DeviceOptions) (device *Device, err error
fmt.Printf("MFA device %s not found.\n", opts.MfaDevice)
}

if opts.AutodetectYubiKey {
if opts.IsYubiKeyAutoDetected {
for _, d := range devices {
if d.DeviceType == MFADeviceYubicoYubiKey {
device = &d
Expand Down
4 changes: 2 additions & 2 deletions onelogin/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGetDevice(t *testing.T) {
{
Name: "AutodetectYubiKey",
Devices: deviceList,
Opts: &DeviceOptions{AutodetectYubiKey: true},
Opts: &DeviceOptions{IsYubiKeyAutoDetected: true},
ExpectedDevice: &Device{DeviceID: 01, DeviceType: "Yubico YubiKey"},
ExpectedError: nil,
},
Expand All @@ -60,7 +60,7 @@ func TestGetDevice(t *testing.T) {
{
Name: "SelectedMfaDeviceOverride",
Devices: deviceList,
Opts: &DeviceOptions{AutodetectYubiKey: true, MfaDevice: "Google Authenticator"},
Opts: &DeviceOptions{IsYubiKeyAutoDetected: true, MfaDevice: "Google Authenticator"},
ExpectedDevice: &Device{DeviceID: 03, DeviceType: "Google Authenticator"},
ExpectedError: nil,
},
Expand Down

0 comments on commit 71c8077

Please sign in to comment.