service

package
v0.0.0-...-cab84a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 90 Imported by: 0

Documentation

Index

Constants

View Source
const AUTHGEARONCE = false
View Source
const DefaultPrivacyPolicyLink string = "https://www.authgear.com/data-privacy"
View Source
const DefaultTermsOfServiceLink string = "https://www.authgear.com/terms"
View Source
const DomainVerificationTimeout = 10 * time.Second
View Source
const SecretVisitTokenValidDuration = duration.Short
View Source
const SecretVisitTokenVisibleSecrets string = "visible_secrets"

Variables

View Source
var DomainVerificationFailed = apierrors.Forbidden.WithReason("DomainVerificationFailed")
View Source
var ErrAppIDInvalid = apierrors.Invalid.WithReason("InvalidAppID").
	New("invalid app ID")
View Source
var ErrAppIDReserved = apierrors.Forbidden.WithReason("AppIDReserved").
	New("requested app ID is reserved")
View Source
var ErrCollaboratorDuplicate = apierrors.AlreadyExists.WithReason("CollaboratorDuplicate").New("collaborator duplicate")
View Source
var ErrCollaboratorInvitationDuplicate = apierrors.AlreadyExists.WithReason("CollaboratorInvitationDuplicate").New("collaborator invitation duplicate")
View Source
var ErrCollaboratorInvitationInvalidCode = apierrors.Invalid.WithReason("CollaboratorInvitationInvalidCode").New("collaborator invitation invalid code")
View Source
var ErrCollaboratorInvitationInvalidEmail = apierrors.Invalid.WithReason("CollaboratorInvitationInvalidEmail").New("the email with the actor does match the invitee email")
View Source
var ErrCollaboratorInvitationNotFound = apierrors.NotFound.WithReason("CollaboratorInvitationNotFound").New("collaborator invitation not found")
View Source
var ErrCollaboratorNotFound = apierrors.NotFound.WithReason("CollaboratorNotFound").New("collaborator not found")
View Source
var ErrCollaboratorQuotaExceeded = apierrors.Invalid.WithReason("CollaboratorQuotaExceeded").New("collaborator quota exceeded")
View Source
var ErrCollaboratorSelfDeletion = apierrors.Forbidden.WithReason("CollaboratorSelfDeletion").New("cannot remove self from collaborator")
View Source
var ErrDomainDuplicated = apierrors.AlreadyExists.WithReason("DuplicatedDomain").
	New("requested domain is already in use")
View Source
var ErrDomainNotCustom = apierrors.Forbidden.WithReason("DomainNotCustom").
	New("requested domain is not a custom domain")
View Source
var ErrDomainNotFound = apierrors.NotFound.WithReason("DomainNotFound").
	New("domain not found")
View Source
var ErrDomainVerified = apierrors.AlreadyExists.WithReason("DomainVerified").
	New("requested domain is already verified")
View Source
var ErrDuplicatedAppID = apierrors.AlreadyExists.WithReason("DuplicatedAppID").
	New("duplicated app ID")
View Source
var ErrForbidden = apierrors.Forbidden.WithReason("Forbidden").New("forbidden")
View Source
var ErrGetStaticAppIDsNotSupported = errors.New("only local FS config source can get static app ID")
View Source
var ErrHostSuffixNotConfigured = errors.New("host suffix not configured")
View Source
var ErrReauthRequrired = apierrors.Forbidden.WithReason("ReauthRequrired").
	New("reauthentication required")
View Source
var ErrSubscriptionCheckoutNotFound = apierrors.NotFound.WithReason("ErrSubscriptionCheckoutNotFound").
	New("subscription checkout not found")
View Source
var ErrSubscriptionNotFound = apierrors.NotFound.WithReason("ErrSubscriptionNotFound").New("subscription not found")
View Source
var ErrUnauthenticated = apierrors.Unauthorized.WithReason("Unauthenticated").New("unauthenticated")
View Source
var InvalidDomain = apierrors.Invalid.WithReason("InvalidDomain")
View Source
var LabelAppID = "authgear.com/app-id"
View Source
var LabelDomainID = "authgear.com/domain-id"

Functions

func MakeVerificationNonce

func MakeVerificationNonce() string

Types

type AdminAPIDefaultDomainService

