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