Skip to content

Commit

Permalink
Merge pull request #20 from HilkopterBob/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
HilkopterBob authored Aug 15, 2024
2 parents 9f02d85 + 3332b0a commit 5c7f3a5
Show file tree
Hide file tree
Showing 20 changed files with 657 additions and 328 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build-docker-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: ci

on:
push:
branches: ["binary-release", "master", "devel"]

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: hilkopterbob/packagelock:latest
17 changes: 0 additions & 17 deletions .github/workflows/run-tests.yml

This file was deleted.

30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1

FROM golang:latest

# Set destination for COPY
WORKDIR /app

# Download Go modules

ADD . /app

RUN go mod download

# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/reference/dockerfile/#copy


# Build

RUN CGO_ENABLED=0 GOOS=linux go build -o /packagelock

# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
# But we can document in the Dockerfile what ports
# the application is going to listen on by default.
# https://docs.docker.com/reference/dockerfile/#expose
EXPOSE 8080

# Run
CMD ["/packagelock"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<h3 align="center">PackageLock</h3>

<p align="center">
Leaning Project!
PackageLock aims to be the distro-agnostic 🔋-included one-stop Solution for patchmanagement on linux systems.
<br />
<a href="https://github.com/HilkopterBob/PackageLock"><strong>Explore the docs (COMING SOON!) »</strong></a>
Expand Down Expand Up @@ -130,6 +131,15 @@ TODO: explain usage
- [ ] backend-api to manage Agents & Hosts
- [ ] frontend to visualize backend data
- [ ] installable agent as background daemon
- [ ] config management
- [ ] TLS Encryption
- [ ] Secured API
- [ ] Best Practice based Package Layout
- [ ] Check Vars and Func-Names for naming convention
- [ ] persistent storage
- [ ] implement interfaces for external functions for easier mocking in tests



TODO: create Issue template:
See the [open issues](https://github.com/HilkopterBob/PackageLock/issues) for a full list of proposed features (and known issues).
Expand Down
11 changes: 11 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
general:
debug: true
production: false
network:
forcehttp: true
fqdn: 0.0.0.0
port: 8080
ssl:
allowselfsigned: true
certificatepath: /etc/packagelock/ssl/cert.pem
privatekeypath: /etc/packagelock/ssl/privkey.pem
75 changes: 75 additions & 0 deletions config/conf-init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package config

import (
"bytes"
"fmt"
"io"

"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
)

type ConfigProvider interface {
SetConfigName(name string)
SetConfigType(fileext string)
AddConfigPath(path string)
ReadInConfig() error
OnConfigChange(run func(e fsnotify.Event))
WatchConfig()
WriteConfigAs(path string) error
ReadConfig(in io.Reader) error
AllSettings() map[string]any
GetString(string string) string
}

// TODO: How to test?
func StartViper(config ConfigProvider) ConfigProvider {
config.SetConfigName("config") // name of config file (without extension)
config.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
config.AddConfigPath("/etc/packagelock/") // path to look for the config file in etc/
config.AddConfigPath(".") // optionally look for config in the working directory

// if no config file found a default file will be Created
// than a rescan. new_config is the same as config, but needs a different name
// as it cont be argument return-store
// if there is a different error -> panic & exit
if err := config.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
CreateDefaultConfig(config)
new_config := StartViper(config)
return new_config
} else {
panic(fmt.Errorf("fatal error config file: %w", err))
}
}

return config
}

func CreateDefaultConfig(config ConfigProvider) {
// TODO: Add default config
yamlExample := []byte(`
general:
debug: True
production: False
Port: 8080
Network:
FQDN: "packagelock.company.com"
ForceHTTP: False
SSL:
CertificatePath: "/etc/packagelock/ssl/cert.pem"
PrivateKeyPath: "/etc/packagelock/ssl/privkey.pem"
AllowSelfSigned: False
`)

err := config.ReadConfig(bytes.NewBuffer(yamlExample))
if err != nil {
panic(fmt.Errorf("fatal error while reading config file: %w", err))
}

err_write := config.WriteConfigAs("./config.yaml")
if err_write != nil {
panic(fmt.Errorf("fatal error while writing config file: %w", err))
}
}
16 changes: 16 additions & 0 deletions config/conf-init_test.go.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package config


import ()


type MockConfigProvider interface {
SetConfigName func()
SetConfigType func()
AddConfigPath func()
ReadInConfig func()
OnConfigChange func()
WatchConfig func()
}


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