type AdminAPIDefaultDomainService interface {
	GetLatestAppHost(appID string) (string, error)
}

type AdminAPIService

type AdminAPIService struct {
	AuthgearConfig *portalconfig.AuthgearConfig
	AdminAPIConfig *portalconfig.AdminAPIConfig
	ConfigSource   *configsource.ConfigSource
	AuthzAdder     AuthzAdder
	DefaultDomains AdminAPIDefaultDomainService
}

func (*AdminAPIService) Director

func (s *AdminAPIService) Director(ctx context.Context, appID string, p string, actorUserID string, usage Usage) (director func(*http.Request), err error)

func (*AdminAPIService) ResolveConfig

func (s *AdminAPIService) ResolveConfig(ctx context.Context, appID string) (cfg *config.Config, err error)

func (*AdminAPIService) ResolveEndpoint

func (s *AdminAPIService) ResolveEndpoint(appID string) (*url.URL, error)

func (*AdminAPIService) SelfDirector

func (s *AdminAPIService) SelfDirector(ctx context.Context, actorUserID string, usage Usage) (director func(*http.Request), err error)

type AppAuthzService

type AppAuthzService interface {
	AddAuthorizedUser(ctx context.Context, appID string, userID string, role model.CollaboratorRole) error
	ListAuthorizedApps(ctx context.Context, userID string) ([]string, error)
}

type AppConfigService

type AppConfigService interface {
	ResolveContext(ctx context.Context, appID string, fn func(context.Context, *config.AppContext) error) error
	UpdateResources(ctx context.Context, appID string, updates []*resource.ResourceFile) error
	Create(ctx context.Context, opts *CreateAppOptions) error
}

type AppConfigSourceStore

type AppConfigSourceStore interface {
	ListAll(ctx context.Context) ([]*configsource.DatabaseSource, error)
}

type AppDefaultDomainService

type AppDefaultDomainService interface {
	GetLatestAppHost(appID string) (string, error)
	CreateAllDefaultDomains(ctx context.Context, appID string) error
}

type AppPlanService

type AppPlanService interface {
	GetDefaultPlan(ctx context.Context) (*plan.Plan, error)
}

type AppResourceManagerFactory

type AppResourceManagerFactory interface {
	NewManagerWithNewAppFS(appFs resource.Fs) *appresource.Manager
	NewManagerWithAppContext(appContext *config.AppContext) *appresource.Manager
}

type AppSecretVisitTokenStore

type AppSecretVisitTokenStore interface {
	CreateToken(
		ctx context.Context,
		appID config.AppID,
		userID string,
		secrets []config.SecretKey,
	) (*appsecret.AppSecretVisitToken, error)
	GetTokenByID(
		ctx context.Context,
		appID config.AppID,
		tokenID string,
	) (*appsecret.AppSecretVisitToken, error)
}

type AppService

type AppService struct {
	Logger      AppServiceLogger
	SQLBuilder  *globaldb.SQLBuilder
	SQLExecutor *globaldb.SQLExecutor

	GlobalDatabase *globaldb.Handle

	AppConfig                *portalconfig.AppConfig
	AppConfigs               AppConfigService
	AppAuthz                 AppAuthzService
	DefaultDomains           AppDefaultDomainService
	Resources                ResourceManager
	AppResMgrFactory         AppResourceManagerFactory
	Plan                     AppPlanService
	Clock                    clock.Clock
	AppSecretVisitTokenStore AppSecretVisitTokenStore
	AppTesterTokenStore      AppTesterTokenStore
	SAMLEnvironmentConfig    config.SAMLEnvironmentConfig
	ConfigSourceStore        AppConfigSourceStore
}

func (*AppService) Create

func (s *AppService) Create(ctx context.Context, userID string, id string) (*model.App, error)

Create calls other services that acquires connection themselves, and acquires connection.

func (*AppService) GenerateSecretVisitToken

func (s *AppService) GenerateSecretVisitToken(
	ctx context.Context,
	app *model.App,
	sessionInfo *apimodel.SessionInfo,
	visitingSecrets []config.SecretKey,
) (*appsecret.AppSecretVisitToken, error)

GenerateSecretVisitToken does not need connection.

func (*AppService) GenerateTesterToken

