Skip to content
Snippets Groups Projects
main.go 2.42 KiB
Newer Older
  • Learn to ignore specific revisions
  • Viktor Popov's avatar
    Viktor Popov committed
    /*
    Copyright (c) 2018 Vereign AG [https://www.vereign.com]
    
    This is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
    
    You should have received a copy of the GNU Affero General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    
    package main
    
    import (
    
    	"code.vereign.com/code/viam-apis/errors"
    
    Viktor Popov's avatar
    Viktor Popov committed
    	"flag"
    
    
    	"code.vereign.com/code/viam-apis/log"
    
    Viktor Popov's avatar
    Viktor Popov committed
    
    
    	"code.vereign.com/code/key-storage-agent/config"
    
    Viktor Popov's avatar
    Viktor Popov committed
    	"code.vereign.com/code/key-storage-agent/server"
    )
    
    // main start a gRPC server and waits for connection
    func main() {
    
    	//log.SetFlags(log.LstdFlags | log.Lshortfile)
    
    Viktor Popov's avatar
    Viktor Popov committed
    	configFile := flag.String("config-file", "", "path to configuration file")
    	etcdURL := flag.String("etcd-url", "", "etcd URL")
    	flag.Parse()
    
    	if *configFile == "" && *etcdURL == "" {
    
    Alisa Dinaburg's avatar
    Alisa Dinaburg committed
    		log.Fatal("Config file path or etcd URL not specified")
    
    Viktor Popov's avatar
    Viktor Popov committed
    		return
    	}
    
    
    	err := config.SetConfigValues(*configFile, *etcdURL)
    	if err != nil {
    		errors.LogFormat(err, "Can not set config values")
    		return
    	}
    
    
    	grpcAddress := config.GrpcListenAddress
    	restAddress := config.RestListenAddress
    	dataStorageAddress := config.DataStorageUrl
    	certPem := config.CertificatePEM
    	keyPem := config.PrivateKeyPEM
    	caCertPem := config.CaCertificatePEM
    	vereignCaCertificatePem := config.VereignCaCertificatePEM
    
    	maxMessageSize := config.MaxMessageSize
    
    	log.SetConfiguration(config.GlobalLogLevel)
    
    Viktor Popov's avatar
    Viktor Popov committed
    	// fire the gRPC server in a goroutine
    	go func() {
    
    		err := server.StartGRPCServer(grpcAddress, certPem, keyPem, caCertPem, vereignCaCertificatePem,
    
    			dataStorageAddress, maxMessageSize)
    
    Viktor Popov's avatar
    Viktor Popov committed
    		if err != nil {
    			log.Fatalf("failed to start gRPC server: %s", err)
    		}
    	}()
    
    	// fire the REST server in a goroutine
    	go func() {
    
    		err := server.StartRESTServer(restAddress, grpcAddress, certPem)
    
    Viktor Popov's avatar
    Viktor Popov committed
    		if err != nil {
    			log.Fatalf("failed to start gRPC server: %s", err)
    		}
    	}()
    
    
    Gospodin Bodurov's avatar
    Gospodin Bodurov committed
    	go func() {
    		err := server.StartPrometheusServer()
    		if err != nil {
    			log.Printf("failed to start prometheus server: %v", err)
    		}
    	}()
    
    
    Viktor Popov's avatar
    Viktor Popov committed
    	// infinite loop
    	log.Printf("Entering infinite loop")
    	select {}
    }