2024-02-13 10:47:57 +00:00
|
|
|
package temporal
|
|
|
|
|
|
|
|
import (
|
2024-02-18 21:37:17 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/rsa"
|
2024-02-13 10:47:57 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2024-05-23 16:33:30 +00:00
|
|
|
internal "github.com/mentos1386/zdravko/internal/config"
|
|
|
|
"github.com/mentos1386/zdravko/pkg/jwt"
|
2024-02-13 10:47:57 +00:00
|
|
|
"go.temporal.io/server/common/cluster"
|
|
|
|
"go.temporal.io/server/common/config"
|
|
|
|
"go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite"
|
|
|
|
)
|
|
|
|
|
|
|
|
const PersistenceStoreName = "sqlite-default"
|
|
|
|
|
|
|
|
const BroadcastAddress = "127.0.0.1"
|
|
|
|
|
2024-06-02 19:53:51 +00:00
|
|
|
const FrontendHttpPort = 7243
|
2024-02-13 10:47:57 +00:00
|
|
|
const FrontendPort = 7233
|
|
|
|
const HistoryPort = 7234
|
|
|
|
const MatchingPort = 7235
|
2024-06-02 19:53:51 +00:00
|
|
|
const WorkerPort = 7239
|
|
|
|
const InternalFrontendPort = 7236
|
2024-02-13 10:47:57 +00:00
|
|
|
|
2024-02-18 21:37:17 +00:00
|
|
|
type TokenKeyProvider struct {
|
2024-02-19 09:09:30 +00:00
|
|
|
config *internal.TemporalConfig
|
2024-02-18 21:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TokenKeyProvider) SupportedMethods() []string {
|
|
|
|
return []string{"RS256", "RS384", "RS512"}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TokenKeyProvider) HmacKey(alg string, kid string) ([]byte, error) {
|
|
|
|
return nil, fmt.Errorf("HMAC key is not supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TokenKeyProvider) EcdsaKey(alg string, kid string) (*ecdsa.PublicKey, error) {
|
|
|
|
return nil, fmt.Errorf("ECDSA key is not supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TokenKeyProvider) RsaKey(alg string, kid string) (*rsa.PublicKey, error) {
|
2024-02-19 09:09:30 +00:00
|
|
|
return jwt.JwtPublicKey(p.config.Jwt.PublicKey)
|
2024-02-18 21:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TokenKeyProvider) Close() {
|
|
|
|
}
|
|
|
|
|
2024-02-19 09:09:30 +00:00
|
|
|
func NewServerConfig(cfg *internal.TemporalConfig) *config.Config {
|
2024-02-13 10:47:57 +00:00
|
|
|
return &config.Config{
|
|
|
|
Persistence: config.Persistence{
|
|
|
|
DataStores: map[string]config.DataStore{
|
|
|
|
PersistenceStoreName: {SQL: &config.SQL{
|
|
|
|
PluginName: sqlite.PluginName,
|
|
|
|
ConnectAttributes: map[string]string{
|
|
|
|
"mode": "rwc",
|
|
|
|
},
|
2024-02-19 09:09:30 +00:00
|
|
|
DatabaseName: cfg.DatabasePath,
|
2024-02-13 10:47:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultStore: PersistenceStoreName,
|
|
|
|
VisibilityStore: PersistenceStoreName,
|
|
|
|
NumHistoryShards: 1,
|
|
|
|
},
|
|
|
|
Global: config.Global{
|
|
|
|
Membership: config.Membership{
|
|
|
|
MaxJoinDuration: 30 * time.Second,
|
|
|
|
BroadcastAddress: BroadcastAddress,
|
|
|
|
},
|
2024-02-18 21:37:17 +00:00
|
|
|
Authorization: config.Authorization{},
|
2024-02-13 10:47:57 +00:00
|
|
|
},
|
|
|
|
Services: map[string]config.Service{
|
|
|
|
"frontend": {
|
|
|
|
RPC: config.RPC{
|
|
|
|
HTTPPort: FrontendHttpPort,
|
|
|
|
GRPCPort: FrontendPort,
|
|
|
|
MembershipPort: FrontendPort + 100,
|
|
|
|
BindOnLocalHost: false,
|
2024-02-19 09:09:30 +00:00
|
|
|
BindOnIP: cfg.ListenAddress,
|
2024-02-13 10:47:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"history": {
|
|
|
|
RPC: config.RPC{
|
|
|
|
GRPCPort: HistoryPort,
|
|
|
|
MembershipPort: HistoryPort + 100,
|
|
|
|
BindOnLocalHost: true,
|
|
|
|
BindOnIP: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"matching": {
|
|
|
|
RPC: config.RPC{
|
|
|
|
GRPCPort: MatchingPort,
|
|
|
|
MembershipPort: MatchingPort + 100,
|
|
|
|
BindOnLocalHost: true,
|
|
|
|
BindOnIP: "",
|
|
|
|
},
|
|
|
|
},
|
2024-02-19 14:23:17 +00:00
|
|
|
"worker": {
|
|
|
|
RPC: config.RPC{
|
|
|
|
GRPCPort: WorkerPort,
|
|
|
|
MembershipPort: WorkerPort + 100,
|
|
|
|
BindOnLocalHost: true,
|
|
|
|
BindOnIP: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"internal-frontend": {
|
|
|
|
RPC: config.RPC{
|
|
|
|
GRPCPort: InternalFrontendPort,
|
|
|
|
MembershipPort: InternalFrontendPort + 100,
|
|
|
|
BindOnLocalHost: true,
|
|
|
|
BindOnIP: "",
|
|
|
|
},
|
|
|
|
},
|
2024-02-13 10:47:57 +00:00
|
|
|
},
|
|
|
|
ClusterMetadata: &cluster.Config{
|
|
|
|
EnableGlobalNamespace: false,
|
|
|
|
FailoverVersionIncrement: 10,
|
|
|
|
MasterClusterName: "active",
|
|
|
|
CurrentClusterName: "active",
|
|
|
|
ClusterInformation: map[string]cluster.ClusterInformation{
|
|
|
|
"active": {
|
|
|
|
Enabled: true,
|
|
|
|
InitialFailoverVersion: 1,
|
2024-02-19 14:23:17 +00:00
|
|
|
RPCAddress: fmt.Sprintf("%s:%d", BroadcastAddress, InternalFrontendPort),
|
2024-02-13 10:47:57 +00:00
|
|
|
ClusterID: "todo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DCRedirectionPolicy: config.DCRedirectionPolicy{
|
|
|
|
Policy: "noop",
|
|
|
|
},
|
|
|
|
Archival: config.Archival{
|
|
|
|
History: config.HistoryArchival{
|
|
|
|
State: "disabled",
|
|
|
|
EnableRead: false,
|
|
|
|
Provider: nil,
|
|
|
|
},
|
|
|
|
Visibility: config.VisibilityArchival{
|
|
|
|
State: "disabled",
|
|
|
|
EnableRead: false,
|
|
|
|
Provider: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NamespaceDefaults: config.NamespaceDefaults{
|
|
|
|
Archival: config.ArchivalNamespaceDefaults{
|
|
|
|
History: config.HistoryArchivalNamespaceDefaults{
|
|
|
|
State: "disabled",
|
|
|
|
},
|
|
|
|
Visibility: config.VisibilityArchivalNamespaceDefaults{
|
|
|
|
State: "disabled",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|