0
0
mirror of https://github.com/thegeeklab/wp-gitea-release.git synced 2024-11-28 08:20:34 +00:00

Add insecure https support (#4)

This commit is contained in:
Lunny Xiao 2018-03-28 09:55:21 +08:00 committed by Bo-Yi Wu
parent 180dadcd0e
commit 1a7e5488a0
2 changed files with 24 additions and 2 deletions

View File

@ -47,6 +47,11 @@ func main() {
Usage: "create a draft release", Usage: "create a draft release",
EnvVar: "PLUGIN_DRAFT,GITEA_RELEASE_DRAFT", EnvVar: "PLUGIN_DRAFT,GITEA_RELEASE_DRAFT",
}, },
cli.BoolFlag{
Name: "insecure",
Usage: "visit base-url via insecure https protocol",
EnvVar: "PLUGIN_INSECURE,GITEA_RELEASE_INSECURE",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "prerelease", Name: "prerelease",
Usage: "set the release as prerelease", Usage: "set the release as prerelease",
@ -126,6 +131,7 @@ func run(c *cli.Context) error {
Draft: c.Bool("draft"), Draft: c.Bool("draft"),
PreRelease: c.Bool("prerelease"), PreRelease: c.Bool("prerelease"),
BaseURL: c.String("base-url"), BaseURL: c.String("base-url"),
Insecure: c.Bool("insecure"),
Title: c.String("title"), Title: c.String("title"),
Note: c.String("note"), Note: c.String("note"),
}, },

View File

@ -1,13 +1,16 @@
package main package main
import ( import (
"crypto/tls"
"fmt" "fmt"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
"io/ioutil"
"os"
) )
type ( type (
@ -31,6 +34,7 @@ type (
Checksum []string Checksum []string
Draft bool Draft bool
PreRelease bool PreRelease bool
Insecure bool
BaseURL string BaseURL string
Title string Title string
Note string Note string
@ -108,6 +112,18 @@ func (p Plugin) Exec() error {
client := gitea.NewClient(p.Config.BaseURL, p.Config.APIKey) client := gitea.NewClient(p.Config.BaseURL, p.Config.APIKey)
if p.Config.Insecure {
cookieJar, _ := cookiejar.New(nil)
var insecureClient = &http.Client{
Jar: cookieJar,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
client.SetHTTPClient(insecureClient)
}
rc := releaseClient{ rc := releaseClient{
Client: client, Client: client,
Owner: p.Repo.Owner, Owner: p.Repo.Owner,