octopush/internal/serverdeps/server_deps.go

65 lines
1.8 KiB
Go
Raw Normal View History

2022-09-10 20:20:49 +02:00
package serverdeps
2022-09-11 14:52:21 +02:00
import (
2022-09-12 09:52:44 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/services/actions"
2022-09-11 22:56:54 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/services/providers"
2022-09-12 14:38:15 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/services/signer"
2022-09-11 14:52:21 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/services/storage"
"go.uber.org/zap"
)
2022-09-10 20:20:49 +02:00
type ServerDeps struct {
2022-09-12 14:38:15 +02:00
logger *zap.Logger
2022-09-11 14:52:21 +02:00
storageConfig *storage.StorageConfig
2022-09-11 22:56:54 +02:00
gitCfg *providers.GitConfig
2022-09-12 14:38:15 +02:00
openPGP *signer.OpenPGP
2022-09-10 20:20:49 +02:00
}
func NewServerDeps(logger *zap.Logger) *ServerDeps {
2022-09-11 14:52:21 +02:00
deps := &ServerDeps{
2022-09-12 09:52:44 +02:00
logger: logger.With(zap.Namespace("serverdeps")),
2022-09-10 20:20:49 +02:00
}
2022-09-11 14:52:21 +02:00
if storageCfg, err := storage.NewDefaultStorageConfig(); err != nil {
panic(err)
} else {
deps.storageConfig = storageCfg
}
2022-09-11 22:56:54 +02:00
deps.gitCfg = &providers.GitConfig{
AuthOption: providers.GIT_AUTH_SSH,
User: "git",
Password: "",
AccessToken: "",
SshPublicKeyFilePath: "/Users/kah/.ssh/id_ed25519",
SshPrivateKeyPassword: "",
}
2022-09-12 14:38:15 +02:00
openPGPConfig := &signer.OpenPgpConfig{
2022-09-12 22:05:06 +02:00
PrivateKeyFilePath: "./example/testkey.private.pgp",
2022-09-12 14:38:15 +02:00
PrivateKeyPassword: "somepassword",
2022-09-12 22:05:06 +02:00
PrivateKeyIdentity: "kraken@kasperhermansen.com",
2022-09-12 14:38:15 +02:00
}
deps.openPGP = signer.NewOpenPGP(logger.With(zap.Namespace("openpgp")), openPGPConfig)
2022-09-11 14:52:21 +02:00
return deps
}
func (deps *ServerDeps) GetStorageService() *storage.Service {
2022-09-12 09:52:44 +02:00
return storage.NewService(deps.logger.With(zap.Namespace("storage")), deps.storageConfig)
2022-09-11 22:56:54 +02:00
}
func (deps *ServerDeps) GetGitProvider() *providers.Git {
2022-09-12 22:05:06 +02:00
return providers.NewGit(deps.logger.With(zap.Namespace("gitProvider")), deps.gitCfg, deps.openPGP)
2022-09-12 09:52:44 +02:00
}
func (deps *ServerDeps) GetAction() *actions.Action {
return actions.NewAction(deps.logger.With(zap.Namespace("action")))
2022-09-10 20:20:49 +02:00
}
2022-09-12 14:38:15 +02:00
func (deps *ServerDeps) GetOpenPGP() *signer.OpenPGP {
return deps.openPGP
}