func (s *AppService) GenerateTesterToken(
	ctx context.Context,
	app *model.App,
	returnURI string,
) (*tester.TesterToken, error)

GenerateTesterToken does not need connection.

func (*AppService) Get

func (s *AppService) Get(ctx context.Context, id string) (*model.App, error)

Get calls other services that acquires connection themselves.

func (*AppService) GetAppList

func (s *AppService) GetAppList(ctx context.Context, userID string) ([]*model.AppListItem, error)

GetAppList calls other services that acquires connection themselves.

func (*AppService) GetMany

func (s *AppService) GetMany(ctx context.Context, ids []string) (out []*model.App, err error)

GetMany just uses Get.

func (*AppService) GetManyProjectQuota

func (s *AppService) GetManyProjectQuota(ctx context.Context, userIDs []string) ([]int, error)

GetManyProjectQuota acquires connection.

func (*AppService) GetProjectQuota

func (s *AppService) GetProjectQuota(ctx context.Context, userID string) (int, error)

GetProjectQuota acquires connection.

func (*AppService) LoadAppSecretConfig

func (s *AppService) LoadAppSecretConfig(
	ctx context.Context,
	app *model.App,
	sessionInfo *apimodel.SessionInfo,
	token string) (*model.SecretConfig, string, error)

LoadAppSecretConfig does not need connection.

func (*AppService) LoadAppWebhookSecretMaterials

func (s *AppService) LoadAppWebhookSecretMaterials(
	ctx context.Context,
	app *model.App) (*config.WebhookKeyMaterials, error)

func (*AppService) LoadRawAppConfig

func (s *AppService) LoadRawAppConfig(ctx context.Context, app *model.App) (*config.AppConfig, string, error)

LoadRawAppConfig does not need connection.

func (*AppService) RenderSAMLEntityID

func (s *AppService) RenderSAMLEntityID(appID string) string

func (*AppService) UpdateResources

func (s *AppService) UpdateResources(ctx context.Context, app *model.App, updates []appresource.Update) error

UpdateResources acquires connection.

func (*AppService) UpdateResources0

func (s *AppService) UpdateResources0(ctx context.Context, app *model.App, updates []appresource.Update) error

UpdateResources0 assumes acquired connection.

type AppServiceLogger

type AppServiceLogger struct{ *log.Logger }

func NewAppServiceLogger

func NewAppServiceLogger(lf *log.Factory) AppServiceLogger

type AppTesterTokenStore

type AppTesterTokenStore interface {
	CreateToken(
		ctx context.Context,
		appID config.AppID,
		returnURI string,
	) (*tester.TesterToken, error)
}

type AuditService

type AuditService struct {
	RemoteIP        httputil.RemoteIP
	UserAgentString httputil.UserAgentString
	Request         *http.Request

	Apps     AuditServiceAppService
	Authgear *portalconfig.AuthgearConfig

	DenoEndpoint config.DenoEndpoint

	GlobalSQLBuilder  *globaldb.SQLBuilder
	GlobalSQLExecutor *globaldb.SQLExecutor
	GlobalDatabase    *globaldb.Handle

	AuditDatabase *auditdb.WriteHandle

	Clock         clock.Clock
	LoggerFactory *log.Factory
}

func (*AuditService) Log

func (s *AuditService) Log(ctx context.Context, app *model.App, payload event.NonBlockingPayload) (err error)

type AuditServiceAppService

type AuditServiceAppService interface {
	Get(ctx context.Context, id string) (*model.App, error)
}

type AuthzAdder

type AuthzAdder interface {
	AddAuthz(
		auth config.AdminAPIAuth,
		appID config.AppID,
		authKey *config.AdminAPIAuthKey,
		auditContext interface{},
		hdr http.Header) (err error)
}

type AuthzCollaboratorService

type AuthzCollaboratorService interface {
	NewCollaborator(appID string, userID string, role model.CollaboratorRole) *model.Collaborator

	CreateCollaborator(ctx context.Context, c *model.Collaborator) error
	ListCollaboratorsByUser(ctx context.Context, userID string) ([]*model.Collaborator, error)
	GetCollaboratorByAppAndUser(ctx context.Context, appID string, userID string) (*model.Collaborator, error)
}

type AuthzConfigService

type AuthzConfigService interface {
	GetStaticAppIDs() ([]string, error)
}

