Skip to content

Commit

Permalink
Have Okta properly handle create/update for org/ttl/max_ttl. (#3236)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai authored Aug 24, 2017
1 parent 950eaee commit f526091
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions builtin/credential/okta/path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"fmt"
"net/url"

"time"

"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
"github.com/sstarcher/go-okta"
"time"
)

func pathConfig(b *backend) *framework.Path {
Expand Down Expand Up @@ -94,7 +95,6 @@ func (b *backend) pathConfigRead(

func (b *backend) pathConfigWrite(
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
org := d.Get("organization").(string)
cfg, err := b.Config(req.Storage)
if err != nil {
return nil, err
Expand All @@ -103,9 +103,14 @@ func (b *backend) pathConfigWrite(
// Due to the existence check, entry will only be nil if it's a create
// operation, so just create a new one
if cfg == nil {
cfg = &ConfigEntry{
Org: org,
}
cfg = &ConfigEntry{}
}

org, ok := d.GetOk("organization")
if ok {
cfg.Org = org.(string)
} else if req.Operation == logical.CreateOperation {
cfg.Org = d.Get("organization").(string)
}

token, ok := d.GetOk("token")
Expand All @@ -129,11 +134,19 @@ func (b *backend) pathConfigWrite(
cfg.BaseURL = d.Get("base_url").(string)
}

ttl := d.Get("ttl").(int)
cfg.TTL = time.Duration(ttl) * time.Second
ttl, ok := d.GetOk("ttl")
if ok {
cfg.TTL = time.Duration(ttl.(int)) * time.Second
} else if req.Operation == logical.CreateOperation {
cfg.TTL = time.Duration(d.Get("ttl").(int)) * time.Second
}

maxTTL := d.Get("max_ttl").(int)
cfg.MaxTTL = time.Duration(maxTTL) * time.Second
maxTTL, ok := d.GetOk("max_ttl")
if ok {
cfg.MaxTTL = time.Duration(maxTTL.(int)) * time.Second
} else if req.Operation == logical.CreateOperation {
cfg.MaxTTL = time.Duration(d.Get("max_ttl").(int)) * time.Second
}

jsonCfg, err := logical.StorageEntryJSON("config", cfg)
if err != nil {
Expand Down

0 comments on commit f526091

Please sign in to comment.