Skip to content
Snippets Groups Projects
Commit 0a032811 authored by Viktor Popov's avatar Viktor Popov
Browse files

Initial commit

parent 8dc41770
No related branches found
No related tags found
1 merge request!43130-implement-etcd-configuration-use
This commit is part of merge request !43. Comments created here will be created in the context of that merge request.
......@@ -8,6 +8,8 @@ ENV GOPATH /srv/
ENV SERVER_OUT "bin/server"
ENV SERVER_PKG_BUILD ${PKG}
ENV PATH "$PATH:/srv/bin/"
ARG CI_JOB_TOKEN
ARG CI_PROJECT_NAME
ARG CI_COMMIT_REF_NAME
......@@ -24,6 +26,8 @@ RUN cd /srv/src/code.vereign.com/code/$CI_PROJECT_NAME && \
git config --global credential.helper "store --file /tmp/store" && \
echo https://gitlab-ci-token:$CI_JOB_TOKEN@code.vereign.com > /tmp/store && cat /tmp/store && \
export PKG=code.vereign.com/code/$CI_PROJECT_NAME && \
go get -u github.com/ugorji/go/codec/codecgen && \
echo PATH $PATH && \
make && rm /tmp/store
#FROM debian:stretch
......
......@@ -11,6 +11,7 @@ all: server
dep: ## Get the dependencies
dep ensure
server: dep ## Build the binary file for server
go generate vendor/github.com/coreos/etcd/client/keys.go
@go build -ldflags="-X code.vereign.com/code/key-storage-agent/handler.version=$(VER)" -i -v -o $(SERVER_OUT) $(SERVER_PKG_BUILD)
clean: ## Remove previous builds
......
......@@ -2,11 +2,16 @@ package config
import (
"log"
"os"
"path/filepath"
"strings"
"code.vereign.com/code/viam-apis/authentication"
"github.com/spf13/viper"
)
import _ "github.com/spf13/viper/remote"
var SystemAuth = &authentication.Authentication{
Uuid: "undefined",
Session: "undefined",
......@@ -27,7 +32,7 @@ var RestListenAddress string
var DataStorageUrl string
var CertDir string
func SetConfigValues() {
func SetConfigValues(configFile, etcdURL string) {
// Set Default Values For Config Variables
// Vereign API Related
......@@ -66,10 +71,22 @@ func SetConfigValues() {
*/
// Read Config File
viper.SetConfigName("config")
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
log.Printf("can't read config: %s, will use default values", err)
if configFile != "" {
configName := strings.Split(filepath.Base(configFile), ".")[0]
configDir := filepath.Dir(configFile)
viper.SetConfigName(configName)
viper.AddConfigPath(configDir)
if err := viper.ReadInConfig(); err != nil {
log.Printf("can't read config: %v, will use default values", err)
}
} else {
log.Printf("requesting config at "+etcdURL, "/"+os.Getenv("ENV_NAME")+"/"+os.Getenv("CI_PROJECT_NAME")+".json")
viper.AddRemoteProvider("etcd", etcdURL, "/"+os.Getenv("ENV_NAME")+"/"+os.Getenv("CI_PROJECT_NAME")+".json")
viper.SetConfigType("json")
if err := viper.ReadRemoteConfig(); err != nil {
log.Printf("can't read config: %v, will use default values", err)
}
}
CertificationMethod = viper.GetString("certificationMethod")
......
......@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"flag"
"log"
"code.vereign.com/code/key-storage-agent/config"
......@@ -26,7 +27,16 @@ import (
// main start a gRPC server and waits for connection
func main() {
config.SetConfigValues()
configFile := flag.String("config-file", "", "path to configuration file")
etcdURL := flag.String("etcd-url", "", "etcd URL")
flag.Parse()
if *configFile == "" && *etcdURL == "" {
log.Fatalln("Config file path or etcd URL not specified")
return
}
config.SetConfigValues(*configFile, *etcdURL)
grpcAddress := config.GrpcListenAddress
restAddress := config.RestListenAddress
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment