Skip to content

Commit

Permalink
Merge pull request #4 from containerum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MargoTuleninova authored Aug 7, 2018
2 parents 98f04d7 + e731e0b commit 208cdc9
Show file tree
Hide file tree
Showing 178 changed files with 3,078 additions and 4,900 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ ENV GIN_MODE=debug \
CH_USER_AUTH_HTTP_ADDR="http://ch-auth:1111/" \
CH_USER_PERMISSIONS="http" \
CH_USER_PERMISSIONS_URL="http://permissions:4242" \
CH_USER_TELEGRAM=false \
CH_USER_TELEGRAM_BOT_ID="" \
CH_USER_TELEGRAM_BOT_TOKEN="" \
CH_USER_TELEGRAM_BOT_CHAT_ID="" \
CH_USER_LISTEN_ADDR=":8111" \
CH_USER_USER_MANAGER="impl"
ENTRYPOINT ["/user-manager"]
65 changes: 25 additions & 40 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ required = ["git.containerum.net/ch/auth"]

[[constraint]]
name = "github.com/containerum/kube-client"
version = "^0.23.2"
version = "^0.23.18"
83 changes: 57 additions & 26 deletions cmd/user-manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,32 @@ const (
)

const (
portFlag = "port"
debugFlag = "debug"
textlogFlag = "textlog"
dbFlag = "db"
dbPGLoginFlag = "db_pg_login"
dbPGPasswordFlag = "db_pg_password"
dbPGAddrFlag = "db_pg_addr"
dbPGNameFlag = "db_pg_dbname"
dbPGNoSSLFlag = "db_pg_nossl"
dbMigrationsFlag = "db_migrations"
mailFlag = "mail"
mailURLFlag = "mail_url"
recaptchaFlag = "racaptcha"
recaptchaKeyFlag = "recaptcha_key"
oauthClientsFlag = "oauth_clients"
authFlag = "auth"
authHTTPAddrFlag = "auth_http_addr"
resourceFlag = "resource_service"
resourceURLFlag = "resource_service_url"
umFlag = "user_manager"
corsFlag = "cors"
adminPwdFlag = "admin_password"
portFlag = "port"
debugFlag = "debug"
textlogFlag = "textlog"
dbFlag = "db"
dbPGLoginFlag = "db_pg_login"
dbPGPasswordFlag = "db_pg_password"
dbPGAddrFlag = "db_pg_addr"
dbPGNameFlag = "db_pg_dbname"
dbPGNoSSLFlag = "db_pg_nossl"
dbMigrationsFlag = "db_migrations"
mailFlag = "mail"
mailURLFlag = "mail_url"
recaptchaFlag = "racaptcha"
recaptchaKeyFlag = "recaptcha_key"
oauthClientsFlag = "oauth_clients"
authFlag = "auth"
authHTTPAddrFlag = "auth_http_addr"
permissionsFlag = "permissions"
permissionsURLFlag = "permissions_url"
telegramFlag = "telegram"
telegramBotIDFlag = "telegram_bot_id"
telegramBotTokenFlag = "telegram_bot_token"
telegramBotChatIDFlag = "telegram_bot_chat_id"
umFlag = "user_manager"
corsFlag = "cors"
adminPwdFlag = "admin_password"
)

var flags = []cli.Flag{
Expand Down Expand Up @@ -141,16 +145,36 @@ var flags = []cli.Flag{
},
cli.StringFlag{
EnvVar: "CH_USER_PERMISSIONS",
Name: resourceFlag,
Name: permissionsFlag,
Value: serviceClientHTTP,
Usage: "Permissions service kind",
},
cli.StringFlag{
EnvVar: "CH_USER_PERMISSIONS_URL",
Name: resourceURLFlag,
Name: permissionsURLFlag,
Value: "http://permissions:4242",
Usage: "Permissions service URL",
},
cli.BoolFlag{
EnvVar: "CH_USER_TELEGRAM",
Name: telegramFlag,
Usage: "Telegram client enabled",
},
cli.StringFlag{
EnvVar: "CH_USER_TELEGRAM_BOT_ID",
Name: telegramBotIDFlag,
Usage: "Telegram bot ID",
},
cli.StringFlag{
EnvVar: "CH_USER_TELEGRAM_BOT_TOKEN",
Name: telegramBotTokenFlag,
Usage: "Telegram bot token",
},
cli.StringFlag{
EnvVar: "CH_USER_TELEGRAM_BOT_CHAT_ID",
Name: telegramBotChatIDFlag,
Usage: "Telegram bot chat ID",
},
cli.StringFlag{
EnvVar: "CH_USER_USER_MANAGER",
Name: umFlag,
Expand Down Expand Up @@ -240,14 +264,21 @@ func getAuthClient(c *cli.Context) (clients.AuthClient, error) {
}

func getPermissionsClient(c *cli.Context) (clients.PermissionsClient, error) {
switch c.String(resourceFlag) {
switch c.String(permissionsFlag) {
case serviceClientHTTP:
return clients.NewHTTPPermissionsClient(c.String(resourceURLFlag)), nil
return clients.NewHTTPPermissionsClient(c.String(permissionsURLFlag)), nil
default:
return nil, errors.New("invalid permissions client")
}
}

func getTelegramClient(c *cli.Context) (clients.TelegramClient, error) {
if c.Bool(telegramFlag) {
return clients.NewTelegramClient(c.String(telegramBotIDFlag), c.String(telegramBotTokenFlag), c.String(telegramBotChatIDFlag))
}
return nil, nil
}

func getUserManager(c *cli.Context, services server.Services) (server.UserManager, error) {
switch c.String(umFlag) {
case "impl":
Expand Down
6 changes: 5 additions & 1 deletion cmd/user-manager/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ func initServer(c *cli.Context) error {
err := oauthClientsSetup(c)
exitOnErr(err)

tgClient, err := getTelegramClient(c)
exitOnErr(err)

userManager, err := getUserManager(c, server.Services{
MailClient: getService(getMailClient(c)).(clients.MailClient),
DB: getService(getDB(c)).(db.DB),
AuthClient: getService(getAuthClient(c)).(clients.AuthClient),
ReCaptchaClient: getService(getReCaptchaClient(c)).(clients.ReCaptchaClient),
PermissionsClient: getService(getPermissionsClient(c)).(clients.PermissionsClient),
TelegramClient: tgClient,
})
exitOnErr(err)
defer userManager.Close()
Expand All @@ -57,7 +61,7 @@ func initServer(c *cli.Context) error {

go exitOnErr(srv.ListenAndServe())

quit := make(chan os.Signal)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
logrus.Infoln("shutting down server...")
Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewHTTPPermissionsClient(serverURL string) PermissionsClient {
SetHostURL(serverURL).
SetLogger(log.WriterLevel(logrus.DebugLevel)).
SetDebug(true).
SetTimeout(3 * time.Second).
SetTimeout(30 * time.Second).
SetError(cherry.Err{})
client.JSONMarshal = jsoniter.Marshal
client.JSONUnmarshal = jsoniter.Unmarshal
Expand Down
Loading

0 comments on commit 208cdc9

Please sign in to comment.