type AuthzService

type AuthzService struct {
	Configs       AuthzConfigService
	Collaborators AuthzCollaboratorService
}

func (*AuthzService) AddAuthorizedUser

func (s *AuthzService) AddAuthorizedUser(ctx context.Context, appID string, userID string, role model.CollaboratorRole) error

AddAuthorizedUser assume acquired connection.

func (*AuthzService) CheckAccessOfViewer

func (s *AuthzService) CheckAccessOfViewer(ctx context.Context, appID string) (userID string, err error)

CheckAccessOfViewer calls other services that acquires connection themselves.

func (*AuthzService) ListAuthorizedApps

func (s *AuthzService) ListAuthorizedApps(ctx context.Context, userID string) ([]string, error)

ListAuthorizedApps calls other services that acquires connection themselves.

type CollaboratorAppConfigService

type CollaboratorAppConfigService interface {
	ResolveContext(ctx context.Context, appID string, fn func(context.Context, *config.AppContext) error) error
}

type CollaboratorService

type CollaboratorService struct {
	Clock       clock.Clock
	SQLBuilder  *globaldb.SQLBuilder
	SQLExecutor *globaldb.SQLExecutor
	HTTPClient  HTTPClient

	GlobalDatabase *globaldb.Handle

	MailConfig     *portalconfig.MailConfig
	SMTPService    CollaboratorServiceSMTPService
	Endpoints      CollaboratorServiceEndpointsProvider
	TemplateEngine *template.Engine
	AdminAPI       CollaboratorServiceAdminAPIService

	AppConfigs CollaboratorAppConfigService
}

func (*CollaboratorService) AcceptInvitation

func (s *CollaboratorService) AcceptInvitation(ctx context.Context, code string) (*model.Collaborator, error)

AcceptInvitation acquires connection.

func (*CollaboratorService) CheckInviteeEmail

func (s *CollaboratorService) CheckInviteeEmail(ctx context.Context, i *model.CollaboratorInvitation, actorID string) error

CheckInviteeEmail calls HTTP request.

func (*CollaboratorService) CreateCollaborator

func (s *CollaboratorService) CreateCollaborator(ctx context.Context, c *model.Collaborator) error

CreateCollaborator assume acquired connection.

func (*CollaboratorService) DeleteCollaborator

func (s *CollaboratorService) DeleteCollaborator(ctx context.Context, c *model.Collaborator) error

DeleteCollaborator acquires connection.

func (*CollaboratorService) DeleteInvitation

DeleteInvitation acquires connection.

func (*CollaboratorService) GetCollaborator

func (s *CollaboratorService) GetCollaborator(ctx context.Context, id string) (*model.Collaborator, error)

GetCollaborator acquires connection.

func (*CollaboratorService) GetCollaboratorByAppAndUser

func (s *CollaboratorService) GetCollaboratorByAppAndUser(ctx context.Context, appID string, userID string) (*model.Collaborator, error)

GetCollaboratorByAppAndUser acquires connection.

func (*CollaboratorService) GetInvitation

GetInvitation acquires connection.

func (*CollaboratorService) GetInvitationWithCode

func (s *CollaboratorService) GetInvitationWithCode(ctx context.Context, code string) (*model.CollaboratorInvitation, error)

GetInvitationWithCode acquires connection.

func (*CollaboratorService) GetManyCollaborators

func (s *CollaboratorService) GetManyCollaborators(ctx context.Context, ids []string) ([]*model.Collaborator, error)

GetManyCollaborators acquires connection.

func (*CollaboratorService) GetManyInvitations

func (s *CollaboratorService) GetManyInvitations(ctx context.Context, ids []string) ([]*model.CollaboratorInvitation, error)

GetManyInvitations acquires connection.

func (*CollaboratorService) GetManyProjectOwnerCount

func (s *CollaboratorService) GetManyProjectOwnerCount(ctx context.Context, userIDs []string) ([]int, error)

GetManyProjectOwnerCount acquires connection.

func (*CollaboratorService) GetProjectOwnerCount

func (s *CollaboratorService) GetProjectOwnerCount(ctx context.Context, userID string) (int, error)

GetProjectOwnerCount acquires connection.

func (*CollaboratorService) ListCollaborators

