Skip to content
Snippets Groups Projects
Unverified Commit da1afd96 authored by Max Adamo's avatar Max Adamo
Browse files

minor

parent 40128ee7
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
certPEM, err := ioutil.ReadFile(certificate)
if err != nil {
if fail == true {
fmt.Printf("[ERROR] %v\n", err)
fmt.Printf("[ERR] %v\n", err)
appExit(255)
} else {
return false
......@@ -59,7 +59,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
certFullchainPEM, err := ioutil.ReadFile(fullchain)
if err != nil {
if fail == true {
fmt.Printf("[ERROR] %v\n", err)
fmt.Printf("[ERR] %v\n", err)
appExit(255)
} else {
return false
......@@ -69,7 +69,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
rootPEM, err := ioutil.ReadFile(ca)
if err != nil {
if fail == true {
fmt.Printf("[ERROR] %v\n", err)
fmt.Printf("[ERR] %v\n", err)
appExit(255)
} else {
return false
......@@ -80,7 +80,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
ok := roots.AppendCertsFromPEM([]byte(rootPEM))
if !ok {
if fail == true {
fmt.Printf("[ERROR] failed to parse root certificate\n")
fmt.Printf("[ERR] failed to parse root certificate\n")
appExit(255)
} else {
return false
......@@ -90,7 +90,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
block, _ := pem.Decode([]byte(certPEM))
if block == nil {
if fail == true {
fmt.Printf("[ERROR] failed to parse certificate PEM\n")
fmt.Printf("[ERR] failed to parse certificate PEM\n")
appExit(255)
} else {
return false
......@@ -99,7 +99,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
if fail == true {
fmt.Printf("[ERROR] failed to parse certificate %v\n", err)
fmt.Printf("[ERR] failed to parse certificate %v\n", err)
appExit(255)
} else {
return false
......@@ -109,7 +109,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
fullchainBlock, _ := pem.Decode([]byte(certFullchainPEM))
if fullchainBlock == nil {
if fail == true {
fmt.Printf("[ERROR] failed to parse certificate PEM\n")
fmt.Printf("[ERR] failed to parse certificate PEM\n")
appExit(255)
} else {
return false
......@@ -118,7 +118,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
fullchainCert, fullchainErr := x509.ParseCertificate(fullchainBlock.Bytes)
if fullchainErr != nil {
if fail == true {
fmt.Printf("[ERROR] failed to parse certificate %v\n", fullchainErr)
fmt.Printf("[ERR] failed to parse certificate %v\n", fullchainErr)
appExit(255)
} else {
return false
......@@ -134,7 +134,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
if _, err := cert.Verify(opts); err != nil {
if fail == true {
fmt.Printf("[ERROR] failed to parse certificate %v\n", err.Error())
fmt.Printf("[ERR] failed to parse certificate %v\n", err.Error())
appExit(255)
} else {
return false
......@@ -142,7 +142,7 @@ func checkCerificates(dnsname string, certificate string, fullchain string, ca s
}
if _, fullchainErr := fullchainCert.Verify(opts); fullchainErr != nil {
if fail == true {
fmt.Printf("[ERROR] failed to parse certificate %v\n", err.Error())
fmt.Printf("[ERR] failed to parse certificate %v\n", err.Error())
} else {
return false
}
......@@ -156,19 +156,19 @@ func GetRedisKey(redisurl string, redistoken string) string {
client := &http.Client{}
req, err := http.NewRequest("GET", redisurl, nil)
if err != nil {
fmt.Printf("[ERROR] Fail to read %v: %v\n", redisurl, err)
fmt.Printf("[ERR] Fail to read %v: %v\n", redisurl, err)
appExit(255)
}
req.SetBasicAuth("redis", redistoken)
resp, err := client.Do(req)
body, err := ioutil.ReadAll(resp.Body)
if resp.StatusCode < 200 || resp.StatusCode > 299 {
fmt.Printf("[ERROR] Fail to fetch %v\n", redisurl)
fmt.Printf("[ERR] Fail to fetch %v\n", redisurl)
appExit(255)
}
defer resp.Body.Close()
if err != nil {
fmt.Printf("[ERROR] Fail to read %v: %v\n", redisurl, err)
fmt.Printf("[ERR] Fail to read %v: %v\n", redisurl, err)
appExit(255)
}
return fmt.Sprintf(string(body))
......@@ -179,19 +179,19 @@ func GetVaultKey(vaulturl string, vaulttoken string) string {
vaultClient := &http.Client{}
req, err := http.NewRequest("GET", vaulturl, nil)
if err != nil {
fmt.Printf("[ERROR] Fail to read %v: %v\n", vaulturl, err)
fmt.Printf("[ERR] Fail to read %v: %v\n", vaulturl, err)
appExit(255)
}
req.Header.Add("X-vault-token", vaulttoken)
resp, err := vaultClient.Do(req)
body, err := ioutil.ReadAll(resp.Body)
if resp.StatusCode < 200 || resp.StatusCode > 299 {
fmt.Printf("[ERROR] Fail to fetch %v\n", vaulturl)
fmt.Printf("[ERR] Fail to fetch %v\n", vaulturl)
appExit(255)
}
defer resp.Body.Close()
if err != nil {
fmt.Printf("[ERROR] Fail to read %v: %v\n", vaulturl, err)
fmt.Printf("[ERR] Fail to read %v: %v\n", vaulturl, err)
appExit(255)
}
return gjson.Get(string(body), "data.value").String()
......@@ -207,7 +207,7 @@ func WriteToFile(content string, destination string, groupname string, filemode
file, err := os.OpenFile(destination, os.O_WRONLY|os.O_CREATE, filemode)
if err != nil {
fmt.Printf("[ERROR] %v cannot be created\n", destination)
fmt.Printf("[ERR] %v cannot be created\n", destination)
appExit(255)
}
......@@ -291,7 +291,7 @@ Options:
DayString := arguments["--days"].(string)
Days, daysErr := strconv.Atoi(DayString)
if daysErr != nil {
fmt.Printf("Days mut be an integer\n")
fmt.Printf("[ERR] Days mut be an integer\n")
appExit(255)
}
RedisBaseURL = "https://redis.geant.org/GET"
......@@ -325,7 +325,7 @@ Options:
// check if there is a certificate installed and it is valid
existingCert := checkCerificates(CertName, certificateDestination, fullchainDestination, caDestination, keyDestination, Days, false)
if existingCert == true {
fmt.Printf("the certificates are still valid\n")
fmt.Printf("[INFO] the certificates are still valid\n")
appExit(0)
}
certificate := GetRedisKey(RedisCertURL, RedisToken)
......@@ -350,10 +350,10 @@ Options:
WriteToFile(ca, caDestination, GroupName, 0644, 0755)
WriteToFile(privKey, keyDestination, GroupName, 0640, 0750)
fmt.Printf("installed: %v\n", certificateDestination)
fmt.Printf("installed: %v\n", caDestination)
fmt.Printf("installed: %v\n", fullchainDestination)
fmt.Printf("installed: %v\n", keyDestination)
fmt.Printf("[INFO] installed: %v\n", certificateDestination)
fmt.Printf("[INFO] installed: %v\n", caDestination)
fmt.Printf("[INFO] installed: %v\n", fullchainDestination)
fmt.Printf("[INFO] installed: %v\n", keyDestination)
// Exit 1 means application needs to be reloaded
appExit(1)
......
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