Add support for app key + token
This commit is contained in:
parent
af6c6bf521
commit
296f16b122
4 changed files with 60 additions and 20 deletions
|
@ -21,12 +21,19 @@ Make sure you have Docker installed, then type:
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
## Creating a developper account
|
||||||
|
|
||||||
|
1. Create a trello account
|
||||||
|
2. Confirm your email
|
||||||
|
3. Enable developper account on <https://trello.com/app-key>
|
||||||
|
4. Get an developer API KEY
|
||||||
|
|
||||||
## Getting a Trello TOKEN
|
## Getting a Trello TOKEN
|
||||||
|
|
||||||
Open the following URL in your web browser and authenticate yourself. That will
|
Open the following URL in your web browser and authenticate yourself. That will
|
||||||
give you the TRELLO_TOKEN that will be needed in the next step.
|
give you the TRELLO_TOKEN that will be needed in the next step.
|
||||||
|
|
||||||
<https://trello.com/1/authorize?expiration=never&scope=read,write,account&response_type=token&name=Server%20Token&key=58117ebf843d49b05bca074c5fd520ee>
|
<https://trello.com/1/authorize?expiration=never&scope=read,write,account&response_type=token&name=Trello2Mail&key=YOUR-API-KEY>
|
||||||
|
|
||||||
## Normal use
|
## Normal use
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ type Config struct {
|
||||||
SmtpSecurityType string `mapstructure:"smtp-security-type"`
|
SmtpSecurityType string `mapstructure:"smtp-security-type"`
|
||||||
|
|
||||||
TrelloUrl string `mapstructure:"trello-url"`
|
TrelloUrl string `mapstructure:"trello-url"`
|
||||||
|
TrelloApiKey string `mapstructure:"trello-api-key"`
|
||||||
TrelloToken string `mapstructure:"trello-token"`
|
TrelloToken string `mapstructure:"trello-token"`
|
||||||
|
|
||||||
Parser *cobra.Command `mapstructure:"-"`
|
Parser *cobra.Command `mapstructure:"-"`
|
||||||
|
@ -53,7 +54,8 @@ func NewConfig() *Config {
|
||||||
cmd.PersistentFlags().StringVarP(&self.EmailSubject, "email-subject", "", "", "email subject")
|
cmd.PersistentFlags().StringVarP(&self.EmailSubject, "email-subject", "", "", "email subject")
|
||||||
|
|
||||||
cmd.PersistentFlags().StringVarP(&self.TrelloUrl, "trello-url", "", "", "url of trello board")
|
cmd.PersistentFlags().StringVarP(&self.TrelloUrl, "trello-url", "", "", "url of trello board")
|
||||||
cmd.PersistentFlags().StringVarP(&self.TrelloToken, "trello-token", "", "", "url of trello token")
|
cmd.PersistentFlags().StringVarP(&self.TrelloUrl, "trello-api-key", "", "", "API KEY for trello access")
|
||||||
|
cmd.PersistentFlags().StringVarP(&self.TrelloToken, "trello-token", "", "", "TOKEN for trello access")
|
||||||
|
|
||||||
cmd.PersistentFlags().StringVarP(&self.SmtpHostname, "smtp-hostname", "", "", "address of smtp server")
|
cmd.PersistentFlags().StringVarP(&self.SmtpHostname, "smtp-hostname", "", "", "address of smtp server")
|
||||||
cmd.PersistentFlags().StringVarP(&self.SmtpUsername, "smtp-username", "", "", "username for smtp server")
|
cmd.PersistentFlags().StringVarP(&self.SmtpUsername, "smtp-username", "", "", "username for smtp server")
|
||||||
|
@ -67,6 +69,7 @@ func NewConfig() *Config {
|
||||||
viper.BindPFlag("email-subject", cmd.PersistentFlags().Lookup("email-subject"))
|
viper.BindPFlag("email-subject", cmd.PersistentFlags().Lookup("email-subject"))
|
||||||
viper.BindPFlag("trello-url", cmd.PersistentFlags().Lookup("trello-url"))
|
viper.BindPFlag("trello-url", cmd.PersistentFlags().Lookup("trello-url"))
|
||||||
viper.BindPFlag("trello-token", cmd.PersistentFlags().Lookup("trello-token"))
|
viper.BindPFlag("trello-token", cmd.PersistentFlags().Lookup("trello-token"))
|
||||||
|
viper.BindPFlag("trello-api-key", cmd.PersistentFlags().Lookup("trello-api-key"))
|
||||||
viper.BindPFlag("smtp-hostname", cmd.PersistentFlags().Lookup("smtp-hostname"))
|
viper.BindPFlag("smtp-hostname", cmd.PersistentFlags().Lookup("smtp-hostname"))
|
||||||
viper.BindPFlag("smtp-username", cmd.PersistentFlags().Lookup("smtp-username"))
|
viper.BindPFlag("smtp-username", cmd.PersistentFlags().Lookup("smtp-username"))
|
||||||
viper.BindPFlag("smtp-password", cmd.PersistentFlags().Lookup("smtp-password"))
|
viper.BindPFlag("smtp-password", cmd.PersistentFlags().Lookup("smtp-password"))
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-mail/mail"
|
"github.com/go-mail/mail"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -11,10 +12,15 @@ func main() {
|
||||||
fmt.Println("d: parsing config")
|
fmt.Println("d: parsing config")
|
||||||
config := NewConfig()
|
config := NewConfig()
|
||||||
config.Parse()
|
config.Parse()
|
||||||
|
fmt.Printf("%+v\n", config)
|
||||||
|
|
||||||
// Get task list as markdown
|
// Get task list as markdown
|
||||||
fmt.Println("d: configuring trello")
|
fmt.Println("d: configuring trello")
|
||||||
trelloCtx := NewTrello(config.TrelloToken)
|
trelloCtx := NewTrello(config.TrelloApiKey, config.TrelloToken)
|
||||||
|
if trelloCtx == nil {
|
||||||
|
fmt.Println("ERROR: Unable to initialize trello context")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("d: getting trello boards")
|
fmt.Println("d: getting trello boards")
|
||||||
var trelloBoardsList []TrelloBoard
|
var trelloBoardsList []TrelloBoard
|
||||||
|
|
|
@ -18,18 +18,9 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// See https://trello.com/app-key
|
|
||||||
APP_KEY string = "58117ebf843d49b05bca074c5fd520ee"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TrelloConfig struct {
|
|
||||||
Url string
|
|
||||||
Token string
|
|
||||||
}
|
|
||||||
|
|
||||||
type TrelloCtx struct {
|
type TrelloCtx struct {
|
||||||
Token string
|
Token string
|
||||||
|
ApiKey string
|
||||||
Client *trello.Client
|
Client *trello.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,13 +44,36 @@ func runcmd(command string) string {
|
||||||
return string(out)
|
return string(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTokenProcessMessage() string {
|
func MessageForApiKey() string {
|
||||||
|
/*
|
||||||
url := strings.Join([]string{
|
url := strings.Join([]string{
|
||||||
"https://trello.com/1/authorize?expiration=never",
|
"https://trello.com/1/authorize?expiration=never",
|
||||||
"name=taskell",
|
"name=Trello-To-Mail",
|
||||||
"scope=read",
|
"scope=read",
|
||||||
"response_type=token",
|
"response_type=token",
|
||||||
fmt.Sprintf("key=%s", APP_KEY),
|
fmt.Sprintf("key=%s", apiKey),
|
||||||
|
}, "&")
|
||||||
|
*/
|
||||||
|
|
||||||
|
url := "https://trello.com/app-key/"
|
||||||
|
|
||||||
|
text := strings.Join([]string{
|
||||||
|
"Wrong or empty TRELLO_API_KEY value. Please visit:",
|
||||||
|
url,
|
||||||
|
"Then enable developper account.",
|
||||||
|
"When you have your user api key, set TRELLO_API_KEY=<your-api-key>",
|
||||||
|
}, "\n\n")
|
||||||
|
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
func MessageForToken(apiKey string) string {
|
||||||
|
url := strings.Join([]string{
|
||||||
|
"https://trello.com/1/authorize?expiration=never",
|
||||||
|
"name=Trello-To-Mail",
|
||||||
|
"scope=read",
|
||||||
|
"response_type=token",
|
||||||
|
fmt.Sprintf("key=%s", apiKey),
|
||||||
}, "&")
|
}, "&")
|
||||||
|
|
||||||
text := strings.Join([]string{
|
text := strings.Join([]string{
|
||||||
|
@ -71,11 +85,21 @@ func GetTokenProcessMessage() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTrello(token string) *TrelloCtx {
|
func NewTrello(apiKey string, token string) *TrelloCtx {
|
||||||
client := trello.NewClient(APP_KEY, token)
|
if len(apiKey) == 0 {
|
||||||
|
fmt.Println(MessageForApiKey())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(token) == 0 {
|
||||||
|
fmt.Println(MessageForToken(apiKey))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
ctx := TrelloCtx{}
|
ctx := TrelloCtx{}
|
||||||
|
ctx.ApiKey = apiKey
|
||||||
ctx.Token = token
|
ctx.Token = token
|
||||||
|
|
||||||
|
client := trello.NewClient(apiKey, token)
|
||||||
ctx.Client = client
|
ctx.Client = client
|
||||||
|
|
||||||
return &ctx
|
return &ctx
|
||||||
|
|
Loading…
Reference in a new issue