Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.

Commit 519d75d

Browse files
authored
Merge e0ffe47 into ef7856b
2 parents ef7856b + e0ffe47 commit 519d75d

File tree

7 files changed

+470
-1
lines changed

7 files changed

+470
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ fabric.properties
6767
.idea/httpRequests
6868

6969
lodestone-fs-publisher-linux-amd64
70+
lodestone-email-publisher-linux-amd64
7071
vendor
72+
emailimap.go

Gopkg.lock

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@
4545
[[constraint]]
4646
branch = "master"
4747
name = "github.com/streadway/amqp"
48+
49+
[[constraint]]
50+
branch = "master"
51+
name = "github.com/emersion/go-imap"
52+
53+
[[constraint]]
54+
branch = "master"
55+
name = "github.com/emersion/go-message"

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ dep ensure
55
# go test -v ./...
66

77
go build -o lodestone-fs-publisher-linux-amd64 ./cmd/fs-publisher/fs-publisher.go
8+
go build -o lodestone-email-publisher-linux-amd64 ./cmd/email-publisher/email-publisher.go
89

910
./lodestone-fs-publisher-linux-amd64 --help
11+
./lodestone-email-publisher-linux-amd64 --help
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/analogj/go-util/utils"
6+
"github.com/analogj/lodestone-publisher/pkg/notify"
7+
"github.com/analogj/lodestone-publisher/pkg/version"
8+
"github.com/analogj/lodestone-publisher/pkg/watch"
9+
"github.com/fatih/color"
10+
"github.com/urfave/cli"
11+
"log"
12+
"os"
13+
"time"
14+
)
15+
16+
var goos string
17+
var goarch string
18+
19+
func main() {
20+
app := &cli.App{
21+
Name: "lodestone-email-publisher",
22+
Usage: "Email watcher & notifications for lodestone",
23+
Version: version.VERSION,
24+
Compiled: time.Now(),
25+
Authors: []cli.Author{
26+
cli.Author{
27+
Name: "Jason Kulatunga",
28+
29+
},
30+
},
31+
Before: func(c *cli.Context) error {
32+
33+
capsuleUrl := "AnalogJ/lodestone-publisher"
34+
35+
versionInfo := fmt.Sprintf("%s.%s-%s", goos, goarch, version.VERSION)
36+
37+
subtitle := capsuleUrl + utils.LeftPad2Len(versionInfo, " ", 53-len(capsuleUrl))
38+
39+
fmt.Fprintf(c.App.Writer, fmt.Sprintf(utils.StripIndent(
40+
`
41+
__ _____ ____ ____ ___ ____ _____ _ _ ____
42+
( ) ( _ )( _ \( ___)/ __)(_ _)( _ )( \( )( ___)
43+
)(__ )(_)( )(_) ))__) \__ \ )( )(_)( ) ( )__)
44+
(____)(_____)(____/(____)(___/ (__) (_____)(_)\_)(____)
45+
%s
46+
`), subtitle))
47+
return nil
48+
},
49+
50+
Commands: []cli.Command{
51+
{
52+
Name: "start",
53+
Usage: "Start the Lodestone email watcher",
54+
Action: func(c *cli.Context) error {
55+
56+
var notifyClient notify.Interface
57+
58+
notifyClient = new(notify.AmqpNotify)
59+
err := notifyClient.Init(map[string]string{
60+
"amqp-url": c.String("amqp-url"),
61+
"exchange": c.String("amqp-exchange"),
62+
"queue": c.String("amqp-queue"),
63+
})
64+
if err != nil {
65+
return err
66+
}
67+
defer notifyClient.Close()
68+
69+
watcher := watch.EmailWatcher{}
70+
watcher.Start(notifyClient, map[string]string{
71+
"imap-hostname": c.String("imap-hostname"),
72+
"imap-port": c.String("imap-port"),
73+
"imap-username": c.String("imap-username"),
74+
"imap-password": c.String("imap-password"),
75+
"imap-interval": c.String("imap-interval"),
76+
"bucket": c.String("bucket"),
77+
"api-endpoint": c.String("api-endpoint"),
78+
})
79+
return nil
80+
},
81+
82+
Flags: []cli.Flag{
83+
&cli.StringFlag{
84+
Name: "imap-hostname",
85+
Usage: "The imap server hostname",
86+
},
87+
&cli.StringFlag{
88+
Name: "imap-port",
89+
Usage: "The imap server port",
90+
Value: "993",
91+
},
92+
&cli.StringFlag{
93+
Name: "imap-username",
94+
Usage: "The imap server username",
95+
},
96+
&cli.StringFlag{
97+
Name: "imap-password",
98+
Usage: "The imap server password",
99+
},
100+
&cli.StringFlag{
101+
Name: "imap-interval",
102+
Usage: "The number of seconds to wait before checking for new messages",
103+
Value: "600", //10 minutes
104+
},
105+
106+
&cli.StringFlag{
107+
Name: "api-endpoint",
108+
Usage: "The api server endpoint",
109+
Value: "http://webapp:3000",
110+
},
111+
&cli.StringFlag{
112+
Name: "bucket",
113+
Usage: "The name of the bucket",
114+
},
115+
116+
&cli.StringFlag{
117+
Name: "amqp-url",
118+
Usage: "The amqp connection string",
119+
Value: "amqp://guest:guest@localhost:5672",
120+
},
121+
122+
&cli.StringFlag{
123+
Name: "amqp-exchange",
124+
Usage: "The amqp exchange",
125+
Value: "lodestone",
126+
},
127+
128+
&cli.StringFlag{
129+
Name: "amqp-queue",
130+
Usage: "The amqp queue",
131+
Value: "storagelogs",
132+
},
133+
},
134+
},
135+
},
136+
}
137+
138+
err := app.Run(os.Args)
139+
if err != nil {
140+
log.Fatal(color.HiRedString("ERROR: %v", err))
141+
}
142+
}

packagr.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
engine_enable_code_mutation: true
33

44
engine_cmd_compile:
5-
- 'GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-X main.goos=linux -X main.goarch=amd64 -extldflags \"-static\"" -o lodestone-fs-publisher-linux-amd64 $(go list ./cmd/...)'
5+
- 'GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-X main.goos=linux -X main.goarch=amd64 -extldflags \"-static\"" -o lodestone-fs-publisher-linux-amd64 $(go list ./cmd/fs-publisher/...)'
6+
- 'GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-X main.goos=linux -X main.goarch=amd64 -extldflags \"-static\"" -o lodestone-email-publisher-linux-amd64 $(go list ./cmd/email-publisher...)'
67
engine_cmd_test: 'go test -v ./...'
78
engine_disable_lint: true
89

@@ -12,3 +13,5 @@ scm_enable_branch_cleanup: true
1213
scm_release_assets:
1314
- local_path: lodestone-fs-publisher-linux-amd64
1415
artifact_name: lodestone-fs-publisher-linux-amd64
16+
- local_path: lodestone-email-publisher-linux-amd64
17+
artifact_name: lodestone-email-publisher-linux-amd64

0 commit comments

Comments
 (0)