Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
// Copyright © 2025 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package flow
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"database/sql/driver"
|
|
"net/url"
|
|
|
|
"github.com/ory/kratos/driver/config"
|
|
)
|
|
|
|
// swagger:type string
|
|
type IdentitySchema string
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (is *IdentitySchema) Scan(value any) error {
|
|
var v sql.NullString
|
|
if err := (&v).Scan(value); err != nil {
|
|
return err
|
|
}
|
|
*is = IdentitySchema(v.String)
|
|
return nil
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (is *IdentitySchema) Value() (driver.Value, error) {
|
|
if is == nil || len(*is) == 0 {
|
|
return sql.NullString{}.Value()
|
|
}
|
|
return sql.NullString{Valid: true, String: string(*is)}.Value()
|
|
}
|
|
|
|
// URL returns the URL of the identity schema, or the default identity traits
|
|
// schema URL if the schema is empty.
|
|
func (is *IdentitySchema) URL(ctx context.Context, config *config.Config) (*url.URL, error) {
|
|
if is == nil || len(*is) == 0 {
|
|
return config.DefaultIdentityTraitsSchemaURL(ctx)
|
|
}
|
|
schemas, err := config.IdentityTraitsSchemas(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
schema, err := schemas.FindSchemaByID(string(*is))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return config.ParseURI(schema.URL)
|
|
}
|
|
|
|
// ID returns the ID of the identity schema, or the default identity schema ID.
|
|
func (is *IdentitySchema) ID(ctx context.Context, config *config.Config) string {
|
|
if is == nil || len(*is) == 0 {
|
|
return config.DefaultIdentityTraitsSchemaID(ctx)
|
|
}
|
|
return string(*is)
|
|
}
|