Skip to content

Commit 08e318a

Browse files
committed
feat: adding repository server and patch commands
1 parent fda64ff commit 08e318a

22 files changed

Lines changed: 428 additions & 419 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ hack/soft-serve/ssh-key.pub
1313

1414
.vscode/launch.json
1515

16+
.env
17+
1618
# Ignore "main" binary
1719
main
1820
# Ignore "gitops" binary

cmd/gitops/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,52 +212,52 @@ func main() {
212212
Usage: "Patch a single file in a GitOps cluster repository",
213213
Flags: []cli.Flag{
214214
&cli.StringFlag{
215-
Name: "repo-server",
215+
Name: "repository-server",
216216
Value: "",
217217
Usage: "GitOps repo server to be used for the patch",
218-
EnvVars: []string{"GITOPS_REPO_SERVER"},
218+
EnvVars: []string{"GITOPS_REPOSITORY_SERVER"},
219219
},
220220
&cli.StringFlag{
221-
Name: "repo-server-api-key",
221+
Name: "repository-server-api-key",
222222
Value: "",
223223
Usage: "GitOps repo server to be used for the patch",
224-
EnvVars: []string{"GITOPS_REPO_SERVER_API_KEY"},
224+
EnvVars: []string{"GITOPS_REPOSITORY_SERVER_API_KEY"},
225225
},
226226
&cli.StringFlag{
227-
Name: "repo",
227+
Name: "repository",
228228
Value: "",
229229
Usage: "Repo to be used for the patch",
230-
EnvVars: []string{"GITOPS_REPO"},
230+
EnvVars: []string{"GITOPS_REPOSITORY"},
231231
},
232232
&cli.StringFlag{
233233
Name: "branch",
234234
Value: "main",
235235
Usage: "Branch to be used for the patch",
236-
EnvVars: []string{"GITOPS_BRANCH"},
236+
EnvVars: []string{"GITOPS_REPOSITORY_BRANCH"},
237237
},
238238
&cli.StringFlag{
239239
Name: "basicauth",
240240
Value: "",
241241
Usage: "BasicAuth for authenticating against the GitOps repository",
242-
EnvVars: []string{"GITOPS_REPO_BASICAUTH"},
242+
EnvVars: []string{"GITOPS_REPOSITORY_BASICAUTH"},
243243
},
244244
&cli.StringFlag{
245245
Name: "ssh-key",
246246
Value: "",
247247
Usage: "SSH key for authenticating against the GitOps repository",
248-
EnvVars: []string{"GITOPS_REPO_SSH_KEY"},
248+
EnvVars: []string{"GITOPS_REPOSITORY_SSH_KEY"},
249249
},
250250
&cli.StringFlag{
251251
Name: "ssh-key-file",
252252
Value: "",
253253
Usage: "SSH key file for authenticating against the GitOps repository",
254-
EnvVars: []string{"GITOPS_REPO_SSH_KEY_FILE"},
254+
EnvVars: []string{"GITOPS_REPOSITORY_SSH_KEY_FILE"},
255255
},
256256
&cli.StringFlag{
257257
Name: "ssh-key-passphrase",
258258
Value: "",
259259
Usage: "SSH key passphrase for authenticating against the GitOps repository",
260-
EnvVars: []string{"GITOPS_REPO_SSH_KEY_PASSPHRASE"},
260+
EnvVars: []string{"GITOPS_REPOSITORY_SSH_KEY_PASSPHRASE"},
261261
},
262262
},
263263
Action: func(c *cli.Context) error {

cmd/repo-server/main.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package main
33
import (
44
"os"
55

6-
"github.com/go-git/go-git/v5/plumbing/transport"
76
"github.com/rs/zerolog/log"
87

98
"github.com/mxcd/gitops-cli/internal/git"
9+
"github.com/mxcd/gitops-cli/internal/patch"
1010
"github.com/mxcd/gitops-cli/internal/repo_server/server"
1111
"github.com/mxcd/gitops-cli/internal/repo_server/util"
1212
"github.com/mxcd/go-config/config"
@@ -33,12 +33,24 @@ func main() {
3333
log.Panic().Err(err).Msg("error cloning git repository")
3434
}
3535

36-
server, err := server.NewServer(&server.RouterConfig{
36+
gitPatcher, err := patch.NewGitPatcher(&patch.GitPatcherOptions{
37+
GitConnection: gitConnection,
38+
})
39+
if err != nil {
40+
log.Panic().Err(err).Msg("error initializing git patcher")
41+
}
42+
43+
err = gitPatcher.Prepare(&patch.PrepareOptions{Clone: false})
44+
if err != nil {
45+
log.Panic().Err(err).Msg("error preparing git patcher")
46+
}
47+
48+
server, err := server.NewServer(&server.RouterOptions{
3749
DevMode: config.Get().Bool("DEV"),
3850
Port: config.Get().Int("PORT"),
3951
ApiBaseUrl: config.Get().String("API_BASE_URL"),
4052
ApiKeys: config.Get().StringArray("API_KEYS"),
41-
}, gitConnection)
53+
}, gitPatcher)
4254

4355
if err != nil {
4456
log.Panic().Err(err).Msg("error initializing server")
@@ -54,15 +66,14 @@ func main() {
5466
}
5567

5668
func getGitConnectionOptions() *git.ConnectionOptions {
57-
var auth transport.AuthMethod
69+
var authentication *git.Authentication
5870
var err error
5971
if config.Get().String("GITOPS_REPOSITORY_BASICAUTH") != "" {
60-
auth, err = git.GetAuthFromBasicAuthString(config.Get().String("GITOPS_REPOSITORY_BASICAUTH"))
72+
authentication, err = git.GetAuthFromBasicAuthString(config.Get().String("GITOPS_REPOSITORY_BASICAUTH"))
6173
if err != nil {
6274
log.Panic().Err(err).Msg("error getting basic auth from string")
6375
}
6476
} else if config.Get().String("GITOPS_REPOSITORY_SSH_KEY") != "" || config.Get().String("GITOPS_REPOSITORY_SSH_KEY_FILE") != "" {
65-
6677
var sshKey []byte
6778
if config.Get().String("GITOPS_REPOSITORY_SSH_KEY") != "" {
6879
sshKey = []byte(config.Get().String("GITOPS_REPOSITORY_SSH_KEY"))
@@ -79,16 +90,17 @@ func getGitConnectionOptions() *git.ConnectionOptions {
7990
passphrase = &_passphrase
8091
}
8192

82-
auth, err = git.GetAuthFromSshKey(sshKey, passphrase, config.Get().Bool("GITOPS_REPOSITORY_NO_STRICT_HOST_KEY_CHECKING"))
93+
authentication, err = git.GetAuthFromSshKey(sshKey, passphrase)
8394

8495
if err != nil {
8596
log.Panic().Err(err).Msg("error getting ssh key from string")
8697
}
8798
}
8899

89100
return &git.ConnectionOptions{
90-
Branch: config.Get().String("GITOPS_REPOSITORY_BRANCH"),
91-
Repository: config.Get().String("GITOPS_REPOSITORY"),
92-
Auth: auth,
101+
Branch: config.Get().String("GITOPS_REPOSITORY_BRANCH"),
102+
Repository: config.Get().String("GITOPS_REPOSITORY"),
103+
Authentication: authentication,
104+
IgnoreSslHostKey: config.Get().Bool("GITOPS_REPOSITORY_IGNORE_SSL_HOSTKEY"),
93105
}
94106
}

go.mod

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ toolchain go1.23.2
66

77
require (
88
github.com/gin-gonic/gin v1.10.0
9-
github.com/go-git/go-billy/v5 v5.5.0
10-
github.com/go-git/go-git/v5 v5.11.0
119
github.com/google/uuid v1.1.2
1210
github.com/schollz/progressbar/v3 v3.13.0
1311
github.com/sirupsen/logrus v1.9.0
@@ -19,20 +17,16 @@ require (
1917
)
2018

2119
require (
22-
dario.cat/mergo v1.0.0 // indirect
2320
github.com/Microsoft/go-winio v0.6.1 // indirect
2421
github.com/bytedance/sonic v1.12.6 // indirect
2522
github.com/bytedance/sonic/loader v0.2.1 // indirect
2623
github.com/cloudflare/circl v1.3.3 // indirect
2724
github.com/cloudwego/base64x v0.1.4 // indirect
2825
github.com/cloudwego/iasm v0.2.0 // indirect
29-
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
3026
github.com/davecgh/go-spew v1.1.1 // indirect
3127
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
32-
github.com/emirpasic/gods v1.18.1 // indirect
3328
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
3429
github.com/gin-contrib/sse v0.1.0 // indirect
35-
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
3630
github.com/go-logr/logr v1.2.4 // indirect
3731
github.com/go-openapi/jsonpointer v0.19.5 // indirect
3832
github.com/go-openapi/jsonreference v0.20.0 // indirect
@@ -46,34 +40,28 @@ require (
4640
github.com/google/go-cmp v0.6.0 // indirect
4741
github.com/google/gofuzz v1.1.0 // indirect
4842
github.com/imdario/mergo v0.3.6 // indirect
49-
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
5043
github.com/jedib0t/go-pretty/v6 v6.4.6 // indirect
5144
github.com/joho/godotenv v1.5.1 // indirect
5245
github.com/josharian/intern v1.0.0 // indirect
5346
github.com/json-iterator/go v1.1.12 // indirect
54-
github.com/kevinburke/ssh_config v1.2.0 // indirect
5547
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
48+
github.com/kr/pretty v0.3.1 // indirect
5649
github.com/leodido/go-urn v1.4.0 // indirect
5750
github.com/mailru/easyjson v0.7.6 // indirect
5851
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5952
github.com/modern-go/reflect2 v1.0.2 // indirect
6053
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6154
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
55+
github.com/onsi/gomega v1.27.10 // indirect
6256
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
63-
github.com/pjbgf/sha1cd v0.3.0 // indirect
6457
github.com/pmezard/go-difflib v1.0.0 // indirect
65-
github.com/sergi/go-diff v1.1.0 // indirect
66-
github.com/skeema/knownhosts v1.2.1 // indirect
58+
github.com/rogpeppe/go-internal v1.11.0 // indirect
6759
github.com/spf13/pflag v1.0.5 // indirect
6860
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
6961
github.com/ugorji/go/codec v1.2.12 // indirect
70-
github.com/xanzy/ssh-agent v0.3.3 // indirect
7162
golang.org/x/arch v0.12.0 // indirect
72-
golang.org/x/mod v0.17.0 // indirect
73-
golang.org/x/sync v0.10.0 // indirect
74-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
63+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
7564
gopkg.in/inf.v0 v0.9.1 // indirect
76-
gopkg.in/warnings.v0 v0.1.2 // indirect
7765
k8s.io/klog/v2 v2.80.1 // indirect
7866
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
7967
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect

0 commit comments

Comments
 (0)