Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/integration-test/test-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ gotify:
gotify_token: "${GOTIFY_APP_TOKEN}"
gotify_format: "{{data}}"
gotify_disabletls: true
jandi:
- id: "jandi-integration-test"
jandi_webhook_url: "${JANDI_WEBHOOK_URL}"
jandi_format: "{{data}}"
52 changes: 52 additions & 0 deletions pkg/providers/jandi/jandi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package jandi

import (
"github.com/oriser/regroup"
"github.com/pkg/errors"
"go.uber.org/multierr"

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/notify/pkg/utils"
sliceutil "github.com/projectdiscovery/utils/slice"
)

var reJandiWebhook = regroup.MustCompile(`(?P<scheme>https?):\/\/(?P<domain>(?:ptb\.|canary\.)?Jandi(?:app)?\.com)\/api(?:\/)?(?P<api_version>v\d{1,2})?\/webhooks\/(?P<webhook_identifier>\d{17,19})\/(?P<webhook_token>[\w\-]{68})`)

type Provider struct {
Jandi []*Options `yaml:"jandi,omitempty"`
counter int
}

type Options struct {
ID string `yaml:"id,omitempty"`
JandiWebHookURL string `yaml:"jandi_webhook_url,omitempty"`
JandiFormat string `yaml:"jandi_format,omitempty"`
}

func New(options []*Options, ids []string) (*Provider, error) {
provider := &Provider{}

for _, o := range options {
if len(ids) == 0 || sliceutil.Contains(ids, o.ID) {
provider.Jandi = append(provider.Jandi, o)
}
}

provider.counter = 0

return provider, nil
}
func (p *Provider) Send(message, CliFormat string) error {
var errs []error
for _, pr := range p.Jandi {
msg := utils.FormatMessage(message, utils.SelectFormat(CliFormat, pr.JandiFormat), p.counter)

if err := pr.SendMessage(msg); err != nil {
errs = append(errs, errors.Wrapf(err, "failed to send jandi notification for id: %s ", pr.ID))
continue
}

gologger.Verbose().Msgf("jandi notification sent for id: %s", pr.ID)
}
return multierr.Combine(errs...)
}
36 changes: 36 additions & 0 deletions pkg/providers/jandi/jandi_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package jandi

import (
"bytes"
"encoding/json"
"net/http"

"github.com/projectdiscovery/notify/pkg/utils/httpreq"
)

func (options *Options) SendMessage(message string) error {
payload := APIRequest{
Body: message,
}

encoded, err := json.Marshal(payload)
if err != nil {
return err
}

body := bytes.NewReader(encoded)
req, err := http.NewRequest(http.MethodPost, options.JandiWebHookURL, body)
if err != nil {
return err
}

req.Header.Set("Accept", "application/vnd.tosslab.jandi-v2+json")
req.Header.Set("Content-Type", "application/json")

_, err = httpreq.NewClient().Do(req)
if err != nil {
return err
}

return nil
}
11 changes: 11 additions & 0 deletions pkg/providers/jandi/jandi_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package jandi

type APIRequest struct {
Body string `json:"body"`
ConnectInfo []ConnectInfo `json:"connectInfo,omitempty"`
}

type ConnectInfo struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
}
11 changes: 11 additions & 0 deletions pkg/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/projectdiscovery/notify/pkg/providers/smtp"
"github.com/projectdiscovery/notify/pkg/providers/teams"
"github.com/projectdiscovery/notify/pkg/providers/telegram"
"github.com/projectdiscovery/notify/pkg/providers/jandi"
"github.com/projectdiscovery/notify/pkg/types"
sliceutil "github.com/projectdiscovery/utils/slice"
)
Expand All @@ -30,6 +31,7 @@ type ProviderOptions struct {
GoogleChat []*googlechat.Options `yaml:"googlechat,omitempty"`
Custom []*custom.Options `yaml:"custom,omitempty"`
Gotify []*gotify.Options `yaml:"gotify,omitempty"`
Jandi []*jandi.Options `yaml:"jandi,omitempty"`
}

// Provider is an interface implemented by providers
Expand Down Expand Up @@ -123,6 +125,15 @@ func New(providerOptions *ProviderOptions, options *types.Options) (*Client, err
client.providers = append(client.providers, provider)
}

if providerOptions.Jandi != nil && (len(options.Providers) == 0 || sliceutil.Contains(options.Providers, "jandi")) {

provider, err := jandi.New(providerOptions.Jandi, options.IDs)
if err != nil {
return nil, errors.Wrap(err, "could not create jandi provider client")
}
client.providers = append(client.providers, provider)
}

return client, nil
}

Expand Down