Skip to content

Commit e742e29

Browse files
committed
fix: public key not being output
1 parent 3231a72 commit e742e29

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

cmd/centra-server/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package main
33
import (
44
"log"
55
"net/http"
6+
"path/filepath"
67

78
"github.com/cheetahbyte/centra/internal/api"
89
"github.com/cheetahbyte/centra/internal/config"
910
"github.com/cheetahbyte/centra/internal/content"
1011
"github.com/cheetahbyte/centra/internal/helper"
1112
"github.com/cheetahbyte/centra/internal/logger"
13+
"github.com/cheetahbyte/drift/keys"
1214

1315
"github.com/go-chi/chi/v5"
1416
)
@@ -26,10 +28,21 @@ func main() {
2628
log := logger.AcquireLogger()
2729

2830
if conf.GitRepo != "" {
31+
if conf.PublicKey != "" {
32+
log.Info().Str("ssh key", conf.PublicKey).Msg("add this ssh key to your github repository as deploy key.")
33+
} else {
34+
publicKeyPath := filepath.Join(conf.KeysDir, "id_ed25519.pub")
35+
pubKey, err := keys.GetPublicKey(publicKeyPath)
36+
if err != nil {
37+
log.Fatal().Err(err).Msg("failed to output public ssh key")
38+
}
39+
log.Info().Str("ssh key", helper.PublicKeyToString(pubKey)).Msg("add this ssh key to your github repository as deploy key.")
40+
}
2941
gitClient := helper.SetupGit()
3042
if err := gitClient.Prepare(conf.GitRepo, conf.ContentRoot); err != nil {
3143
log.Fatal().Err(err).Msg("failed to clone or prepare git repository")
3244
}
45+
3346
}
3447

3548
if err := content.LoadAll(conf.ContentRoot); err != nil {

go.mod

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,20 @@ module github.com/cheetahbyte/centra
33
go 1.25.5
44

55
require (
6-
github.com/cheetahbyte/drift v0.1.0
6+
github.com/caarlos0/env/v10 v10.0.0
7+
github.com/cheetahbyte/drift v0.2.0
78
github.com/go-chi/chi/v5 v5.2.3
89
github.com/go-chi/cors v1.2.2
910
github.com/go-chi/httprate v0.15.0
1011
github.com/goccy/go-yaml v1.18.0
1112
github.com/rs/zerolog v1.34.0
12-
github.com/stretchr/testify v1.11.1
13-
golang.org/x/crypto v0.46.0
1413
)
1514

1615
require (
17-
github.com/caarlos0/env/v10 v10.0.0 // indirect
18-
github.com/davecgh/go-spew v1.1.1 // indirect
1916
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
20-
github.com/kr/pretty v0.3.1 // indirect
2117
github.com/mattn/go-colorable v0.1.13 // indirect
2218
github.com/mattn/go-isatty v0.0.19 // indirect
23-
github.com/pmezard/go-difflib v1.0.0 // indirect
24-
github.com/rogpeppe/go-internal v1.14.1 // indirect
2519
github.com/zeebo/xxh3 v1.0.2 // indirect
20+
golang.org/x/crypto v0.46.0 // indirect
2621
golang.org/x/sys v0.39.0 // indirect
27-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
28-
gopkg.in/yaml.v3 v3.0.1 // indirect
2922
)

go.sum

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ github.com/caarlos0/env/v10 v10.0.0 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdz
22
github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18=
33
github.com/cheetahbyte/drift v0.1.0 h1:jXVeTWuKRMuZLQaBLqevUfUryu69qkNMjFm0Yra1pUI=
44
github.com/cheetahbyte/drift v0.1.0/go.mod h1:nGgDPTvPB5bM8i8t/vWuu2+bgJQJEmu7oclfwekyKY0=
5+
github.com/cheetahbyte/drift v0.2.0 h1:4HKj9gwT22pZa2DVn4yBffSZddS1U2M4NQLsmTlQ++c=
6+
github.com/cheetahbyte/drift v0.2.0/go.mod h1:nGgDPTvPB5bM8i8t/vWuu2+bgJQJEmu7oclfwekyKY0=
57
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
6-
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
7-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
98
github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE=
109
github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
1110
github.com/go-chi/cors v1.2.2 h1:Jmey33TE+b+rB7fT8MUy1u0I4L+NARQlK6LhzKPSyQE=
@@ -17,30 +16,15 @@ github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7Lk
1716
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
1817
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
1918
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
20-
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
21-
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
22-
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
23-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
24-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
25-
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
26-
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
2719
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2820
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
2921
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
3022
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
3123
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
32-
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
3324
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
34-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
35-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
36-
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
37-
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
38-
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
3925
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
4026
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
4127
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
42-
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
43-
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
4428
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
4529
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
4630
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
@@ -56,8 +40,3 @@ golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
5640
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
5741
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
5842
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
59-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
60-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
61-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
62-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
63-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/helper/git.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func SetupGit() *git.Client {
1818
conf.PrivateKey,
1919
conf.PublicKey,
2020
)
21+
2122
if err != nil {
2223
log.Fatal().Err(err).Msg("failed to setup ssh keys")
2324
}

internal/helper/ssh.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package helper
2+
3+
import (
4+
"strings"
5+
6+
"golang.org/x/crypto/ssh"
7+
)
8+
9+
func PublicKeyToString(pub ssh.PublicKey) string {
10+
// MarshalAuthorizedKey returns bytes in the format: "type base64-key\n"
11+
pubBytes := ssh.MarshalAuthorizedKey(pub)
12+
13+
// Convert to string and trim the trailing newline
14+
return strings.TrimSpace(string(pubBytes))
15+
}

0 commit comments

Comments
 (0)