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

minor

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