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 OIDC auth method and account resource #105

Merged
merged 57 commits into from
May 5, 2021
Merged

Add OIDC auth method and account resource #105

merged 57 commits into from
May 5, 2021

Conversation

malnick
Copy link
Contributor

@malnick malnick commented May 4, 2021

No description provided.

Copy link
Contributor

@jimlambrt jimlambrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple minor suggestions for this PR and some ideas for future PRs.


func resourceAccountOidc() *schema.Resource {
return &schema.Resource{
Description: "The account resource allows you to configure a Boundary account.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might suggest: "a Boundary OIDC account"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to keep this, and account, as-is until we do a refactor across all resources so the descriptions have consistent language.


func resourceAccountPassword() *schema.Resource {
return &schema.Resource{
Description: "The account resource allows you to configure a Boundary account.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "a Boundary password account"

}

func resourceAccountPasswordUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
md := meta.(*metaData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the account's password?

internal/provider/resource_account.go Show resolved Hide resolved
testAccCheckAccountPasswordResourceExists(provider, "boundary_account_password.foo"),
),
},
importStep("boundary_account_password.foo", "password"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ignore the password?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to save it in state.

}`, fooAuthMethodDescUpdate)
)

func TestAccAuthMethodPassword(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add min login name and min password len to these tested attributes?

internal/provider/resource_auth_method_oidc.go Outdated Show resolved Hide resolved
internal/provider/resource_auth_method_oidc.go Outdated Show resolved Hide resolved
d.Set(authmethodOidcClientIdKey, attrs[authmethodOidcClientIdKey].(string))
d.Set(authmethodOidcClientSecretHmacKey, attrs[authmethodOidcClientSecretHmacKey].(string))

if certs, ok := attrs[authmethodOidcIdpCaCertsKey]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider refactoring these if statements to happen inside a for loop that ranges over all the attribute keys. For example (not a complete list of keys, but just an idea)

for _, k := range []string{authmethodOidcIdpCaCertsKey, authmethodOidcAllowedAudiencesKey } {
    if obj, ok := attrs[k]; ok {
        switch obj.(type) {
            case []interface{}:
                d.Set(k, obj.([]interface{}))
            case bool:
                d.Set(k, obj.(bool))
            case string:
                d.Set(k, obj.(string))
            default:
               // raise some error 
        }
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a for loop like this, makes it easier to check that you didn't miss any fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to make this change in a future PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have key clashes that way, you'd probably want to format it as attributes.%s and use k there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact arguably this is already a problem here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's easy to range over values coming from TF. If it is, then naming these with an attributes. prefix and ranging is likely the way to go. Even if it isn't, you should probably ensure things are disambiguated by having the keys that are referencing attributes be prefixed as such.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess since this is the OIDC specific provider maybe it's not a big deal. I'm not really sure.

return setFromOidcAuthMethodResponseMap(d, amrr.GetResponse().Map)
}

func resourceAuthMethodOidcUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future PR idea for both Create/Update: use a common func to build the opts. Not complete but something like:

func buildOpts(d *schema.ResourceData, fields []string) []authmethods.Option {
	opts := []authmethods.Option{}

	m := map[string]func() authmethods.Option{
		NameKey: func() authmethods.Option {
			val, ok := d.GetOk(NameKey)
			if ok {
				return authmethods.WithName(val.(string))
			}
			return authmethods.DefaultName()
		},
		DescriptionKey: func() authmethods.Option {
			val, ok := d.GetOk(DescriptionKey)
			if ok {
				return authmethods.WithName(val.(string))
			}
			return nil
		},
	}
	for _, fieldName := range fields {
		if o := m[fieldName](); o != nil {
			opts = append(opts, o)
		}
	}
	return opts
}

d.Set(authmethodOidcStateKey, attrs[authmethodOidcStateKey].(string))
d.Set(authmethodOidcIssuerKey, attrs[authmethodOidcIssuerKey].(string))
d.Set(authmethodOidcClientIdKey, attrs[authmethodOidcClientIdKey].(string))
d.Set(authmethodOidcClientSecretHmacKey, attrs[authmethodOidcClientSecretHmacKey].(string))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this in fact be set if the user hasn't provided it yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be empty.

@malnick malnick merged commit 3d42195 into main May 5, 2021
@malnick malnick deleted the malnick-oidc-test branch May 5, 2021 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants