Skip to content

Commit

Permalink
Merge pull request #6 from kayac/raw-message
Browse files Browse the repository at this point in the history
Raw message
  • Loading branch information
fujiwara authored Mar 4, 2024
2 parents 24c6a0f + c1cf752 commit 9ed7919
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
28 changes: 21 additions & 7 deletions nopaste.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 != "" {
Expand Down

0 comments on commit 9ed7919

Please sign in to comment.