diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4ba6501..7271b81 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,13 +12,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: - go-version: 1.17 + go-version: "1.22" - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v1 + uses: goreleaser/goreleaser-action@v5 with: version: latest args: release --rm-dist diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc332af..c1c1419 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,19 +5,19 @@ jobs: strategy: matrix: go: - - 1.16 - - 1.17 + - "1.21" + - "1.22" name: Build runs-on: ubuntu-latest steps: - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} id: go - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Build & Test run: | diff --git a/nopaste.go b/nopaste.go index 6f24c4f..d7bad5f 100644 --- a/nopaste.go +++ b/nopaste.go @@ -174,11 +174,30 @@ func snsHandler(w http.ResponseWriter, req *http.Request, chs []MessageChan) { serverError(w, 400) return } + p := strings.Split(req.URL.Path, "/") + channel := p[len(p)-1] + if channel == "" { + serverError(w, 404) + return + } var n HttpNotification - dec := json.NewDecoder(req.Body) - dec.Decode(&n) + b, _ := io.ReadAll(req.Body) + if err := json.Unmarshal(b, &n); err != nil { + log.Println("[warn]", err) + } log.Println("[info] sns", n.Type, n.TopicArn, n.Subject) switch n.Type { + case "": + // raw message + np := nopasteContent{ + Text: string(b), + Summary: "Received raw message", + Notice: "", + Channel: "#" + channel, + IconEmoji: ":amazonsns:", + Nick: "AmazonSNS", + } + saveContent(np, chs) case "SubscriptionConfirmation", "Notification": if n.Type == "SubscriptionConfirmation" { region, _ := getRegionFromARN(n.TopicArn) @@ -193,11 +212,6 @@ func snsHandler(w http.ResponseWriter, req *http.Request, chs []MessageChan) { break } } - p := strings.Split(req.URL.Path, "/") - channel := p[len(p)-1] - if channel == "" { - break - } var out bytes.Buffer fmt.Fprintf(&out, "%s from %s\n", n.Type, n.TopicArn) if subscriptionArn := req.Header.Get("x-amz-sns-subscription-arn"); subscriptionArn != "" {