Skip to content

Commit

Permalink
docs: improve enum handling and completeness (#3714)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored Jan 30, 2024
1 parent 549308d commit 4b881ca
Show file tree
Hide file tree
Showing 28 changed files with 280 additions and 541 deletions.
23 changes: 0 additions & 23 deletions .schema/openapi/patches/identity.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
- op: add
path: /components/schemas/identityState/enum
value:
- active
- inactive
- op: add
path: /components/schemas/identityCredentialsType/enum
value:
- password
- totp
- oidc
- webauthn
- lookup_secret
- code
- op: add
path: /paths/~1admin~1identities~1{id}/get/parameters/1/schema/items/enum
value:
- password
- totp
- oidc
- webauthn
- lookup_secret
- code
- op: remove
path: /components/schemas/updateIdentityBody/properties/metadata_admin/type
- op: remove
Expand Down
22 changes: 11 additions & 11 deletions identity/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,19 @@ func (n NullableAuthenticatorAssuranceLevel) ToAAL() (AuthenticatorAssuranceLeve
// CredentialsType represents several different credential types, like password credentials, passwordless credentials,
// and so on.
//
// swagger:model identityCredentialsType
// swagger:enum CredentialsType
type CredentialsType string

// Please make sure to add all of these values to the test that ensures they are created during migration
const (
CredentialsTypePassword CredentialsType = "password"
CredentialsTypeOIDC CredentialsType = "oidc"
CredentialsTypeTOTP CredentialsType = "totp"
CredentialsTypeLookup CredentialsType = "lookup_secret"
CredentialsTypeWebAuthn CredentialsType = "webauthn"
CredentialsTypeCodeAuth CredentialsType = "code"
)

func (c CredentialsType) String() string {
return string(c)
}
Expand All @@ -101,16 +111,6 @@ func (c CredentialsType) ToUiNodeGroup() node.UiNodeGroup {
}
}

// Please make sure to add all of these values to the test that ensures they are created during migration
const (
CredentialsTypePassword CredentialsType = "password"
CredentialsTypeOIDC CredentialsType = "oidc"
CredentialsTypeTOTP CredentialsType = "totp"
CredentialsTypeLookup CredentialsType = "lookup_secret"
CredentialsTypeWebAuthn CredentialsType = "webauthn"
CredentialsTypeCodeAuth CredentialsType = "code"
)

var AllCredentialTypes = []CredentialsType{
CredentialsTypePassword,
CredentialsTypeOIDC,
Expand Down
16 changes: 5 additions & 11 deletions identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ type getIdentity struct {
//
// required: false
// in: query
DeclassifyCredentials []string `json:"include_credential"`
DeclassifyCredentials []CredentialsType `json:"include_credential"`
}

// swagger:route GET /admin/identities/{id} identity getIdentity
Expand Down Expand Up @@ -932,13 +932,11 @@ type deleteIdentityCredentials struct {
// in: path
ID string `json:"id"`

// Type is the credential's Type.
// One of totp, webauthn, lookup
// Type is the type of credentials to be deleted.
//
// enum: totp,webauthn,lookup
// required: true
// in: path
Type string `json:"type"`
Type CredentialsType `json:"type"`
}

// swagger:route DELETE /admin/identities/{id}/credentials/{type} identity deleteIdentityCredentials
Expand Down Expand Up @@ -977,19 +975,15 @@ func (h *Handler) deleteIdentityCredentials(w http.ResponseWriter, r *http.Reque
}

switch cred.Type {
case CredentialsTypeLookup:
fallthrough
case CredentialsTypeTOTP:
case CredentialsTypeLookup, CredentialsTypeTOTP:
identity.DeleteCredentialsType(cred.Type)
case CredentialsTypeWebAuthn:
identity, err = deletCredentialWebAuthFromIdentity(identity)
if err != nil {
h.r.Writer().WriteError(w, r, err)
return
}
case CredentialsTypeOIDC:
fallthrough
case CredentialsTypePassword:
case CredentialsTypeOIDC, CredentialsTypePassword, CredentialsTypeCodeAuth:
h.r.Writer().WriteError(w, r, errors.WithStack(herodot.ErrBadRequest.WithReasonf("You can't remove first factor credentials.")))
return
default:
Expand Down
2 changes: 1 addition & 1 deletion identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
//
// The state can either be `active` or `inactive`.
//
// swagger:model identityState
// swagger:enum State
type State string

const (
Expand Down
4 changes: 0 additions & 4 deletions internal/client-go/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ docs/IdentityCredentialsCode.md
docs/IdentityCredentialsOidc.md
docs/IdentityCredentialsOidcProvider.md
docs/IdentityCredentialsPassword.md
docs/IdentityCredentialsType.md
docs/IdentityPatch.md
docs/IdentityPatchResponse.md
docs/IdentitySchemaContainer.md
docs/IdentityState.md
docs/IdentityWithCredentials.md
docs/IdentityWithCredentialsOidc.md
docs/IdentityWithCredentialsOidcConfig.md
Expand Down Expand Up @@ -163,11 +161,9 @@ model_identity_credentials_code.go
model_identity_credentials_oidc.go
model_identity_credentials_oidc_provider.go
model_identity_credentials_password.go
model_identity_credentials_type.go
model_identity_patch.go
model_identity_patch_response.go
model_identity_schema_container.go
model_identity_state.go
model_identity_with_credentials.go
model_identity_with_credentials_oidc.go
model_identity_with_credentials_oidc_config.go
Expand Down
2 changes: 0 additions & 2 deletions internal/client-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,9 @@ Class | Method | HTTP request | Description
- [IdentityCredentialsOidc](docs/IdentityCredentialsOidc.md)
- [IdentityCredentialsOidcProvider](docs/IdentityCredentialsOidcProvider.md)
- [IdentityCredentialsPassword](docs/IdentityCredentialsPassword.md)
- [IdentityCredentialsType](docs/IdentityCredentialsType.md)
- [IdentityPatch](docs/IdentityPatch.md)
- [IdentityPatchResponse](docs/IdentityPatchResponse.md)
- [IdentitySchemaContainer](docs/IdentitySchemaContainer.md)
- [IdentityState](docs/IdentityState.md)
- [IdentityWithCredentials](docs/IdentityWithCredentials.md)
- [IdentityWithCredentialsOidc](docs/IdentityWithCredentialsOidc.md)
- [IdentityWithCredentialsOidcConfig](docs/IdentityWithCredentialsOidcConfig.md)
Expand Down
4 changes: 2 additions & 2 deletions internal/client-go/api_identity.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions internal/client-go/model_create_identity_body.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions internal/client-go/model_identity.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions internal/client-go/model_identity_credentials.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 0 additions & 88 deletions internal/client-go/model_identity_credentials_type.go

This file was deleted.

Loading

0 comments on commit 4b881ca

Please sign in to comment.