mirror of
https://github.com/vbatts/sl-feeds.git
synced 2024-12-23 12:46:29 +00:00
Merge pull request #19 from vbatts/certs
sl-feeds: adding --insecure and --ca flags
This commit is contained in:
commit
e6f218314b
1 changed files with 34 additions and 0 deletions
|
@ -1,9 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
@ -33,6 +36,14 @@ func main() {
|
||||||
Name: "quiet, q",
|
Name: "quiet, q",
|
||||||
Usage: "Less output",
|
Usage: "Less output",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "insecure",
|
||||||
|
Usage: "do not validate server certificate",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "ca",
|
||||||
|
Usage: "additional CA cert to use",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "sample-config",
|
Name: "sample-config",
|
||||||
Usage: "Output sample config file to stdout",
|
Usage: "Output sample config file to stdout",
|
||||||
|
@ -41,6 +52,29 @@ func main() {
|
||||||
|
|
||||||
// This is the main/default application
|
// This is the main/default application
|
||||||
app.Action = func(c *cli.Context) error {
|
app.Action = func(c *cli.Context) error {
|
||||||
|
rootCAs, _ := x509.SystemCertPool()
|
||||||
|
if c.String("ca") != "" {
|
||||||
|
if rootCAs == nil {
|
||||||
|
rootCAs = x509.NewCertPool()
|
||||||
|
}
|
||||||
|
// Read in the cert file
|
||||||
|
certs, err := ioutil.ReadFile(c.String("ca"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to append %q to RootCAs: %v", c.String("ca"), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append our cert to the system pool
|
||||||
|
if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
|
||||||
|
log.Println("No certs appended, using system certs only")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c.Bool("insecure") {
|
||||||
|
config := &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
RootCAs: rootCAs,
|
||||||
|
}
|
||||||
|
http.DefaultTransport = &http.Transport{TLSClientConfig: config}
|
||||||
|
}
|
||||||
if c.Bool("sample-config") {
|
if c.Bool("sample-config") {
|
||||||
c := Config{
|
c := Config{
|
||||||
Dest: "$HOME/public_html/feeds/",
|
Dest: "$HOME/public_html/feeds/",
|
||||||
|
|
Loading…
Reference in a new issue