func (s *CollaboratorService) ListCollaborators(ctx context.Context, appID string) ([]*model.Collaborator, error)

ListCollaborators acquires connection.

func (*CollaboratorService) ListCollaboratorsByUser

func (s *CollaboratorService) ListCollaboratorsByUser(ctx context.Context, userID string) ([]*model.Collaborator, error)

ListCollaboratorsByUser acquires connection.

func (*CollaboratorService) ListInvitations

func (s *CollaboratorService) ListInvitations(ctx context.Context, appID string) ([]*model.CollaboratorInvitation, error)

ListInvitations acquires connection.

func (*CollaboratorService) NewCollaborator

func (s *CollaboratorService) NewCollaborator(appID string, userID string, role model.CollaboratorRole) *model.Collaborator

NewCollaborator does not need connection.

func (*CollaboratorService) SendInvitation

func (s *CollaboratorService) SendInvitation(
	ctx context.Context,
	appID string,
	inviteeEmail string,
) (*model.CollaboratorInvitation, error)

SendInvitation acquires connection.

type CollaboratorServiceAdminAPIService

type CollaboratorServiceAdminAPIService interface {
	SelfDirector(ctx context.Context, actorUserID string, usage Usage) (func(*http.Request), error)
}

type CollaboratorServiceEndpointsProvider

type CollaboratorServiceEndpointsProvider interface {
	AcceptCollaboratorInvitationEndpointURL() *url.URL
}

type CollaboratorServiceSMTPService

type CollaboratorServiceSMTPService interface {
	SendRealEmail(ctx context.Context, opts mail.SendOptions) error
}

type ConfigService

type ConfigService struct {
	Logger               ConfigServiceLogger
	AppConfig            *portalconfig.AppConfig
	Controller           *configsource.Controller
	ConfigSource         *configsource.ConfigSource
	DomainImplementation portalconfig.DomainImplementationType
	Kubernetes           *Kubernetes
}

func (*ConfigService) Create

func (s *ConfigService) Create(ctx context.Context, opts *CreateAppOptions) error

Create assumes acquired connection.

func (*ConfigService) CreateDomain

func (s *ConfigService) CreateDomain(ctx context.Context, appID string, domainID string, domain string, isCustom bool) error

CreateDomain does not need connection.

func (*ConfigService) DeleteDomain

func (s *ConfigService) DeleteDomain(ctx context.Context, domain *apimodel.Domain) error

DeleteDomain does not need connection.

func (*ConfigService) GetStaticAppIDs

func (s *ConfigService) GetStaticAppIDs() ([]string, error)

GetStaticAppIDs does not need connection.

func (*ConfigService) ResolveContext

func (s *ConfigService) ResolveContext(ctx context.Context, appID string, fn func(context.Context, *config.AppContext) error) error

ResolveContext calls other services that acquires connection themselves.

func (*ConfigService) UpdateResources

func (s *ConfigService) UpdateResources(ctx context.Context, appID string, files []*resource.ResourceFile) error

UpdateResources assumes acquired connection.

type ConfigServiceLogger

type ConfigServiceLogger struct{ *log.Logger }

func NewConfigServiceLogger

func NewConfigServiceLogger(lf *log.Factory) ConfigServiceLogger

type CreateAppOptions

type CreateAppOptions struct {
	AppID     string
	Resources map[string][]byte
	PlanName  string
}

type DefaultDomainDomainService

type DefaultDomainDomainService interface {
	CreateDomain(ctx context.Context, appID string, domain string, isVerified bool, isCustom bool) (*apimodel.Domain, error)
}

type DefaultDomainService

type DefaultDomainService struct {
	AppHostSuffixes config.AppHostSuffixes
	AppConfig       *portalconfig.AppConfig
	Domains         DefaultDomainDomainService
}

func (*DefaultDomainService) CreateAllDefaultDomains

func (s *DefaultDomainService) CreateAllDefaultDomains(ctx context.Context, appID string) error

CreateAllDefaultDomains assume acquired connection.

func (*DefaultDomainService) GetLatestAppHost

func (s *DefaultDomainService) GetLatestAppHost(appID string) (string, error)

GetLatestAppHost does not need connection.

type DomainConfigService

