Merged together app SDKs

This commit is contained in:
frikky
2021-07-01 13:37:56 +02:00
parent ea83fa389d
commit bc5151bd88
23 changed files with 73 additions and 3481 deletions
+4 -80
View File
@@ -7,7 +7,6 @@ import (
"bytes"
"context"
"crypto/md5"
"crypto/tls"
//"crypto/x509"
"encoding/hex"
"encoding/json"
@@ -31,7 +30,7 @@ import (
"cloud.google.com/go/storage"
"google.golang.org/appengine/mail"
"github.com/elastic/go-elasticsearch/v8"
//"github.com/elastic/go-elasticsearch/v7"
//"github.com/elastic/go-elasticsearch/v8/esapi"
"github.com/frikky/kin-openapi/openapi2"
@@ -4081,6 +4080,7 @@ func runInitEs(ctx context.Context) {
}
// Getting apps to see if we should initialize a test
// FIXME: Isn't this a little backwards?
workflowapps, err := shuffle.GetAllWorkflowApps(ctx, 1000)
log.Printf("[INFO] Getting and validating workflowapps. Got %d with err %#v", len(workflowapps), err)
if err != nil && len(workflowapps) == 0 {
@@ -5304,7 +5304,7 @@ func migrateDatabase(resp http.ResponseWriter, request *http.Request) {
}
ctx := context.Background()
es := getEsConfig()
es := shuffle.GetEsConfig()
_, err := shuffle.RunInit(*dbclient, *es, storage.Client{}, gceProject, "onprem", false, "")
if err != nil {
log.Printf("[WARNING] Failed to start migration because of init issues: %s", err)
@@ -5657,82 +5657,6 @@ func makeWorkflowPublic(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(fmt.Sprintf(`{"success": true}`)))
}
func getEsConfig() *elasticsearch.Client {
esUrl := os.Getenv("SHUFFLE_OPENSEARCH_URL")
if len(esUrl) == 0 {
esUrl = "http://shuffle-opensearch:9200"
}
// https://github.com/elastic/go-elasticsearch/blob/f741c073f324c15d3d401d945ee05b0c410bd06d/elasticsearch.go#L98
config := elasticsearch.Config{
Addresses: []string{esUrl},
Username: os.Getenv("SHUFFLE_OPENSEARCH_USERNAME"),
Password: os.Getenv("SHUFFLE_OPENSEARCH_PASSWORD"),
APIKey: os.Getenv("SHUFFLE_OPENSEARCH_APIKEY"),
CloudID: os.Getenv("SHUFFLE_OPENSEARCH_CLOUDID"),
}
//config.Transport.TLSClientConfig
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.MaxIdleConnsPerHost = 100
transport.ResponseHeaderTimeout = time.Second * 10
transport.Proxy = nil
if len(os.Getenv("SHUFFLE_OPENSEARCH_PROXY")) > 0 {
httpProxy := os.Getenv("SHUFFLE_OPENSEARCH_PROXY")
url_i := url.URL{}
url_proxy, err := url_i.Parse(httpProxy)
if err == nil {
log.Printf("[DEBUG] Setting Opensearch proxy to %s", httpProxy)
transport.Proxy = http.ProxyURL(url_proxy)
} else {
log.Printf("[ERROR] Failed setting proxy for %s", httpProxy)
}
}
skipSSLVerify := false
if strings.ToLower(os.Getenv("SHUFFLE_OPENSEARCH_SKIPSSL_VERIFY")) == "true" {
log.Printf("[DEBUG] SKIPPING SSL verification with Opensearch")
skipSSLVerify = true
}
transport.TLSClientConfig = &tls.Config{
MinVersion: tls.VersionTLS11,
InsecureSkipVerify: skipSSLVerify,
}
//https://github.com/elastic/go-elasticsearch/blob/master/_examples/security/elasticsearch-cluster.yml
certificateLocation := os.Getenv("SHUFFLE_OPENSEARCH_CERTIFICATE_FILE")
if len(certificateLocation) > 0 {
cert, err := ioutil.ReadFile(certificateLocation)
if err != nil {
log.Fatalf("[WARNING] Failed configuring certificates: %s not found", err)
} else {
config.CACert = cert
//if transport.TLSClientConfig.RootCAs, err = x509.SystemCertPool(); err != nil {
// log.Fatalf("[ERROR] Problem adding system CA: %s", err)
//}
//// --> Add the custom certificate authority
//if ok := transport.TLSClientConfig.RootCAs.AppendCertsFromPEM(cert); !ok {
// log.Fatalf("[ERROR] Problem adding CA from file %q", *cert)
//}
}
log.Printf("[INFO] Added certificate %#v elastic client.", certificateLocation)
}
config.Transport = transport
es, err := elasticsearch.NewClient(config)
if err != nil {
log.Fatalf("[DEBUG] Database client for ELASTICSEARCH error during init (fatal): %s", err)
}
return es
}
func initHandlers() {
var err error
ctx := context.Background()
@@ -5744,7 +5668,7 @@ func initHandlers() {
log.Fatalf("[DEBUG] Database client error during init: %s", err)
}
es := getEsConfig()
es := shuffle.GetEsConfig()
elasticConfig := "elasticsearch"
if strings.ToLower(os.Getenv("SHUFFLE_ELASTIC")) == "false" {
elasticConfig = ""