Skip to content

Commit

Permalink
Merge pull request #45 from natrontech/44-integrate-git-transactions
Browse files Browse the repository at this point in the history
integrates git transactions
  • Loading branch information
Joel-Haeberli committed Aug 15, 2023
2 parents b695f4e + 9c1b4d1 commit c79ebf2
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 47 deletions.
2 changes: 2 additions & 0 deletions momentum-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dev-setup.sh
momentum-core
5 changes: 4 additions & 1 deletion momentum-core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ generate-api-spec: check-swagger
swag init

install-swagger:
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/swaggo/swag/cmd/swag@latest

setup-dev: dev-setup.sh
. ./dev-setup.sh
13 changes: 13 additions & 0 deletions momentum-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Momentum-Core

The core of momentum is about managing the core structure and functionality of a core repository as described in the momentum-structure.

The core implements a REST-API empowering consumers to manage their repository instance.

# Environment variables

| Name | Description | Mandatory
|--------------|-------------|-----------
| MOMENTUM_GIT_USER | Username for user who creates transactions | yes
| MOMENTUM_GIT_EMAIL | Email for the user who creates the transactions | yes
| MOMENTUM_GIT_TOKEN | Access token which belongs to the user who creates the transaction | yes
38 changes: 38 additions & 0 deletions momentum-core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import (
"errors"
"momentum-core/utils"
"os"

gittransaction "github.com/Joel-Haeberli/git-transaction"
)

const MOMENTUM_ROOT = "momentum-root"

const TRANSACTION_MODE = gittransaction.DEBUG

const MOMENTUM_GIT_USER = "MOMENTUM_GIT_USER"
const MOMENTUM_GIT_EMAIL = "MOMENTUM_GIT_EMAIL"
const MOMENTUM_GIT_TOKEN = "MOMENTUM_GIT_TOKEN"

type ILoggerClient interface {
LogTrace(msg string, traceId string)
LogInfo(msg string, traceId string)
Expand All @@ -24,6 +32,8 @@ type MomentumConfig struct {
templatesDir string
logDir string

transactionToken *gittransaction.Token

applicationTemplateFolderPath string
stageTemplateFolderPath string
deploymentTemplateFilePath string
Expand Down Expand Up @@ -62,6 +72,10 @@ func (m *MomentumConfig) DeploymentTemplateFilePath() string {
return m.deploymentTemplateFilePath
}

func (m *MomentumConfig) TransactionToken() *gittransaction.Token {
return m.transactionToken
}

func (m *MomentumConfig) checkMandatoryTemplates() error {

if !utils.FileExists(m.ApplicationTemplateFolderPath()) {
Expand All @@ -83,6 +97,25 @@ func (m *MomentumConfig) checkMandatoryTemplates() error {
return nil
}

func (m *MomentumConfig) initializeGitAccessToken() error {

m.transactionToken = new(gittransaction.Token)

m.transactionToken.Username = os.Getenv(MOMENTUM_GIT_USER)
m.transactionToken.Email = os.Getenv(MOMENTUM_GIT_EMAIL)
m.transactionToken.Token = os.Getenv(MOMENTUM_GIT_TOKEN)

if m.transactionToken == nil ||
m.transactionToken.Username == "" ||
m.transactionToken.Email == "" ||
m.transactionToken.Token == "" {

return errors.New("failed initializing git transaction user please make sure to set " + MOMENTUM_GIT_USER + " and " + MOMENTUM_GIT_EMAIL + " and " + MOMENTUM_GIT_TOKEN)
}

return nil
}

func InitializeMomentumCore() (*MomentumConfig, error) {

usrHome, err := os.UserHomeDir()
Expand Down Expand Up @@ -110,6 +143,11 @@ func InitializeMomentumCore() (*MomentumConfig, error) {
config.deploymentTemplateFolderPath = utils.BuildPath(templatesDir, "deployments", "deploymentName")
config.deploymentTemplateFilePath = utils.BuildPath(templatesDir, "deployments", "deploymentName.yaml")

err = config.initializeGitAccessToken()
if err != nil {
return nil, err
}

err = config.checkMandatoryTemplates()
if err != nil {
return nil, err
Expand Down
37 changes: 24 additions & 13 deletions momentum-core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module momentum-core
go 1.20

require (
github.com/Joel-Haeberli/git-transaction v0.1.4
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.3.0
github.com/json-iterator/go v1.1.12
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.1
gopkg.in/src-d/go-git.v4 v4.13.1
sigs.k8s.io/kustomize/api v0.14.0
Expand All @@ -14,25 +17,33 @@ require (

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-git/v5 v5.8.0 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-swagger/go-swagger v0.30.5 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/labstack/echo v3.3.10+incompatible // indirect
github.com/labstack/gommon v0.2.9 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.0.1 // indirect
golang.org/x/tools v0.9.3 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/tools v0.11.0 // indirect
)

require (
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand All @@ -49,10 +60,10 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -64,18 +75,18 @@ require (
github.com/pdrum/swagger-automation v0.0.0-20190629163613-c8c7c80ba858
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/src-d/gcfg v1.4.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading

0 comments on commit c79ebf2

Please sign in to comment.