type DomainConfigService interface {
	CreateDomain(ctx context.Context, appID string, domainID string, domain string, isCustom bool) error
	DeleteDomain(ctx context.Context, domain *apimodel.Domain) error
}

type DomainService

type DomainService struct {
	Clock          clock.Clock
	DomainConfig   DomainConfigService
	SQLBuilder     *globaldb.SQLBuilder
	SQLExecutor    *globaldb.SQLExecutor
	GlobalDatabase *globaldb.Handle
}

func (*DomainService) CreateCustomDomain

func (s *DomainService) CreateCustomDomain(ctx context.Context, appID string, domain string) (*apimodel.Domain, error)

CreateCustomDomain acquires connection.

func (*DomainService) CreateDomain

func (s *DomainService) CreateDomain(ctx context.Context, appID string, domain string, isVerified bool, isCustom bool) (*apimodel.Domain, error)

CreateDomain assumes acquired connection.

func (*DomainService) DeleteDomain

func (s *DomainService) DeleteDomain(ctx context.Context, appID string, id string) error

DeleteDomain assumes acquired connection.

func (*DomainService) GetMany

func (s *DomainService) GetMany(ctx context.Context, ids []string) ([]*apimodel.Domain, error)

GetMany acquires connection.

func (*DomainService) ListDomains

func (s *DomainService) ListDomains(ctx context.Context, appID string) ([]*apimodel.Domain, error)

ListDomains acquires connection.

func (*DomainService) VerifyDomain

func (s *DomainService) VerifyDomain(ctx context.Context, appID string, id string) (*apimodel.Domain, error)

VerifyDomain acquires connection.

type HTTPClient

type HTTPClient struct {
	*http.Client
}

func NewHTTPClient

func NewHTTPClient() HTTPClient

type IngressTemplateData

type IngressTemplateData struct {
	AppID         string
	DomainID      string
	IsCustom      bool
	Host          string
	TLSSecretName string
}

type Kubernetes

type Kubernetes struct {
	KubernetesConfig *portalconfig.KubernetesConfig
	AppConfig        *portalconfig.AppConfig
	Logger           KubernetesLogger

	Namespace           string                         `wire:"-"`
	KubeConfig          *rest.Config                   `wire:"-"`
	Client              kubernetes.Interface           `wire:"-"`
	CertManagerClient   certmanagerclientset.Interface `wire:"-"`
	DynamicClient       dynamic.Interface              `wire:"-"`
	DiscoveryRESTMapper meta.RESTMapper                `wire:"-"`
}

func (*Kubernetes) CreateResourcesForDomain

func (k *Kubernetes) CreateResourcesForDomain(
	ctx context.Context,
	appID string,
	domainID string,
	domain string,
	isCustom bool,
) error

func (*Kubernetes) DeleteResourcesForDomain

func (k *Kubernetes) DeleteResourcesForDomain(ctx context.Context, domainID string) error

type KubernetesLogger

type KubernetesLogger struct{ *log.Logger }

func NewKubernetesLogger

func NewKubernetesLogger(lf *log.Factory) KubernetesLogger

type KubernetesResource

type KubernetesResource struct {
	Object *unstructured.Unstructured
	GVK    *schema.GroupVersionKind
}

func GenerateResources

func GenerateResources(def *ResourceTemplateData, templateBytes []byte) ([]*KubernetesResource, error)

type NoopAttributesService

type NoopAttributesService struct{}

func (*NoopAttributesService) UpdateAllCustomAttributes

func (*NoopAttributesService) UpdateAllCustomAttributes(ctx context.Context, role accesscontrol.Role, userID string, stdAttrs map[string]interface{}) error

func (*NoopAttributesService) UpdateStandardAttributes

func (*NoopAttributesService) UpdateStandardAttributes(ctx context.Context, role accesscontrol.Role, userID string, stdAttrs map[string]interface{}) error

type NoopRolesAndGroupsService

type NoopRolesAndGroupsService struct{}

func (*NoopRolesAndGroupsService) ResetUserGroup

func (*NoopRolesAndGroupsService) ResetUserRole

type OnboardService

type OnboardService struct {
	HTTPClient     HTTPClient
	AuthgearConfig *portalconfig.AuthgearConfig
	AdminAPI       OnboardServiceAdminAPIService
}

func (*OnboardService) CheckOnboardingSurveyCompletion

