Skip to content

Commit

Permalink
API: Merged devel into API-Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartoffel096 committed Oct 8, 2024
2 parents 8380669 + e756cce commit 13024d8
Show file tree
Hide file tree
Showing 18 changed files with 344 additions and 495 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ certs/**
config.yaml
config.yml
packagelock.pid
packagelock/**
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/HilkopterBob/PackageLock/.github%2Fworkflows%2Frun-tests.yml)
![GitHub Actions Workflow Status](https://github.com/hilkopterbob/packagelock/actions/workflows/test-build.yml/badge.svg)
![GitHub Actions Workflow Status](https://github.com/hilkopterbob/packagelock/actions/workflows/golangci-lint.yml/badge.svg)
![GitHub Actions Workflow Status](https://github.com/hilkopterbob/packagelock/actions/workflows/build-docker-container.yml/badge.svg)
![GitHub Actions Workflow Status](https://github.com/hilkopterbob/packagelock/actions/workflows/unstable-build-docker-container.yml/badge.svg)

![GitHub repo file or directory count](https://img.shields.io/github/directory-file-count/HilkopterBob/PackageLock)


Expand Down Expand Up @@ -132,17 +137,22 @@ sudo docker run -p 8080:8080 hilkopterbob/packagelock
The default-config:
```yaml
general:
debug: true
production: false
debug: true
production: false
database:
address: 127.0.0.1
port: 8000
username: root
password: root
network:
fqdn: 0.0.0.0
port: 8080
ssl: true
ssl-config:
allowselfsigned: true
certificatepath: ./certs/testing.crt
privatekeypath: ./certs/testing.key
redirecthttp: true
fqdn: 0.0.0.0
port: 8080
ssl: true
ssl-config:
allowselfsigned: true
certificatepath: ./certs/testing.crt
privatekeypath: ./certs/testing.key
redirecthttp: true
```
Expand All @@ -164,6 +174,8 @@ TODO: explain usage
- [ ] backend-api to manage Agents & Hosts
- [ ] frontend to visualize backend data
- [ ] installable agent as background daemon
- [ ] agent CLI:
- [ ] `packagelock id` -> returns agent id
- [ ] config management
- [ ] TLS Encryption
- [ ] Best Practice based Package Layout
Expand Down
30 changes: 18 additions & 12 deletions certs/generate-certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ func CreateSelfSignedCert(certFile, keyFile string) error {
if err != nil {
return fmt.Errorf("failed to open cert.pem for writing: %v", err)
}
defer certOut.Close()

// INFO: If the parrent throws an err and this defer is called
// and fileOut.Close() throws an error to, the original error will be overwritten.
defer func() {
err := certOut.Close()
if err != nil {
panic(err)
}
}()

if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certDER}); err != nil {
return fmt.Errorf("failed to write certificate to cert.pem: %v", err)
Expand All @@ -63,7 +71,15 @@ func CreateSelfSignedCert(certFile, keyFile string) error {
if err != nil {
return fmt.Errorf("failed to open key.pem for writing: %v", err)
}
defer keyOut.Close()

// INFO: If the parrent throws an err and this defer is called
// and fileOut.Close() throws an error to, the original error will be overwritten.
defer func() {
err := keyOut.Close()
if err != nil {
panic(err)
}
}()

// Marshal the RSA private key
privBytes := x509.MarshalPKCS1PrivateKey(priv)
Expand All @@ -74,13 +90,3 @@ func CreateSelfSignedCert(certFile, keyFile string) error {
fmt.Println("Successfully created self-signed RSA certificate and private key.")
return nil
}

func main() {
// Call the function to create the self-signed certificate and private key
err := CreateSelfSignedCert("server.crt", "server.key")
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Certificate and key generation successful.")
}
}
10 changes: 5 additions & 5 deletions config/conf-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ func StartViper(config ConfigProvider) ConfigProvider {
func CreateDefaultConfig(config ConfigProvider) {
// TODO: Add default config
yamlExample := []byte(`
generalgeneral:
general:
debug: true
production: false
database:
address: 172.19.0.2
port: 27017
username: username
password: password
address: 127.0.0.1
port: 8000
username: root
password: root
network:
fqdn: 0.0.0.0
port: 8080
Expand Down
24 changes: 0 additions & 24 deletions db/connector.go

This file was deleted.

72 changes: 72 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package db

import (
"fmt"
"packagelock/config"

"github.com/surrealdb/surrealdb.go"
)

var DB *surrealdb.DB

Check failure on line 10 in db/db.go

View workflow job for this annotation

GitHub Actions / lint

undefined: surrealdb (typecheck)

func InitDB() error {
dbAddress := config.Config.GetString("database.address")
dbPort := config.Config.GetString("database.port")
dbUsername := config.Config.GetString("database.username")
dbPasswd := config.Config.GetString("database.password")

db, err := surrealdb.New("ws://" + dbAddress + ":" + dbPort + "/rpc")

Check failure on line 18 in db/db.go

View workflow job for this annotation

GitHub Actions / lint

undefined: surrealdb (typecheck)
if err != nil {
errorMessage := fmt.Sprintf(` Couldn't connect to DB! Got: '%s'.
1. Check the config for a wrong Address/Port (Currently: %s:%s)
2. Check if the DB is reachable (eg. a Ping). Check the Firewalls if there.
3. Consult the PackageLock Doc's! 🚀
Golang Trace Logs:
`, err.Error(), dbAddress, dbPort)
fmt.Println(errorMessage)
panic(err)
}

if _, err = db.Signin(map[string]interface{}{
// TODO: get user&password from Conf
"user": dbUsername,
"pass": dbPasswd,
}); err != nil {
errorMessage := fmt.Sprintf(` Couldn't connect to DB! Got: '%s'.
1. Check the config for a wrong DB-Username/Password (Currently: %s/<read the config!>)
3. Consult the PackageLock Doc's! 🚀
Golang Trace Logs:
`, err.Error(), dbUsername)
fmt.Println(errorMessage)
panic(err)
}

if _, err = db.Use("PackageLock", "db1.0"); err != nil {
// No error handling possible, as we need to use this db
panic(err)
}

DB = db

return nil
}

// INFO: If you use this, fix it!
func Select(tablename string, SliceOfType interface{}) error {
transaction, err := DB.Select(tablename)
if err != nil {
// FIXME: logging?
// Error handling
panic(err)

Check failure on line 60 in db/db.go

View workflow job for this annotation

GitHub Actions / lint

undefined: surrealdb (typecheck)
}

err = surrealdb.Unmarshal(transaction, &SliceOfType)
if err != nil {
// FIXME: Logging?
// Error Handling?
panic(err)
}

// FIXME: Add Success msg in Log!
return nil
}
3 changes: 3 additions & 0 deletions db/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package db

// this package is for future DB migrations
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ services:
ports:
- "8080:8080" # Map your container's port to the host. Change if necessary
volumes:
- ./data/certs:/app/certs
- ./data/config.yml:/app/config.yaml
- ./packagelock/certs:/app/certs # Mount certs to /app/certs
- ./packagelock/config:/app/config # Mount config to /app/config
restart: always # Automatically restart the container if it stops

packagelock-db:
image: surrealdb/surrealdb:v2.0.3
command: start -A --auth --user root --pass pass file:/db/database
volumes:
- ./packagelock/db:/db # Mount db directory to the database service
ports:
- ${DATABASE_PORT}:8000
16 changes: 7 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ require (
github.com/gofiber/template/html/v2 v2.1.2
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
github.com/k0kubun/pp v3.0.1+incompatible
github.com/k0kubun/pp/v3 v3.2.0
github.com/sethvargo/go-password v0.3.1
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
go.mongodb.org/mongo-driver v1.16.1
github.com/surrealdb/surrealdb.go v0.2.1
)

require (
github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/utils v1.1.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand All @@ -41,15 +45,9 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
Loading

0 comments on commit 13024d8

Please sign in to comment.