-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding config, cert and util functions #12
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at config yet, but the rest is great, thanks. Just a few hopefully trivial changes.
args = append(args, "fatal", true) | ||
logger(ctx).Crit(msg, args...) | ||
|
||
if os.Getenv("FATAL_EXIT_TEST") == "1" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to see this envar prefixed with 'WR_' to make it unique to us.
@@ -1,7 +1,7 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2020 Genome Research Ltd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update Copyright in all changed files to 2020, 2021
// GenerateCerts creates a CA certificate which is used to sign a created server | ||
// certificate which will have a corresponding key, all saved as PEM files. An | ||
// error is generated if any of the files already exist. | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not obvious what all the args for this method are. Would be good to explain them all in the docs here, with examples.
// generateCertificates generates root and server certificates. | ||
func generateCertificates(caFile, domain string, rootKey *rsa.PrivateKey, serverKey *rsa.PrivateKey, | ||
serverPemFile string, randReader io.Reader, fileFlags int) error { | ||
// create templates for root and server certificates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for these comments, the code is clear
// certTemplate creates a certificate template with a random serial number, | ||
// valid from now until validFor. It will be valid for supplied domain. | ||
func certTemplate(domain string, randReader io.Reader) (*x509.Certificate, error) { | ||
serialNumLimit := new(big.Int).Lsh(big.NewInt(1), 128) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it is a constant? Maybe make it a package var?
// parseCertAndSavePEM parses the certificate to reuse it and saves it in PEM | ||
// format to certPath. | ||
func parseCertAndSavePEM(certByte []byte, certPath string, flags int) (*x509.Certificate, error) { | ||
// parse the resulting certificate so we can use it again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for comment
// CA. | ||
func generateServerCert(serverPemFile string, rootCert *x509.Certificate, template *x509.Certificate, | ||
rootKey *rsa.PrivateKey, serverKey *rsa.PrivateKey, randReader io.Reader, fileFlags int) error { | ||
// generate server cert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for comment
|
||
func TestCertFuncs(t *testing.T) { | ||
Convey("Given the certificates key file paths", t, func() { | ||
certtmpdir, err1 := ioutil.TempDir("/tmp", "wr_jobqueue_cert_dir_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't explicitly say "/tmp", and switch to using a filepath method?
* IN THE SOFTWARE. | ||
******************************************************************************/ | ||
|
||
package internal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't have a 'utils' file or package. Split these methods out in to appropriate dedicated non-internal packages where appropriate, or to dedicated files in internal package if they're really internal use only and not generally able code.
// PathToContent takes the path to a file and returns its contents as a string. | ||
// If path begins with a tilda, TildaToHome() is used to first convert the path | ||
// to an absolute path, in order to find the file. | ||
func PathToContent(path string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These path and file related methods seem to belong in the filepath package or similar.
No description provided.