func (s *OnboardService) CheckOnboardingSurveyCompletion(ctx context.Context, actorID string) (bool, error)

func (*OnboardService) SubmitOnboardEntry

func (s *OnboardService) SubmitOnboardEntry(ctx context.Context, entry model.OnboardEntry, actorID string) error

type OnboardServiceAdminAPIService

type OnboardServiceAdminAPIService interface {
	SelfDirector(ctx context.Context, actorUserID string, usage Usage) (func(*http.Request), error)
}

type PortalAdminAPIAuthContext

type PortalAdminAPIAuthContext struct {
	Usage       Usage  `json:"usage"`
	ActorUserID string `json:"actor_user_id,omitempty"`
	HTTPReferer string `json:"http_referer,omitempty"`
}

type ResourceManager

type ResourceManager interface {
	Read(ctx context.Context, desc resource.Descriptor, view resource.View) (interface{}, error)
}

type ResourceTemplateData

type ResourceTemplateData struct {
	AppID    string
	DomainID string
	IsCustom bool
	Host     string
}

type SubscriptionConfigSourceStore

type SubscriptionConfigSourceStore interface {
	GetDatabaseSourceByAppID(ctx context.Context, appID string) (*configsource.DatabaseSource, error)
	UpdateDatabaseSource(ctx context.Context, dbs *configsource.DatabaseSource) error
}

type SubscriptionPlanStore

type SubscriptionPlanStore interface {
	GetPlan(ctx context.Context, name string) (*plan.Plan, error)
}

type SubscriptionService

type SubscriptionService struct {
	SQLBuilder        *globaldb.SQLBuilder
	SQLExecutor       *globaldb.SQLExecutor
	GlobalDatabase    *globaldb.Handle
	ConfigSourceStore SubscriptionConfigSourceStore
	PlanStore         SubscriptionPlanStore
	UsageStore        SubscriptionUsageStore
	Clock             clock.Clock
	AppConfig         *portalconfig.AppConfig
}

func (*SubscriptionService) ArchiveSubscription0

func (s *SubscriptionService) ArchiveSubscription0(ctx context.Context, sub *model.Subscription) error

ArchiveSubscription0 assumes acquired connection.

func (*SubscriptionService) CreateSubscriptionCheckout

func (s *SubscriptionService) CreateSubscriptionCheckout(ctx context.Context, checkoutSession *libstripe.CheckoutSession) (*model.SubscriptionCheckout, error)

CreateSubscriptionCheckout acquires connection.

func (*SubscriptionService) GetLastProcessingCustomerID

func (s *SubscriptionService) GetLastProcessingCustomerID(ctx context.Context, appID string) (*string, error)

GetLastProcessingCustomerID acquires connection.

func (*SubscriptionService) GetSubscription

func (s *SubscriptionService) GetSubscription(ctx context.Context, appID string) (*model.Subscription, error)

GetSubscription acquires connection.

func (*SubscriptionService) GetSubscription0

func (s *SubscriptionService) GetSubscription0(ctx context.Context, appID string) (*model.Subscription, error)

GetSubscription0 assumes acquired connection.

func (*SubscriptionService) GetSubscriptionUsage

func (s *SubscriptionService) GetSubscriptionUsage(
	ctx context.Context,
	appID string,
	planName string,
	date time.Time,
	subscriptionPlans []*model.SubscriptionPlan,
) (*model.SubscriptionUsage, error)

GetSubscriptionUsage acquires connection. GetSubscriptionUsage uses the current plan to estimate the usage and the cost. However, if we ever adjust the prices, the estimation will become inaccurate. A accurate estimation should use the Prices in the Stripe Subscription to perform calculation.

func (*SubscriptionService) MarkCheckoutCancelled0

func (s *SubscriptionService) MarkCheckoutCancelled0(ctx context.Context, appID string, customerID string) error

MarkCheckoutCancelled0 assumes acquired connection.

func (*SubscriptionService) MarkCheckoutCompleted

func (s *SubscriptionService) MarkCheckoutCompleted(ctx context.Context, appID string, stripCheckoutSessionID string, customerID string) error

MarkCheckoutCompleted acquires connection. MarkCheckoutCompleted marks subscription checkout as completed. It returns ErrSubscriptionCheckoutNotFound when the checkout is not found or the checkout status is already subscribed.

