From 3e187a11a0748a13f3eaa84b640d653be1507b82 Mon Sep 17 00:00:00 2001 From: Viktor Liu Date: Thu, 8 Jan 2026 00:25:23 +0800 Subject: [PATCH] Add no-cgo stubs to idp/dex to fix building testing binaries --- idp/dex/config.go | 2 + idp/dex/provider.go | 2 + idp/dex/provider_test.go | 2 + idp/dex/stub.go | 222 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 idp/dex/stub.go diff --git a/idp/dex/config.go b/idp/dex/config.go index 57f832406..d531eccc2 100644 --- a/idp/dex/config.go +++ b/idp/dex/config.go @@ -1,3 +1,5 @@ +//go:build cgo + package dex import ( diff --git a/idp/dex/provider.go b/idp/dex/provider.go index 09713a226..3f8c3b266 100644 --- a/idp/dex/provider.go +++ b/idp/dex/provider.go @@ -1,3 +1,5 @@ +//go:build cgo + // Package dex provides an embedded Dex OIDC identity provider. package dex diff --git a/idp/dex/provider_test.go b/idp/dex/provider_test.go index bc34e592f..d42264436 100644 --- a/idp/dex/provider_test.go +++ b/idp/dex/provider_test.go @@ -1,3 +1,5 @@ +//go:build cgo + package dex import ( diff --git a/idp/dex/stub.go b/idp/dex/stub.go new file mode 100644 index 000000000..68968e465 --- /dev/null +++ b/idp/dex/stub.go @@ -0,0 +1,222 @@ +//go:build !cgo + +// Package dex provides an embedded Dex OIDC identity provider. +// This stub exists for non-CGO builds where SQLite is unavailable. +package dex + +import ( + "context" + "errors" + "log/slog" + "net/http" + + "github.com/dexidp/dex/server" + "github.com/dexidp/dex/storage" +) + +var errNoCGO = errors.New("embedded IdP requires CGO (SQLite)") + +// Config for simple provider creation +type Config struct { + Issuer string + Port int + DataDir string + DevMode bool + GRPCAddr string +} + +// Provider wraps a Dex server +type Provider struct{} + +// NewProvider creates a new Provider +func NewProvider(_ context.Context, _ *Config) (*Provider, error) { return nil, errNoCGO } + +// NewProviderFromYAML creates a Provider from YAML config +func NewProviderFromYAML(_ context.Context, _ *YAMLConfig) (*Provider, error) { return nil, errNoCGO } + +// Start starts the server +func (p *Provider) Start(_ context.Context) error { return errNoCGO } + +// Stop stops the server +func (p *Provider) Stop(_ context.Context) error { return errNoCGO } + +// EnsureDefaultClients ensures default clients exist +func (p *Provider) EnsureDefaultClients(_ context.Context, _, _ []string) error { return errNoCGO } + +// Storage returns the storage +func (p *Provider) Storage() storage.Storage { return nil } + +// Handler returns the HTTP handler +func (p *Provider) Handler() http.Handler { return nil } + +// CreateUser creates a user +func (p *Provider) CreateUser(_ context.Context, _, _, _ string) (string, error) { + return "", errNoCGO +} + +// GetUser gets a user +func (p *Provider) GetUser(_ context.Context, _ string) (storage.Password, error) { + return storage.Password{}, errNoCGO +} + +// GetUserByID gets a user by ID +func (p *Provider) GetUserByID(_ context.Context, _ string) (storage.Password, error) { + return storage.Password{}, errNoCGO +} + +// DeleteUser deletes a user +func (p *Provider) DeleteUser(_ context.Context, _ string) error { return errNoCGO } + +// ListUsers lists users +func (p *Provider) ListUsers(_ context.Context) ([]storage.Password, error) { return nil, errNoCGO } + +// GetRedirectURI returns the redirect URI +func (p *Provider) GetRedirectURI() string { return "" } + +// GetIssuer returns the issuer +func (p *Provider) GetIssuer() string { return "" } + +// GetTokenEndpoint returns the token endpoint +func (p *Provider) GetTokenEndpoint() string { return "" } + +// GetDeviceAuthEndpoint returns the device auth endpoint +func (p *Provider) GetDeviceAuthEndpoint() string { return "" } + +// GetAuthorizationEndpoint returns the auth endpoint +func (p *Provider) GetAuthorizationEndpoint() string { return "" } + +// GetKeysLocation returns the keys location +func (p *Provider) GetKeysLocation() string { return "" } + +// ConnectorConfig for identity provider connectors +type ConnectorConfig struct { + ID, Name, Type, Issuer, ClientID, ClientSecret string + Scopes []string + UserIDKey, UserNameKey, EmailKey string + InsecureSkipVerify bool + AuthorizationURL, TokenURL, UserInfoURL string + IdentityProviderType string +} + +// CreateConnector creates a connector +func (p *Provider) CreateConnector(_ context.Context, _ *ConnectorConfig) (*ConnectorConfig, error) { + return nil, errNoCGO +} + +// GetConnector gets a connector +func (p *Provider) GetConnector(_ context.Context, _ string) (*ConnectorConfig, error) { + return nil, errNoCGO +} + +// ListConnectors lists connectors +func (p *Provider) ListConnectors(_ context.Context) ([]*ConnectorConfig, error) { return nil, errNoCGO } + +// UpdateConnector updates a connector +func (p *Provider) UpdateConnector(_ context.Context, _ *ConnectorConfig) error { return errNoCGO } + +// DeleteConnector deletes a connector +func (p *Provider) DeleteConnector(_ context.Context, _ string) error { return errNoCGO } + +// EncodeDexUserID encodes a user ID +func EncodeDexUserID(_, _ string) string { return "" } + +// DecodeDexUserID decodes a user ID +func DecodeDexUserID(_ string) (string, string, error) { return "", "", errNoCGO } + +// YAMLConfig for YAML-based configuration +type YAMLConfig struct { + Issuer string `yaml:"issuer" json:"issuer"` + Storage Storage `yaml:"storage" json:"storage"` + Web Web `yaml:"web" json:"web"` + GRPC GRPC `yaml:"grpc" json:"grpc"` + OAuth2 OAuth2 `yaml:"oauth2" json:"oauth2"` + Expiry Expiry `yaml:"expiry" json:"expiry"` + Logger Logger `yaml:"logger" json:"logger"` + Frontend Frontend `yaml:"frontend" json:"frontend"` + StaticConnectors []Connector `yaml:"connectors" json:"connectors"` + StaticClients []storage.Client `yaml:"staticClients" json:"staticClients"` + EnablePasswordDB bool `yaml:"enablePasswordDB" json:"enablePasswordDB"` + StaticPasswords []Password `yaml:"staticPasswords" json:"staticPasswords"` +} + +// Validate validates config +func (c *YAMLConfig) Validate() error { return errNoCGO } + +// ToServerConfig converts to server config +func (c *YAMLConfig) ToServerConfig(_ storage.Storage, _ *slog.Logger) server.Config { + return server.Config{} +} + +// GetRefreshTokenPolicy gets refresh policy +func (c *YAMLConfig) GetRefreshTokenPolicy(_ *slog.Logger) (*server.RefreshTokenPolicy, error) { + return nil, errNoCGO +} + +// LoadConfig loads config from file +func LoadConfig(_ string) (*YAMLConfig, error) { return nil, errNoCGO } + +// Web config +type Web struct { + HTTP, HTTPS string + AllowedOrigins []string + AllowedHeaders []string +} + +// GRPC config +type GRPC struct{ Addr, TLSCert, TLSKey, TLSClientCA string } + +// OAuth2 config +type OAuth2 struct { + SkipApprovalScreen, AlwaysShowLoginScreen bool + PasswordConnector string + ResponseTypes, GrantTypes []string +} + +// Expiry config +type Expiry struct { + SigningKeys, IDTokens, AuthRequests, DeviceRequests string + RefreshTokens RefreshTokensExpiry +} + +// RefreshTokensExpiry config +type RefreshTokensExpiry struct { + ReuseInterval, ValidIfNotUsedFor, AbsoluteLifetime string + DisableRotation bool +} + +// Logger config +type Logger struct{ Level, Format string } + +// Frontend config +type Frontend struct { + Dir, Theme, Issuer, LogoURL string + Extra map[string]string +} + +// Storage config +type Storage struct { + Type string + Config map[string]interface{} +} + +// OpenStorage opens storage +func (s *Storage) OpenStorage(_ *slog.Logger) (storage.Storage, error) { return nil, errNoCGO } + +// Password type +type Password storage.Password + +// Connector config +type Connector struct { + Type, Name, ID string + Config map[string]interface{} +} + +// ToStorageConnector converts to storage connector +func (c *Connector) ToStorageConnector() (storage.Connector, error) { + return storage.Connector{}, errNoCGO +} + +// StorageConfig interface +type StorageConfig interface { + Open(logger *slog.Logger) (storage.Storage, error) +}