-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from HilkopterBob/devel
Devel
- Loading branch information
Showing
20 changed files
with
657 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package config | ||
|
||
// This file is for declaration of viper defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package config | ||
|
||
// This is a test file for config migrations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.