func (*SubscriptionService) MarkCheckoutExpired

func (s *SubscriptionService) MarkCheckoutExpired(ctx context.Context, appID string, customerID string) error

MarkCheckoutExpired acquires connection.

func (*SubscriptionService) MarkCheckoutSubscribed0

func (s *SubscriptionService) MarkCheckoutSubscribed0(ctx context.Context, appID string, customerID string) error

MarkCheckoutSubscribed0 assumes acquired connection. MarkCheckoutSubscribed0 marks subscription checkout as subscribed. It returns ErrSubscriptionCheckoutNotFound when the checkout is not found or the checkout status is already subscribed.

func (*SubscriptionService) SetSubscriptionCancelledStatus

func (s *SubscriptionService) SetSubscriptionCancelledStatus(ctx context.Context, id string, cancelled bool, endedAt *time.Time) error

SetSubscriptionCancelledStatus acquires connection.

func (*SubscriptionService) UpdateAppPlan

func (s *SubscriptionService) UpdateAppPlan(ctx context.Context, appID string, planName string) error

UpdateAppPlan acquires connection.

func (*SubscriptionService) UpdateAppPlan0

func (s *SubscriptionService) UpdateAppPlan0(ctx context.Context, appID string, planName string) error

UpdateAppPlan0 assumes acquired connection.

func (*SubscriptionService) UpdateAppPlanToDefault0

func (s *SubscriptionService) UpdateAppPlanToDefault0(ctx context.Context, appID string) error

UpdateAppPlanToDefault0 assumes acquired connection.

func (*SubscriptionService) UpsertSubscription0

func (s *SubscriptionService) UpsertSubscription0(ctx context.Context, appID string, stripeSubscriptionID string, stripeCustomerID string) (*model.Subscription, error)

UpsertSubscription0 assumes acquired connection.

type SubscriptionUsageStore

type SubscriptionUsageStore interface {
	FetchUploadedUsageRecords(
		ctx context.Context,
		appID string,
		recordName usage.RecordName,
		period periodical.Type,
		stripeStart time.Time,
		stripeEnd time.Time,
	) ([]*usage.UsageRecord, error)
	FetchUsageRecords(
		ctx context.Context,
		appID string,
		recordName usage.RecordName,
		period periodical.Type,
		startTime time.Time,
	) ([]*usage.UsageRecord, error)
}

type SystemConfigProvider

type SystemConfigProvider struct {
	AuthgearConfig                 *config.AuthgearConfig
	AppConfig                      *config.AppConfig
	SearchConfig                   *config.SearchConfig
	AuditLogConfig                 *config.AuditLogConfig
	AnalyticConfig                 *configlib.AnalyticConfig
	GTMConfig                      *config.GoogleTagManagerConfig
	FrontendSentryConfig           *config.PortalFrontendSentryConfig
	PortalFeaturesConfig           *config.PortalFeaturesConfig
	GlobalUIImplementation         configlib.GlobalUIImplementation
	GlobalUISettingsImplementation configlib.GlobalUISettingsImplementation
	Resources                      ResourceManager
}

func (*SystemConfigProvider) SystemConfig

func (p *SystemConfigProvider) SystemConfig(ctx context.Context) (*model.SystemConfig, error)

type Usage

type Usage string
const (
	UsageProxy    Usage = "proxy"
	UsageInternal Usage = "internal"
)

type UsageService

type UsageService struct {
	GlobalDatabase *globaldb.Handle
	UsageStore     UsageUsageStore
}

func (*UsageService) GetUsage

func (s *UsageService) GetUsage(
	ctx context.Context,
	appID string,
	date time.Time,
) (
	*model.Usage,
	error,
)

type UsageUsageStore

type UsageUsageStore interface {
	FetchUsageRecordsInRange(
		ctx context.Context,
		appID string,
		recordName usage.RecordName,
		period periodical.Type,
		fromStartTime time.Time,
		toEndTime time.Time,
	) ([]*usage.UsageRecord, error)
	FetchUsageRecords(
		ctx context.Context,
		appID string,
		recordName usage.RecordName,
		period periodical.Type,
		startTime time.Time,
	) ([]*usage.UsageRecord, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL