Skip to content

Instantly share code, notes, and snippets.

@cahyowhy
Created April 19, 2021 06:21
Show Gist options
  • Save cahyowhy/a57350a507e5506f0f05b4b350023da0 to your computer and use it in GitHub Desktop.
Save cahyowhy/a57350a507e5506f0f05b4b350023da0 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"github.com/siuyin/dflt"
"github.com/xendit/xendit-provisioner/engr-onboard/evt"
)
var (
emailSlack string // Joined
groupSlack string // PerformanceReviewed
)
func init() {
eUsage := "Fill email"
flag.StringVar(&emailSlack, "Email", "", eUsage)
flag.StringVar(&emailSlack, "e", "", eUsage+" (shorthand)")
prUsage := "Fill private group slack"
flag.StringVar(&groupSlack, "PrivateGroup", "", prUsage)
flag.StringVar(&groupSlack, "g", "", prUsage+" (shorthand)")
}
func main() {
fmt.Println("authz-slack-pub: command-line authz check is-member pub")
if !parseCommandLineFlags() {
return
}
const subject = "authz.slack"
natsURL := dflt.EnvString("NATS_URL", "nats://localhost:4222")
p := evt.NewNATSPublisher(subject, natsURL)
defer p.Close()
param := make(map[string]string)
param["username"] = emailSlack
param["groupname"] = groupSlack
payload, err := json.Marshal(param)
if err != nil {
log.Fatal(err)
}
p.Publish(evt.AuthzSlackSvc, payload)
fmt.Println("test event sent")
}
func parseCommandLineFlags() bool {
flag.Parse()
if len(emailSlack) <= 0 || len(groupSlack) <= 0 {
fmt.Printf("\nUsage:\nPlease issue flag -e and -g\ntype %s --help for more info\n", os.Args[0])
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment