Skip to content
Snippets Groups Projects

HTTP endpoint for exporting policy evaluation results

Merged Lyuben Penkovski requested to merge 3-export-endpoint into main
All threads resolved!
10 files
+ 761
26
Compare changes
  • Side-by-side
  • Inline
Files
10
+ 57
16
@@ -4,16 +4,20 @@ import (
"context"
"errors"
"log"
"net"
"net/http"
"time"
"github.com/kelseyhightower/envconfig"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
"golang.org/x/sync/errgroup"
"code.vereign.com/gaiax/tsa/golib/cache"
"code.vereign.com/gaiax/tsa/golib/graceful"
goahealth "code.vereign.com/gaiax/tsa/infohub/gen/health"
goahealthsrv "code.vereign.com/gaiax/tsa/infohub/gen/http/health/server"
@@ -21,10 +25,14 @@ import (
goaopenapisrv "code.vereign.com/gaiax/tsa/infohub/gen/http/openapi/server"
goainfohub "code.vereign.com/gaiax/tsa/infohub/gen/infohub"
"code.vereign.com/gaiax/tsa/infohub/gen/openapi"
"code.vereign.com/gaiax/tsa/infohub/internal/clients/policy"
"code.vereign.com/gaiax/tsa/infohub/internal/clients/vault"
"code.vereign.com/gaiax/tsa/infohub/internal/config"
"code.vereign.com/gaiax/tsa/infohub/internal/credential"
"code.vereign.com/gaiax/tsa/infohub/internal/service"
"code.vereign.com/gaiax/tsa/infohub/internal/service/health"
"code.vereign.com/gaiax/tsa/infohub/internal/service/infohub"
"code.vereign.com/gaiax/tsa/infohub/internal/storage"
)
var Version = "0.0.0+development"
@@ -45,13 +53,46 @@ func main() {
logger.Info("infohub service started", zap.String("version", Version), zap.String("goa", goa.Version()))
// connect to mongo db
db, err := mongo.Connect(
context.Background(),
options.Client().ApplyURI(cfg.Mongo.Addr).SetAuth(options.Credential{
Username: cfg.Mongo.User,
Password: cfg.Mongo.Pass,
}),
)
if err != nil {
logger.Fatal("error connecting to mongodb", zap.Error(err))
}
defer db.Disconnect(context.Background()) //nolint:errcheck
// create storage
storage, err := storage.New(db, cfg.Mongo.DB, cfg.Mongo.Collection, logger)
if err != nil {
logger.Fatal("error connecting to database", zap.Error(err))
}
vault, err := vault.New(cfg.Vault.Addr, cfg.Vault.Token, cfg.Vault.Keyname)
if err != nil {
logger.Fatal("error creating vault client", zap.Error(err))
}
httpClient := httpClient()
credentials := credential.NewIssuer(cfg.Credential.IssuerName, cfg.Credential.Keyname, vault, httpClient)
// create policy client
policy := policy.New(cfg.Policy.Addr, httpClient)
// create cache client
cache := cache.New(cfg.Cache.Addr)
// create services
var (
infohubSvc goainfohub.Service
healthSvc goahealth.Service
)
{
infohubSvc = infohub.New(logger)
infohubSvc = infohub.New(storage, policy, cache, credentials, logger)
healthSvc = health.New()
}
@@ -145,18 +186,18 @@ func errFormatter(e error) goahttp.Statuser {
return service.NewErrorResponse(e)
}
//func httpClient() *http.Client {
// return &http.Client{
// Transport: &http.Transport{
// Proxy: http.ProxyFromEnvironment,
// DialContext: (&net.Dialer{
// Timeout: 30 * time.Second,
// }).DialContext,
// MaxIdleConns: 100,
// MaxIdleConnsPerHost: 100,
// TLSHandshakeTimeout: 10 * time.Second,
// IdleConnTimeout: 60 * time.Second,
// },
// Timeout: 30 * time.Second,
// }
//}
func httpClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
}).DialContext,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 100,
TLSHandshakeTimeout: 10 * time.Second,
IdleConnTimeout: 60 * time.Second,
},
Timeout: 30 * time.Second,
}
}
Loading