summaryrefslogtreecommitdiffstats
path: root/sms-service/src/quorumclient/quorumclient.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-04-06 16:45:23 -0700
committerGirish Havaldar <hg0071052@techmahindra.com>2018-04-11 04:04:16 +0000
commitc0830dc3d8ce9113fb29f9f81c7560b550b479ba (patch)
treeb375899c6a706959677ba5de1d4bea712c7fda9e /sms-service/src/quorumclient/quorumclient.go
parenta9e5943435ba1fb61fd891f1173f1b020858049f (diff)
Refactoring some code and adding disable_tls flag
Refactored some code and adding disable_tls flag This is needed for now to enable some end to end testing of quorum abilities and will be enabled once certificate support is added to ONAP Also updated test script to take port as argument Issue-ID: AAF-95 Change-Id: I4124bbfd22185a83b3c671b8a0499bfb3bde865d Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'sms-service/src/quorumclient/quorumclient.go')
-rw-r--r--sms-service/src/quorumclient/quorumclient.go46
1 files changed, 33 insertions, 13 deletions
diff --git a/sms-service/src/quorumclient/quorumclient.go b/sms-service/src/quorumclient/quorumclient.go
index 3f3c70b..e3e6e40 100644
--- a/sms-service/src/quorumclient/quorumclient.go
+++ b/sms-service/src/quorumclient/quorumclient.go
@@ -25,6 +25,8 @@ import (
"log"
"net/http"
"os"
+ smsauth "sms/auth"
+ smslogger "sms/log"
"strings"
"time"
)
@@ -33,6 +35,8 @@ import (
//calls necessary initialization endpoints on the
//SMS webservice
func main() {
+ smslogger.Init("quorumclient.log")
+
//Struct to read json configuration file
type config struct {
BackEndURL string `json:"url"`
@@ -41,7 +45,9 @@ func main() {
ClientKey string `json:"clientkey"`
B64Key string `json:"key"`
TimeOut string `json:"timeout"`
+ DisableTLS bool `json:"disable_tls"`
}
+
//Load the config File for reading
vcf, err := os.Open("config.json")
if err != nil {
@@ -55,32 +61,44 @@ func main() {
log.Fatalf("Error while parsing config file %v", err)
}
- duration, _ := time.ParseDuration(cfg.TimeOut)
- ticker := time.NewTicker(duration)
-
- for _ = range ticker.C {
+ transport := http.Transport{}
+ if cfg.DisableTLS {
+ // Read the CA cert. This can be the self-signed CA
+ // or CA cert provided by AAF
caCert, err := ioutil.ReadFile(cfg.CAFile)
if err != nil {
log.Fatalf("Error while reading CA file %v ", err)
}
+
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
+
+ // Load the client certificate files
cert, err := tls.LoadX509KeyPair(cfg.ClientCert, cfg.ClientKey)
if err != nil {
log.Fatalf("Error while loading key pair %v ", err)
}
- client := &http.Client{
- Transport: &http.Transport{
- TLSClientConfig: &tls.Config{
- RootCAs: caCertPool,
- Certificates: []tls.Certificate{cert},
- },
- },
+ transport.TLSClientConfig = &tls.Config{
+ RootCAs: caCertPool,
+ Certificates: []tls.Certificate{cert},
}
+ }
+
+ client := &http.Client{
+ Transport: &transport,
+ }
+
+ smsauth.GeneratePGPKeyPair()
+
+ duration, _ := time.ParseDuration(cfg.TimeOut)
+ ticker := time.NewTicker(duration)
+
+ for _ = range ticker.C {
+
//URL and Port is configured in config file
- response, err := client.Get(cfg.BackEndURL + "v1/sms/status")
+ response, err := client.Get(cfg.BackEndURL + "/v1/sms/status")
if err != nil {
log.Fatalf("Error while connecting to SMS webservice %v", err)
}
@@ -89,15 +107,17 @@ func main() {
if err != nil {
log.Fatalf("Error while reading response %v", err)
}
+
var data map[string]interface{}
json.Unmarshal(responseData, &data)
sealed := data["sealed"].(bool)
+
// Unseal the vault if sealed
if sealed {
decdB64Key, _ := base64.StdEncoding.DecodeString(cfg.B64Key)
body := strings.NewReader(`{"key":"` + string(decdB64Key) + `"}`)
//URL and PORT is configured via config file
- response, err = client.Post(cfg.BackEndURL+"v1/sms/unseal", "application/json", body)
+ response, err = client.Post(cfg.BackEndURL+"/v1/sms/unseal", "application/json", body)
if err != nil {
log.Fatalf("Error while unsealing %v", err)
}