mirror of
https://github.com/kovetskiy/mark.git
synced 2025-12-13 04:07:36 +08:00
feature: Add --insecure flag for ignoring tls errors
This commit is contained in:
parent
be4ff0d58a
commit
b36d7aa135
@ -2,6 +2,7 @@ package confluence
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -97,7 +98,7 @@ func (tracer *tracer) Printf(format string, args ...interface{}) {
|
||||
log.Tracef(nil, tracer.prefix+" "+format, args...)
|
||||
}
|
||||
|
||||
func NewAPI(baseURL string, username string, password string) *API {
|
||||
func NewAPI(baseURL string, username string, password string, insecure bool) *API {
|
||||
var auth *gopencils.BasicAuth
|
||||
if username != "" {
|
||||
auth = &gopencils.BasicAuth{
|
||||
@ -105,7 +106,19 @@ func NewAPI(baseURL string, username string, password string) *API {
|
||||
Password: password,
|
||||
}
|
||||
}
|
||||
rest := gopencils.Api(baseURL+"/rest/api", auth, 3) // set option for 3 retries on failure
|
||||
|
||||
var httpClient *http.Client
|
||||
if insecure {
|
||||
httpClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
rest := gopencils.Api(baseURL+"/rest/api", auth, httpClient, 3) // set option for 3 retries on failure
|
||||
if username == "" {
|
||||
if rest.Headers == nil {
|
||||
rest.Headers = http.Header{}
|
||||
@ -113,7 +126,7 @@ func NewAPI(baseURL string, username string, password string) *API {
|
||||
rest.SetHeader("Authorization", fmt.Sprintf("Bearer %s", password))
|
||||
}
|
||||
|
||||
json := gopencils.Api(baseURL+"/rpc/json-rpc/confluenceservice-v2", auth, 3)
|
||||
json := gopencils.Api(baseURL+"/rpc/json-rpc/confluenceservice-v2", auth, httpClient, 3)
|
||||
|
||||
if log.GetLevel() == lorg.LevelTrace {
|
||||
rest.Logger = &tracer{"rest:"}
|
||||
|
||||
@ -49,7 +49,7 @@ func RunMark(ctx context.Context, cmd *cli.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
api := confluence.NewAPI(creds.BaseURL, creds.Username, creds.Password)
|
||||
api := confluence.NewAPI(creds.BaseURL, creds.Username, creds.Password, cmd.Bool("insecure"))
|
||||
|
||||
files, err := doublestar.FilepathGlob(cmd.String("files"))
|
||||
if err != nil {
|
||||
|
||||
@ -196,6 +196,12 @@ var Flags = []cli.Flag{
|
||||
Usage: "Enables optional features. Current features: d2, mermaid, mkdocsadmonitions",
|
||||
Sources: cli.NewValueSourceChain(cli.EnvVar("MARK_FEATURES"), altsrctoml.TOML("features", altsrc.NewStringPtrSourcer(&filename))),
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "insecure",
|
||||
Value: false,
|
||||
Usage: "skip TLS certificate verification (useful for self-signed certificates)",
|
||||
Sources: cli.NewValueSourceChain(cli.EnvVar("MARK_INSECURE"), altsrctoml.TOML("insecure", altsrc.NewStringPtrSourcer(&filename))),
|
||||
},
|
||||
}
|
||||
|
||||
// CheckMutuallyExclusiveTitleFlags checks if both title-from-h1 and title-from-filename are set
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user