From 58258ca69f01f4cfc3307ff950842df7242991b9 Mon Sep 17 00:00:00 2001 From: Philip Deuchler Date: Mon, 15 May 2017 15:59:29 -0600 Subject: [PATCH 1/2] Initial commit --- .../passwordExpiryWatcher.go | 5 +- jcapi-systemusers.go | 48 ++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go b/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go index 5c529ad..c737ccd 100644 --- a/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go +++ b/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go @@ -7,6 +7,7 @@ import ( "log" "os" "path/filepath" + "strconv" "time" "github.com/TheJumpCloud/jcapi" @@ -52,7 +53,7 @@ func main() { defer file.Close() w := csv.NewWriter(file) - if err := w.Write([]string{"FIRSTNAME", "LASTNAME", "EMAIL", "PASSWORD EXPIRY DATE", "PASSWORD EXPIRED"}); err != nil { + if err := w.Write([]string{"FIRSTNAME", "LASTNAME", "EMAIL", "PASSWORD EXPIRY DATE", "PASSWORD EXPIRED", "MFA ENABLED", "MFA VERIFIED"}); err != nil { log.Fatalln("error writing record to csv:", err) } @@ -69,7 +70,7 @@ func main() { } else { passwordExpirationString = record.PasswordExpirationDate.String() } - if err := w.Write([]string{record.FirstName, record.LastName, record.Email, passwordExpirationString, expired}); err != nil { + if err := w.Write([]string{record.FirstName, record.LastName, record.Email, passwordExpirationString, expired, strconv.FormatBool(record.EnableUserPortalMultifactor), strconv.FormatBool(record.TotpEnabled)}); err != nil { log.Fatalln("error writing record to csv:", err) } } diff --git a/jcapi-systemusers.go b/jcapi-systemusers.go index a8b8cbe..a4a1c81 100644 --- a/jcapi-systemusers.go +++ b/jcapi-systemusers.go @@ -9,23 +9,25 @@ import ( // If you add a field here make sure to add corresponding logic to getJCUserFieldsFromInterface type JCUser struct { - Id string `json:"_id,omitempty"` - UserName string `json:"username,omitempty"` - FirstName string `json:"firstname,omitempty"` - LastName string `json:"lastname,omitempty"` - Email string `json:"email"` - Password string `json:"password,omitempty"` - PasswordDate string `json:"password_date,omitempty"` - Activated bool `json:"activated"` - ActivationKey string `json:"activation_key"` - ExpiredWarned bool `json:"expired_warned"` - PasswordExpired bool `json:"password_expired"` - PasswordExpirationDate time.Time `json:"password_expiration_date,omitempty"` - PendingProvisioning bool `json:"pendingProvisioning,omitempty"` - Sudo bool `json:"sudo"` - Uid string `json:"unix_uid"` - Gid string `json:"unix_guid"` - EnableManagedUid bool `json:"enable_managed_uid"` + Id string `json:"_id,omitempty"` + UserName string `json:"username,omitempty"` + FirstName string `json:"firstname,omitempty"` + LastName string `json:"lastname,omitempty"` + Email string `json:"email"` + Password string `json:"password,omitempty"` + PasswordDate string `json:"password_date,omitempty"` + Activated bool `json:"activated"` + ActivationKey string `json:"activation_key"` + ExpiredWarned bool `json:"expired_warned"` + PasswordExpired bool `json:"password_expired"` + PasswordExpirationDate time.Time `json:"password_expiration_date,omitempty"` + PendingProvisioning bool `json:"pendingProvisioning,omitempty"` + Sudo bool `json:"sudo"` + Uid string `json:"unix_uid"` + Gid string `json:"unix_guid"` + EnableManagedUid bool `json:"enable_managed_uid"` + EnableUserPortalMultifactor bool `json:"enable_user_portal_multifactor"` + TotpEnabled bool `json:"totp_enabled"` TagIds []string `json:"tags,omitempty"` // the list of tag IDs that this user should be put in @@ -149,6 +151,18 @@ func getJCUserFieldsFromInterface(fields map[string]interface{}, user *JCUser) e return err } } + if _, exists := fields["enable_user_portal_multifactor"]; exists { + if value, err := strconv.ParseBool(fields["enable_user_portal_multifactor"]); err != nil { + return err + } + user.EnableUserPortalMultifactor = value + } + if _, exists := fields["totp_enabled"]; exists { + if value, err := strconv.ParseBool(fields["totp_enabled"]); err != nil { + return err + } + user.TotpEnabled = value + } return nil } From 375dcee8f189f757549b23cc82696f4bdfee43e1 Mon Sep 17 00:00:00 2001 From: Philip Deuchler Date: Mon, 15 May 2017 16:17:51 -0600 Subject: [PATCH 2/2] Type shenanigans, change params to StringVar --- .../PasswordExpiryWatcher/passwordExpiryWatcher.go | 4 ++-- jcapi-systemusers.go | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go b/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go index c737ccd..3d72cb9 100644 --- a/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go +++ b/examples/PasswordExpiryWatcher/passwordExpiryWatcher.go @@ -19,8 +19,8 @@ func main() { var csvFile string // Obtain the input parameters - flag.StringVar(&csvFile, "output", "o", "-output=") - flag.StringVar(&apiKey, "key", "k", "-key=") + flag.StringVar(&csvFile, "output", "", "-output=") + flag.StringVar(&apiKey, "key", "", "-key=") flag.Parse() if csvFile == "" || apiKey == "" { diff --git a/jcapi-systemusers.go b/jcapi-systemusers.go index a4a1c81..c611651 100644 --- a/jcapi-systemusers.go +++ b/jcapi-systemusers.go @@ -152,16 +152,10 @@ func getJCUserFieldsFromInterface(fields map[string]interface{}, user *JCUser) e } } if _, exists := fields["enable_user_portal_multifactor"]; exists { - if value, err := strconv.ParseBool(fields["enable_user_portal_multifactor"]); err != nil { - return err - } - user.EnableUserPortalMultifactor = value + user.EnableUserPortalMultifactor = fields["enable_user_portal_multifactor"].(bool) } if _, exists := fields["totp_enabled"]; exists { - if value, err := strconv.ParseBool(fields["totp_enabled"]); err != nil { - return err - } - user.TotpEnabled = value + user.TotpEnabled = fields["totp_enabled"].(bool) } return nil }