Skip to content

Commit

Permalink
Merge pull request #6 from tomdoherty/linting
Browse files Browse the repository at this point in the history
fix linting
  • Loading branch information
tomdoherty authored Sep 24, 2020
2 parents 0fa1735 + 814642a commit 6363c7e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 19 deletions.
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2010-2015 Illumina, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDi
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# gobblah

[![Go Report Card](https://goreportcard.com/badge/github.com/TomWright/dasel)](https://goreportcard.com/report/github.com/TomWright/dasel)

## Usage
```shell
NAME:
gobblah - Generate SSL certificates against Active Directory
Expand All @@ -18,3 +21,8 @@ GLOBAL OPTIONS:
--k8s-secret, -k output as a kubernetes secret (default: false)
--help, -h show help (default: false)
```

### Example
```shell
$ gobblah -e myad.example.com -p p4ssw0rd -l host1,host2 -k | kubectl apply -f -
```
30 changes: 15 additions & 15 deletions pkg/adssl/adssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ func getCaCert(endpoint string, username string, password string) (string, error
renewal = found[1]
}

crtUrl := "https://" + endpoint + "/certsrv/certnew.cer?ReqID=CACert&Enc=b64&Mode=inst&" + renewal
req, err = http.NewRequest("GET", crtUrl, nil)
crtURL := "https://" + endpoint + "/certsrv/certnew.cer?ReqID=CACert&Enc=b64&Mode=inst&" + renewal
req, err = http.NewRequest("GET", crtURL, nil)

if err != nil {
return "", fmt.Errorf("failed to request %s: %v", crtUrl, err)
return "", fmt.Errorf("failed to request %s: %v", crtURL, err)
}

req.SetBasicAuth(username, password)
resp, err = client.Do(req)
defer resp.Body.Close()

if err != nil {
return "", fmt.Errorf("failed to request %s: %v", crtUrl, err)
return "", fmt.Errorf("failed to request %s: %v", crtURL, err)
}

dataInBytes, err = ioutil.ReadAll(resp.Body)
Expand All @@ -125,7 +125,7 @@ func getCaCert(endpoint string, username string, password string) (string, error
}

func genCertRequest(csr string, endpoint string, username string, password string) (string, error) {
var resUrl string
var resURL string

data := url.Values{}
data.Set("Mode", "newreq")
Expand Down Expand Up @@ -168,25 +168,24 @@ func genCertRequest(csr string, endpoint string, username string, password strin
pageContent := string(dataInBytes)

re := regexp.MustCompile("certnew.cer\\?ReqID=([0-9]*)&Enc=b64")
reqId := re.FindString(string(pageContent))
reqID := re.FindString(string(pageContent))

if reqId == "" {
if reqID == "" {
return "", fmt.Errorf("failed to get new cert ReqID: %v", err)
} else {
resUrl = "https://" + endpoint + "/certsrv/" + reqId
}
return resUrl, nil
}
resURL = "https://" + endpoint + "/certsrv/" + reqID
return resURL, nil
}

func fetchCertResult(resUrl string, username string, password string) (string, error) {
func fetchCertResult(resURL string, username string, password string) (string, error) {
client := &http.Client{
Transport: ntlmssp.Negotiator{
RoundTripper: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
},
}
req, err := http.NewRequest("GET", resUrl, nil)
req, err := http.NewRequest("GET", resURL, nil)

if err != nil {
return "", fmt.Errorf("failed to fetch resulting cert: %v", err)
Expand All @@ -205,6 +204,7 @@ func fetchCertResult(resUrl string, username string, password string) (string, e
return string(dataInBytes), err
}

// CreateCertificates returns certs/keys as strings
func CreateCertificates(endpoint string, username string, password string, hosts string) (cacrt string, tlskey string, tlscert string, err error) {
var privateKey bytes.Buffer

Expand All @@ -231,13 +231,13 @@ func CreateCertificates(endpoint string, username string, password string, hosts
return "", "", "", fmt.Errorf("failed to generate csr: %v", err)
}

resUrl, err := genCertRequest(csr.String(), endpoint, username, password)
resURL, err := genCertRequest(csr.String(), endpoint, username, password)

if err != nil {
return "", "", "", fmt.Errorf("failed to generate csr: %v", err)
}

resCrt, err := fetchCertResult(resUrl, username, password)
resCrt, err := fetchCertResult(resURL, username, password)

if err != nil {
return "", "", "", fmt.Errorf("failed to fetch result: %v", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/output/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
)

// OutputFiles writes certs/keys to files
func OutputFiles(cacrt string, tlskey string, tlscrt string) error {
log.Println("writing ca.crt")
if err := ioutil.WriteFile("ca.crt", []byte(cacrt), 0600); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/output/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"text/template"
)

const secret = `
apiVersion: v1
const secret = `apiVersion: v1
kind: Secret
name: tls-secret
data:
Expand All @@ -17,6 +16,7 @@ data:
tls.crt: {{.Tlscrt}}
`

// OutputSecret prints kubernetes secret of certs/keys
func OutputSecret(cacrt string, tlskey string, tlscrt string) error {
t := template.Must(template.New("secret").Parse(secret))
r := struct {
Expand Down
5 changes: 3 additions & 2 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

golint \
./cmd/gobblah \
./pkg/gobblah
./cmd/* \
./pkg/output/* \
./pkg/*

0 comments on commit 6363c7e

Please sign in to comment.