Compare commits

..

3 commits

Author SHA1 Message Date
b18d481f03 feat #35: Add sqlite3 storage backend 2023-10-22 13:37:08 +02:00
0e41483302 TEMP 2023-10-22 13:22:54 +02:00
a6011106d5 feat #4: add storage config in config file
All checks were successful
continuous-integration/drone/push Build is passing
2023-10-22 00:01:12 +02:00
3 changed files with 28 additions and 131 deletions

View file

@ -1,88 +0,0 @@
---
# Test building the code and docker image
kind: pipeline
type: docker
name: test-build
steps:
- name: go-test
image: golang
commands:
- make -C polyculeconnect test
depends_on:
- name: go-build
image: golang
commands:
- make -C polyculeconnect build
depends_on:
- name: docker-build-only
image: thegeeklab/drone-docker-buildx
privileged: true
settings:
repo: git.faercol.me/polyculeconnect/polyculeconnect
tags: latest
dry_run: true
platforms:
- linux/amd64
# - linux/arm64
depends_on:
when:
branch:
exclude:
- main
- name: docker-build-push
image: thegeeklab/drone-docker-buildx
privileged: true
settings:
repo: git.faercol.me/polyculeconnect/polyculeconnect
registry: git.faercol.me
tags: latest
username:
from_secret: GIT_USERNAME
password:
from_secret: GIT_PASSWORD
platforms:
- linux/amd64
# - linux/arm64
depends_on:
- go-test
- go-build
when:
branch:
- main
trigger:
event:
- push
- tag
---
# On a tag, only build the related docker image
kind: pipeline
type: docker
name: tag-release
depends_on:
- test-build
steps:
- name: docker-push-tag
image: thegeeklab/drone-docker-buildx
privileged: true
settings:
registry: git.faercol.me
repo: git.faercol.me/polyculeconnect/polyculeconnect
auto_tag: true
platforms:
- linux/amd64
# - linux/arm64
username:
from_secret: GIT_USERNAME
password:
from_secret: GIT_PASSWORD
trigger:
event:
- tag

View file

@ -40,18 +40,11 @@ const (
ModeNet
)
type BackendConfigType string
const (
Memory BackendConfigType = "memory"
SQLite BackendConfigType = "sqlite"
)
type BackendConfig struct {
Config *oidc.Config `json:"config"`
Name string `json:"name"`
ID string `json:"ID"`
Type BackendConfigType `json:"type"`
Type string `json:"type"`
Local bool `json:"local"`
}
@ -61,7 +54,7 @@ type OpenConnectConfig struct {
Issuer string `json:"issuer"`
}
type StorageConfig struct {
type StorageConfigConfig struct {
File string `json:"file"`
Host string `json:"host"`
Port int `json:"port"`
@ -86,7 +79,7 @@ type jsonConf struct {
} `json:"server"`
Storage struct {
StorageType string `json:"type"`
Config *StorageConfig `json:"config"`
StorageConfig *StorageConfigConfig `json:"config"`
} `json:"storage"`
OpenConnectConfig *OpenConnectConfig `json:"openconnect"`
}
@ -98,7 +91,7 @@ type AppConfig struct {
Port int
SockPath string
StorageType string
StorageConfig *StorageConfig
StorageConfig *StorageConfigConfig
OpenConnectConfig *OpenConnectConfig
}
@ -129,7 +122,7 @@ func (ac *AppConfig) UnmarshalJSON(data []byte) error {
ac.Port = jsonConf.Server.Port
ac.OpenConnectConfig = jsonConf.OpenConnectConfig
ac.StorageType = jsonConf.Storage.StorageType
ac.StorageConfig = jsonConf.Storage.Config
ac.StorageConfig = jsonConf.Storage.StorageConfig
return nil
}

View file

@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
"os/signal"
"time"
@ -36,26 +35,6 @@ func parseArgs() *cliArgs {
}
}
func initStorage(conf *config.AppConfig) (storage.Storage, error) {
var storageType storage.Storage
var err error
switch conf.StorageType {
case "memory":
storageType = memory.New(logger.L)
case "sqlite":
sqlconfig := sql.SQLite3{
File: conf.StorageConfig.File,
}
storageType, err = sqlconfig.Open(logger.L)
if err != nil {
logger.L.Fatalf("Failed to initialize sqlite backend: %s", err.Error())
}
default:
return storageType, fmt.Errorf("unsupported storage backend type: %s", conf.StorageType)
}
return storageType, nil
}
func main() {
args := parseArgs()
@ -69,11 +48,24 @@ func main() {
logger.Init(conf.LogLevel)
logger.L.Infof("Initialized logger with level %v", conf.LogLevel)
storageType, err := initStorage(conf)
if err != nil {
logger.L.Fatalf("Failed to initialize storage backend: %s", err.Error())
var storageType storage.Storage
switch conf.StorageType {
case "memory":
storageType = memory.New(logger.L)
case "sqlite":
sqlconfig := sql.SQLite3{
File: conf.StorageConfig.File,
}
logger.L.Infof("Initialized storage backend %q", conf.StorageType)
storageType, err = sqlconfig.Open(logger.L)
if err != nil {
logger.L.Fatalf("Failed to initialize sqlite backend: %s", err.Error())
}
default:
logger.L.Fatalf("Unsupported storage backend type: %s", conf.StorageType)
}
logger.L.Infof("Initialized storage backend \"%s\"", conf.StorageType)
dexConf := dex_server.Config{
Web: dex_server.WebConfig{
Dir: "./",
@ -109,7 +101,7 @@ func main() {
if err := dexConf.Storage.CreateConnector(storage.Connector{
ID: backend.ID,
Name: backend.Name,
Type: string(backend.Type),
Type: backend.Type,
Config: backendConfJson,
}); err != nil {
logger.L.Errorf("Failed to add connector for backend %q to stage: %s", backend.Name, err.Error())