forked from hswaw/hscloud
DeveloperCredentialsLocation used to glog.Exitf instead of returning an error, and a consumer (prodaccess) used to not check the return code. Bad refactor? Change-Id: I6c2d05966ba6b3eb300c24a51584ccf5e324cd49
36 lines
737 B
Go
36 lines
737 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/golang/glog"
|
|
|
|
pb "code.hackerspace.pl/hscloud/cluster/prodvider/proto"
|
|
"code.hackerspace.pl/hscloud/go/pki"
|
|
)
|
|
|
|
func useHSPKIKeys(keys *pb.HSPKIKeys) {
|
|
path, err := pki.DeveloperCredentialsLocation()
|
|
if err != nil {
|
|
glog.Exitf("Could not get location of HSPKI creds: %v", err)
|
|
}
|
|
err = os.MkdirAll(path, 0700)
|
|
if err != nil {
|
|
glog.Exitf("mkdir %q: %v", path, err)
|
|
}
|
|
|
|
for _, el := range []struct {
|
|
target string
|
|
data []byte
|
|
}{
|
|
{path + "/ca.crt", keys.Ca},
|
|
{path + "/tls.crt", keys.Cert},
|
|
{path + "/tls.key", keys.Key},
|
|
} {
|
|
err := ioutil.WriteFile(el.target, el.data, 400)
|
|
if err != nil {
|
|
glog.Exitf("Failed to write %q: %v", el.target, err)
|
|
}
|
|
}
|
|
}
|