Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add okta_app_oauth_post_logout_redirect_uri resource #931

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ the provider, but we don't quite have the manpower yet to do so.
Attribute Schemas.
- [okta_user](./okta_user) Supports the management of Okta Users.
- [okta_users](./okta_users) Data source to retrieve a group of users.
- [okta_app_oauth_post_logout_redirect_uri](./okta_app_oauth_post_logout_redirect_uri) Supports decentralizing post logout redirect uri config.
- [okta_app_oauth_redirect_uri](./okta_app_oauth_redirect_uri) Supports decentralizing redirect uri config. Due to
Okta's API not allowing this field to be null, you must set a redirect uri in your app, and ignore changes to this
attribute. We follow TF best practices and detect config drift. The best case scenario is Okta makes this field
Expand Down
6 changes: 6 additions & 0 deletions examples/okta_app_oauth_post_logout_redirect_uri/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# okta_app_oauth_post_logout_redirect_uri

Resource to support configuring post logout redirect
uris. [See Okta documentation for more details](https://developer.okta.com/docs/api/resources/apps#settings-7).

- Simple example [can be found here](./basic.tf)
23 changes: 23 additions & 0 deletions examples/okta_app_oauth_post_logout_redirect_uri/basic.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This would normally be in another repo if you were decentralizing redirect_uri settings
resource "okta_app_oauth" "test" {
label = "testAcc_replace_with_uuid"
type = "web"
grant_types = ["authorization_code"]
response_types = ["code"]

// Okta requires at least one redirect URI to create an app
redirect_uris = ["myapp://callback"]

// After logout, Okta redirects users to one of these URIs
post_logout_redirect_uris = ["https://www.example.com"]

// Since Okta forces us to create it with a redirect URI we have to ignore future changes, they will be detected as config drift.
lifecycle {
ignore_changes = [redirect_uris]
}
}

resource "okta_app_oauth_post_logout_redirect_uri" "test" {
app_id = okta_app_oauth.test.id
uri = "http://google.com"
}
24 changes: 24 additions & 0 deletions examples/okta_app_oauth_post_logout_redirect_uri/basic_updated.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This would normally be in another repo if you were decentralizing redirect_uri settings
resource "okta_app_oauth" "test" {
label = "testAcc_replace_with_uuid"
type = "web"
grant_types = ["authorization_code"]
response_types = ["code"]

// Okta requires at least one redirect URI to create an app
redirect_uris = ["myapp://callback"]

// After logout, Okta redirects users to one of these URIs
post_logout_redirect_uris = ["https://www.example.com"]


// Since Okta forces us to create it with a redirect URI we have to ignore future changes, they will be detected as config drift.
lifecycle {
ignore_changes = [redirect_uris]
}
}

resource "okta_app_oauth_post_logout_redirect_uri" "test" {
app_id = okta_app_oauth.test.id
uri = "https://www.example-updated.com"
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/zclconf/go-cty v1.9.1 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/mod v0.4.0 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb // indirect
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c // indirect
google.golang.org/api v0.34.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20211029142109-e255c875f7c7 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -595,8 +596,8 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb h1:KVWk3RW1AZlxWum4tYqegLgwJHb5oouozcGM8HfNQaw=
golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c h1:dS09fXwOFF9cXBnIzZexIuUBj95U1NyQjkEhkgidDow=
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
51 changes: 51 additions & 0 deletions okta/internal/mutexkv/mutexkv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package mutexkv

import (
"log"
"sync"
)

// MutexKV is a simple key/value store for arbitrary mutexes. It can be used to
// serialize changes across arbitrary collaborators that share knowledge of the
// keys they must serialize on.
//
// The initial use case is to let aws_security_group_rule resources serialize
// their access to individual security groups based on SG ID.
type MutexKV struct {
lock sync.Mutex
store map[string]*sync.Mutex
}

// Locks the mutex for the given key. Caller is responsible for calling Unlock
// for the same key.
func (m *MutexKV) Lock(key string) {
log.Printf("[DEBUG] Locking %q", key)
m.get(key).Lock()
log.Printf("[DEBUG] Locked %q", key)
}

// Unlock the mutex for the given key. Caller must have called Lock for the same key first.
func (m *MutexKV) Unlock(key string) {
log.Printf("[DEBUG] Unlocking %q", key)
m.get(key).Unlock()
log.Printf("[DEBUG] Unlocked %q", key)
}

// Returns a mutex for the given key, no guarantee of its lock status.
func (m *MutexKV) get(key string) *sync.Mutex {
m.lock.Lock()
defer m.lock.Unlock()
mutex, ok := m.store[key]
if !ok {
mutex = &sync.Mutex{}
m.store[key] = mutex
}
return mutex
}

// Returns a properly initialized MutexKV.
func NewMutexKV() *MutexKV {
return &MutexKV{
store: make(map[string]*sync.Mutex),
}
}
67 changes: 67 additions & 0 deletions okta/internal/mutexkv/mutexkv_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package mutexkv

import (
"testing"
"time"
)

func TestMutexKVLock(t *testing.T) {
mkv := NewMutexKV()

mkv.Lock("foo")

doneCh := make(chan struct{})

go func() {
mkv.Lock("foo")
close(doneCh)
}()

select {
case <-doneCh:
t.Fatal("Second lock was able to be taken. This shouldn't happen.")
case <-time.After(50 * time.Millisecond):
// pass
}
}

func TestMutexKVUnlock(t *testing.T) {
mkv := NewMutexKV()

mkv.Lock("foo")
mkv.Unlock("foo")

doneCh := make(chan struct{})

go func() {
mkv.Lock("foo")
close(doneCh)
}()

select {
case <-doneCh:
// pass
case <-time.After(50 * time.Millisecond):
t.Fatal("Second lock blocked after unlock. This shouldn't happen.")
}
}

func TestMutexKVDifferentKeys(t *testing.T) {
mkv := NewMutexKV()

mkv.Lock("foo")

doneCh := make(chan struct{})

go func() {
mkv.Lock("bar")
close(doneCh)
}()

select {
case <-doneCh:
// pass
case <-time.After(50 * time.Millisecond):
t.Fatal("Second lock on a different key blocked. This shouldn't happen.")
}
}
Loading