Skip to content

Commit

Permalink
fix ca
Browse files Browse the repository at this point in the history
  • Loading branch information
x1ah committed May 18, 2021
1 parent 04fcf09 commit c5b2c39
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ RUN sed -i "s|//dl-cdn.alpinelinux.org|//${APK_REPO}|g" /etc/apk/repositories; \

WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build
RUN CGO_ENABLED=0 go build -o bin/feishu .

FROM scratch

WORKDIR /app
COPY --from=builder /app/actions-feishu /app/actions-feishu
COPY --from=builder /app/bin/feishu /app

ENTRYPOINT [ "/app/actions-feishu" ]
ENTRYPOINT [ "/app" ]
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/xiachufang/actions-feishu

go 1.14

require github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d h1:S2NE3iHSwP0XV47EEXL8mWmRdEfGscSJ+7EgePNgt0s=
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
21 changes: 20 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package main

import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"

"github.com/certifi/gocertifi"
)

// Message interface of message
Expand All @@ -32,7 +36,22 @@ func (webhook *WebHook) post(body interface{}) {
return
}

resp, err := http.Post(webhook.Address, "application/json", bytes.NewBuffer(buf))
var caCerts *x509.CertPool
if rootCAS, err := gocertifi.CACerts(); err == nil {
caCerts = rootCAS
} else {
setOutput("Couldn't load CA Certificates")
return
}

client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCerts,
},
},
}
resp, err := client.Post(webhook.Address, "application/json", bytes.NewBuffer(buf))
if resp != nil {
defer func() {
if err := resp.Body.Close(); err != nil {
Expand Down

0 comments on commit c5b2c39

Please sign in to comment.