// This file is for declaration of viper defaults
3 changes: 3 additions & 0 deletions config/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package config

// This is a test file for config migrations.
143 changes: 143 additions & 0 deletions config/mockgen.go.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: config/conf-init.go
//
// Generated by this command:
//
// mockgen -source=config/conf-init.go
//

// Package mock_config is a generated GoMock package.
package mock_config

import (
io "io"
reflect "reflect"

fsnotify "github.com/fsnotify/fsnotify"
gomock "go.uber.org/mock/gomock"
)

// MockConfigProvider is a mock of ConfigProvider interface.
type MockConfigProvider struct {
ctrl *gomock.Controller
recorder *MockConfigProviderMockRecorder
}

// MockConfigProviderMockRecorder is the mock recorder for MockConfigProvider.
type MockConfigProviderMockRecorder struct {
mock *MockConfigProvider
}

// NewMockConfigProvider creates a new mock instance.
func NewMockConfigProvider(ctrl *gomock.Controller) *MockConfigProvider {
mock := &MockConfigProvider{ctrl: ctrl}
mock.recorder = &MockConfigProviderMockRecorder{mock}
return mock
}

// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockConfigProvider) EXPECT() *MockConfigProviderMockRecorder {
return m.recorder
}

// AddConfigPath mocks base method.
func (m *MockConfigProvider) AddConfigPath(path string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "AddConfigPath", path)
}

// AddConfigPath indicates an expected call of AddConfigPath.
func (mr *MockConfigProviderMockRecorder) AddConfigPath(path any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddConfigPath", reflect.TypeOf((*MockConfigProvider)(nil).AddConfigPath), path)
}

// OnConfigChange mocks base method.
func (m *MockConfigProvider) OnConfigChange(run func(fsnotify.Event)) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "OnConfigChange", run)
}

// OnConfigChange indicates an expected call of OnConfigChange.
func (mr *MockConfigProviderMockRecorder) OnConfigChange(run any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnConfigChange", reflect.TypeOf((*MockConfigProvider)(nil).OnConfigChange), run)
}

// ReadConfig mocks base method.
func (m *MockConfigProvider) ReadConfig(in io.Reader) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ReadConfig", in)
ret0, _ := ret[0].(error)
return ret0
}

// ReadConfig indicates an expected call of ReadConfig.
func (mr *MockConfigProviderMockRecorder) ReadConfig(in any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadConfig", reflect.TypeOf((*MockConfigProvider)(nil).ReadConfig), in)
}

// ReadInConfig mocks base method.
func (m *MockConfigProvider) ReadInConfig() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ReadInConfig")
ret0, _ := ret[0].(error)
return ret0
}

// ReadInConfig indicates an expected call of ReadInConfig.
func (mr *MockConfigProviderMockRecorder) ReadInConfig() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadInConfig", reflect.TypeOf((*MockConfigProvider)(nil).ReadInConfig))
}

// SetConfigName mocks base method.
func (m *MockConfigProvider) SetConfigName(name string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetConfigName", name)
}

// SetConfigName indicates an expected call of SetConfigName.
func (mr *MockConfigProviderMockRecorder) SetConfigName(name any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetConfigName", reflect.TypeOf((*MockConfigProvider)(nil).SetConfigName), name)
}

// SetConfigType mocks base method.
func (m *MockConfigProvider) SetConfigType(fileext string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetConfigType", fileext)
}

// SetConfigType indicates an expected call of SetConfigType.
func (mr *MockConfigProviderMockRecorder) SetConfigType(fileext any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetConfigType", reflect.TypeOf((*MockConfigProvider)(nil).SetConfigType), fileext)
}

// WatchConfig mocks base method.
func (m *MockConfigProvider) WatchConfig() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "WatchConfig")
}

// WatchConfig indicates an expected call of WatchConfig.
func (mr *MockConfigProviderMockRecorder) WatchConfig() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchConfig", reflect.TypeOf((*MockConfigProvider)(nil).WatchConfig))
}

// WriteConfigAs mocks base method.
func (m *MockConfigProvider) WriteConfigAs(path string) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "WriteConfigAs", path)
ret0, _ := ret[0].(error)
return ret0
}

// WriteConfigAs indicates an expected call of WriteConfigAs.
func (mr *MockConfigProviderMockRecorder) WriteConfigAs(path any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteConfigAs", reflect.TypeOf((*MockConfigProvider)(nil).WriteConfigAs), path)
}
Loading

0 comments on commit 5c7f3a5

Please sign in to comment.