domain.go
domain.go - Overview
-
Overview This file defines the structure and methods for handling organization domains, including Single Sign-On (SSO) configurations like SAML and Google Auth. It includes data structures for storing domain information, SSO settings, and functions for validating, loading configurations, and preparing SSO requests.
-
Detailed Documentation
type StorableOrgDomain
- Purpose: Represents the structure of an organization domain that is stored in the database.
- Fields:
bun.BaseModel
: Base model for bun ORM.types.TimeAuditable
: Embeds fields for tracking creation and modification timestamps.ID
: Unique identifier of the domain.OrgID
: Identifier of the organization that owns the domain.Name
: Name of the domain.Data
: JSON string containing configuration data for the domain.
type SSOType
- Purpose: Represents the type of SSO configuration.
- Type:
string
const (SAML SSOType = "SAML"; GoogleAuth SSOType = "GOOGLE_AUTH")
- Purpose: Defines the possible values for
SSOType
. - Constants:
SAML
: Represents SAML-based SSO.GoogleAuth
: Represents Google OAuth-based SSO.
type GettableOrgDomain
- Purpose: Represents an organization domain with its SSO configuration details. This struct is used when retrieving domain information.
- Fields:
StorableOrgDomain
: Embedded struct containing storable domain information.SsoEnabled
: Indicates whether SSO is enabled for the domain.SsoType
: Type of SSO configured for the domain (e.g., SAML, GoogleAuth).SamlConfig
: Configuration for SAML SSO.GoogleAuthConfig
: Configuration for Google OAuth SSO.Org
: The organization this domain belongs to.
func (od *GettableOrgDomain) String() string
- Purpose: Returns a string representation of the
GettableOrgDomain
. - Parameters:
od
(*GettableOrgDomain): The domain object.
- Returns:
string
: Formatted string containing the domain name, ID, and SSO type.
func (od *GettableOrgDomain) Valid(err error) error
- Purpose: Validates the
GettableOrgDomain
loaded from the database. - Parameters:
od
(*GettableOrgDomain): The domain object.err
(error): An existing error, if any.
- Returns:
error
: An error if the domain is invalid (e.g., missing ID or OrgID), otherwise returns the input error.
func (od *GettableOrgDomain) ValidNew() error
- Purpose: Validates a new
GettableOrgDomain
before insertion into the database. - Parameters:
od
(*GettableOrgDomain): The domain object.
- Returns:
error
: An error if the domain is invalid (e.g., missing OrgID or Name).
func (od *GettableOrgDomain) LoadConfig(jsondata string) error
- Purpose: Loads configuration parameters from a JSON string into the
GettableOrgDomain
. - Parameters:
od
(*GettableOrgDomain): The domain object.jsondata
(string): JSON string containing configuration data.
- Returns:
error
: An error if unmarshaling fails.
func (od *GettableOrgDomain) GetSAMLEntityID() string
- Purpose: Retrieves the SAML entity ID from the domain's SAML configuration.
- Parameters:
od
(*GettableOrgDomain): The domain object.
- Returns:
string
: The SAML entity ID, or an empty string if SAML is not configured.
func (od *GettableOrgDomain) GetSAMLIdpURL() string
- Purpose: Retrieves the SAML IdP URL from the domain's SAML configuration.
- Parameters:
od
(*GettableOrgDomain): The domain object.
- Returns:
string
: The SAML IdP URL, or an empty string if SAML is not configured.
func (od *GettableOrgDomain) GetSAMLCert() string
- Purpose: Retrieves the SAML certificate from the domain's SAML configuration.
- Parameters:
od
(*GettableOrgDomain): The domain object.
- Returns:
string
: The SAML certificate, or an empty string if SAML is not configured.
func (od *GettableOrgDomain) PrepareGoogleOAuthProvider(siteUrl *url.URL) (sso.OAuthCallbackProvider, error)
- Purpose: Creates a Google OAuth provider based on the domain's configuration.
- Parameters:
od
(*GettableOrgDomain): The domain object.siteUrl
(*url.URL): The site URL.
- Returns:
sso.OAuthCallbackProvider
: The Google OAuth provider.error
: An error if the Google OAuth configuration is invalid.
func (od *GettableOrgDomain) PrepareSamlRequest(siteUrl *url.URL) (*saml2.SAMLServiceProvider, error)
- Purpose: Prepares a SAML request based on the domain's configuration.
- Parameters:
od
(*GettableOrgDomain): The domain object.siteUrl
(*url.URL): The site URL.
- Returns:
*saml2.SAMLServiceProvider
: The SAML service provider.error
: An error if the SAML configuration is invalid.
func (od *GettableOrgDomain) BuildSsoUrl(siteUrl *url.URL) (ssoUrl string, err error)
- Purpose: Builds the SSO URL based on the domain's SSO type (SAML or Google Auth).
- Parameters:
od
(*GettableOrgDomain): The domain object.siteUrl
(*url.URL): The site URL.
- Returns:
ssoUrl
(string): The SSO URL.err
(error): An error if the SSO type is unsupported or if there are configuration issues.
-
Code Examples N/A
-
Clarity and Accuracy The documentation accurately reflects the code's functionality based on its structure and comments.
Include in Getting Started: NO