Skip to content

Commit

Permalink
Merge pull request #39 from TheJumpCloud/add_mfa_to_password_expiry_h…
Browse files Browse the repository at this point in the history
…elper

Expand Password Expiry helper to encompass MFA state
  • Loading branch information
pbdeuchler committed May 15, 2017
2 parents 09b3d54 + 015d104 commit ec2989f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
9 changes: 5 additions & 4 deletions examples/PasswordExpiryWatcher/passwordExpiryWatcher.go
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"strconv"
"time"

"github.com/TheJumpCloud/jcapi"
Expand All @@ -18,8 +19,8 @@ func main() {
var csvFile string

// Obtain the input parameters
flag.StringVar(&csvFile, "output", "o", "-output=<filename>")
flag.StringVar(&apiKey, "key", "k", "-key=<API-key-value>")
flag.StringVar(&csvFile, "output", "", "-output=<filename>")
flag.StringVar(&apiKey, "key", "", "-key=<API-key-value>")
flag.Parse()

if csvFile == "" || apiKey == "" {
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}
}
Expand Down
44 changes: 27 additions & 17 deletions jcapi-systemusers.go
Expand Up @@ -14,23 +14,25 @@ type JCUserAttribute struct {

// 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"`

Attributes []JCUserAttribute `json:"attributes,omitempty"`

Expand Down Expand Up @@ -164,6 +166,14 @@ func getJCUserFieldsFromInterface(fields map[string]interface{}, user *JCUser) e
return err
}
}

if _, exists := fields["enable_user_portal_multifactor"]; exists {
user.EnableUserPortalMultifactor = fields["enable_user_portal_multifactor"].(bool)
}

if _, exists := fields["totp_enabled"]; exists {
user.TotpEnabled = fields["totp_enabled"].(bool)
}

if attrs, exists := fields["attributes"]; exists {
attributes := attrs.([]interface{})
Expand Down

0 comments on commit ec2989f

Please sign in to comment.