Add cli tool.
This commit is contained in:
parent
754fca8cb8
commit
3b4e33ece0
@ -8,10 +8,11 @@ RUN mkdir -p /rootfs/usr/bin && \
|
|||||||
go get -u github.com/golang/dep/cmd/dep && \
|
go get -u github.com/golang/dep/cmd/dep && \
|
||||||
dep ensure && \
|
dep ensure && \
|
||||||
go build -o /rootfs/usr/bin/server . && \
|
go build -o /rootfs/usr/bin/server . && \
|
||||||
go build -o /rootfs/usr/bin/worker ./worker
|
go build -o /rootfs/usr/bin/worker ./worker && \
|
||||||
|
go build -o /rootfs/usr/bin/ar-cli ./cli
|
||||||
|
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
COPY --from=build /rootfs/usr/bin /usr/bin
|
COPY --from=build /rootfs/usr/bin /usr/bin
|
||||||
RUN chmod +x /usr/bin/server /usr/bin/worker && \
|
RUN chmod +x /usr/bin/server /usr/bin/worker /usr/bin/ar-cli && \
|
||||||
apk add -U --no-cache ca-certificates
|
apk add -U --no-cache ca-certificates
|
||||||
|
9
Gopkg.lock
generated
9
Gopkg.lock
generated
@ -227,6 +227,14 @@
|
|||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "70e15c650864f4fc47f5d3c82ea117285480895d"
|
revision = "70e15c650864f4fc47f5d3c82ea117285480895d"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:b24d38b282bacf9791408a080f606370efa3d364e4b5fd9ba0f7b87786d3b679"
|
||||||
|
name = "github.com/urfave/cli"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
|
||||||
|
version = "v1.20.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:bb78bf98bee383e091714423f2363a9a3b31a62e9ebbd887cb4f94e693d4890d"
|
digest = "1:bb78bf98bee383e091714423f2363a9a3b31a62e9ebbd887cb4f94e693d4890d"
|
||||||
name = "github.com/yukimochi/httpsig"
|
name = "github.com/yukimochi/httpsig"
|
||||||
@ -469,6 +477,7 @@
|
|||||||
"github.com/Songmu/go-httpdate",
|
"github.com/Songmu/go-httpdate",
|
||||||
"github.com/go-redis/redis",
|
"github.com/go-redis/redis",
|
||||||
"github.com/satori/go.uuid",
|
"github.com/satori/go.uuid",
|
||||||
|
"github.com/urfave/cli",
|
||||||
"github.com/yukimochi/httpsig",
|
"github.com/yukimochi/httpsig",
|
||||||
]
|
]
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
|
127
cli/cli.go
Normal file
127
cli/cli.go
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-redis/redis"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var redClient *redis.Client
|
||||||
|
|
||||||
|
func listDomain(c *cli.Context) error {
|
||||||
|
var err error
|
||||||
|
var domains []string
|
||||||
|
var message string
|
||||||
|
switch c.String("type") {
|
||||||
|
case "limited":
|
||||||
|
message = " - Limited domain :"
|
||||||
|
domains, err = redClient.HKeys("relay:config:limitedDomain").Result()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case "blocked":
|
||||||
|
message = " - Blocked domain :"
|
||||||
|
domains, err = redClient.HKeys("relay:config:blockedDomain").Result()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
message = " - Subscribed domain :"
|
||||||
|
temp, err := redClient.Keys("relay:subscription:*").Result()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, domain := range temp {
|
||||||
|
domains = append(domains, strings.Replace(domain, "relay:subscription:", "", 1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println(message)
|
||||||
|
for _, domain := range domains {
|
||||||
|
fmt.Println(domain)
|
||||||
|
}
|
||||||
|
fmt.Println(fmt.Sprintf("Total : %d", len(domains)))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func manageDomain(c *cli.Context) error {
|
||||||
|
if c.String("domain") == "" {
|
||||||
|
fmt.Println("No domain given.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
switch c.String("type") {
|
||||||
|
case "limited":
|
||||||
|
if c.Bool("undo") {
|
||||||
|
redClient.HDel("relay:config:limitedDomain", c.String("domain"))
|
||||||
|
fmt.Println("Unregistrate [" + c.String("domain") + "] from Limited domain.")
|
||||||
|
} else {
|
||||||
|
redClient.HSet("relay:config:limitedDomain", c.String("domain"), "1")
|
||||||
|
fmt.Println("Registrate [" + c.String("domain") + "] as Limited domain.")
|
||||||
|
}
|
||||||
|
case "blocked":
|
||||||
|
if c.Bool("undo") {
|
||||||
|
redClient.HDel("relay:config:blockedDomain", c.String("domain"))
|
||||||
|
fmt.Println("Unregistrate [" + c.String("domain") + "] from Blocked domain.")
|
||||||
|
} else {
|
||||||
|
redClient.HSet("relay:config:blockedDomain", c.String("domain"), "1")
|
||||||
|
fmt.Println("Registrate [" + c.String("domain") + "] as Blocked domain.")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
fmt.Println("No type given.")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
redClient = redis.NewClient(&redis.Options{
|
||||||
|
Addr: os.Getenv("REDIS_URL"),
|
||||||
|
})
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "Activity Relay Extarnal CLI"
|
||||||
|
app.Usage = "Control Relay configration"
|
||||||
|
app.Version = "0.0.2"
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "list-domain",
|
||||||
|
Aliases: []string{"ld"},
|
||||||
|
Usage: "List {subscribed,limited,blocked} domains",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "type, t",
|
||||||
|
Value: "subscribed",
|
||||||
|
Usage: "Registrate type [subscribed,limited,blocked]",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: listDomain,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "manage-domain",
|
||||||
|
Aliases: []string{"md"},
|
||||||
|
Usage: "Manage {limited,blocked} domains",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "type, t",
|
||||||
|
Usage: "Registrate type [limited,blocked]",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "domain, d",
|
||||||
|
Usage: "Registrate domain",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "undo, u",
|
||||||
|
Usage: "Undo registrate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: manageDomain,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user