Skip to content

Commit

Permalink
Fix bug in certtificate generate wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
la3lma committed May 29, 2019
1 parent f2878ee commit 31a885e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
30 changes: 20 additions & 10 deletions build-all.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,38 +137,48 @@ func isError(err error) bool {
func generateEspEndpointCertificates() {

originalCertPath := "certs/ocs.dev.ostelco.org/nginx.crt"
activeCertPath := "ocsgw/cert/metrics.crt"
activeCertPath := "ocsgw/cert/metrics.crt"

if bothFilesExistsButAreDifferent(originalCertPath, activeCertPath) {
deleteFile(originalCertPath)
deleteFile(activeCertPath)
}

// If no original certificate (for whatever reason), generate a new one.
// If no original certificate (for whatever reason),
// generate a new one.
if !fileExists(originalCertPath) {
generateNewCertificate(originalCertPath)
generateNewCertificate(originalCertPath, "ocs.dev.ostelco.org")
}

if !fileExists(activeCertPath) {
if fileExists(activeCertPath) {
copyFile(originalCertPath, activeCertPath)
}
}

// XXX This does not work.
func copyFile(src string, dest string) {
cp := fmt.Sprintf("cp %s %s", src, dest)
cpCmd := exec.Command("bash", "-c", cp)
err := cpCmd.Run()
_, err := exec.Command("bash", "-c", cp).Output()

if err != nil {
log.Fatalf("ERROR: Could not copy from '%s' to '%s'", src, dest)
os.Exit(1)
}
}

func generateNewCertificate(certificatePath string) {
cmd := fmt.Sprintf("scripts/generate-selfsigned-ssl-certs.sh %s", certificatePath)
_, err := exec.Command("bash", "-c", cmd).Output()
func generateNewCertificate(certificateFilename string, certificateDomain string) {
cmd := fmt.Sprintf("scripts/generate-selfsigned-ssl-certs.sh %s", certificateDomain)
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
log.Fatalf("ERROR: Could not generate certificate '%s'", certificatePath)
log.Fatalf("ERROR: Could not generate self signed certificate for domain '%s'.\n Reason: %s", certificateDomain, err)
os.Exit(1)
}

log.Printf("out = %s", out)


if !fileExists(certificateFilename) {
log.Fatalf("ERROR: Did not generate self signed for domain '%s'", certificateDomain)
os.Exit(1)
}
}
Expand Down
7 changes: 4 additions & 3 deletions scripts/generate-selfsigned-ssl-certs.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

# This script generates a slefsigned SSL certificate for a given input domain.
# This script generates a self SSL certificate for a given input domain.

#### input
DOMAIN_NAME=$1
####

#### sanity check
if [ -z "${DOMAIN_NAME}" ]; then
echo "ERROR: No domain-name was provided in input. Aborting!"
echo "ERROR: No domain-name was provided in input. Aborting!" > /dev/stderr
exit 1
fi
####
Expand All @@ -34,7 +34,8 @@ if [ -d ${CERTS_DIR} ]; then
ls -l ${CERTS_DIR}

else
echo "Could not find a matching domain name in certs for ${DOMAIN_NAME}"
echo "Could not find a matching domain name in certs for ${DOMAIN_NAME} in ${CERTS_DIR}" > /dev/stderr
exit 1
fi

popd

0 comments on commit 31a885e

Please sign in to comment.