Use of a configuration file to store the client and secret keys
This commit is contained in:
parent
3240657289
commit
f5658a1de1
2 changed files with 34 additions and 0 deletions
3
configuration-example.toml
Normal file
3
configuration-example.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Get a key on https://developers.eveonline.com/applications
|
||||||
|
ClientID = "SAMPLE_CLIENTID"
|
||||||
|
ClientSecret = "SAMPLE_CLIENTSECRET"
|
31
main.go
31
main.go
|
@ -16,6 +16,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
"github.com/leekchan/accounting"
|
"github.com/leekchan/accounting"
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
|
@ -41,6 +42,11 @@ type Character struct {
|
||||||
ExpiresOn string
|
ExpiresOn string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type configurationFile struct {
|
||||||
|
ClientID string
|
||||||
|
ClientSecret string
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
googleOauthConfig = &oauth2.Config{
|
googleOauthConfig = &oauth2.Config{
|
||||||
RedirectURL: "http://localhost:3000/callback",
|
RedirectURL: "http://localhost:3000/callback",
|
||||||
|
@ -74,6 +80,12 @@ func main() {
|
||||||
|
|
||||||
log.SetOutput(f)
|
log.SetOutput(f)
|
||||||
|
|
||||||
|
cErr := readConfigurationFile()
|
||||||
|
if cErr != nil {
|
||||||
|
fmt.Println("Missing configuration file.")
|
||||||
|
log.Fatal(cErr)
|
||||||
|
}
|
||||||
|
|
||||||
cToken := getDatabaseToken()
|
cToken := getDatabaseToken()
|
||||||
|
|
||||||
if cToken == nil {
|
if cToken == nil {
|
||||||
|
@ -104,6 +116,25 @@ func main() {
|
||||||
printCharacterSkillQueue(swaggerclient, m)
|
printCharacterSkillQueue(swaggerclient, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readConfigurationFile() error {
|
||||||
|
cfgFilePath := "configuration.toml"
|
||||||
|
var config configurationFile
|
||||||
|
if _, err := toml.DecodeFile(cfgFilePath, &config); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.ClientID == "" || config.ClientSecret == "" {
|
||||||
|
log.Println("Missing ClientID or ClientSecret configuration option in configuration file" + cfgFilePath + ".")
|
||||||
|
return errors.New("Missing ClientID or ClientSecret in configuration file " + cfgFilePath + ".")
|
||||||
|
}
|
||||||
|
|
||||||
|
googleOauthConfig.ClientID = config.ClientID
|
||||||
|
googleOauthConfig.ClientSecret = config.ClientSecret
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getCharacterInfo(client *http.Client) (*Character, error) {
|
func getCharacterInfo(client *http.Client) (*Character, error) {
|
||||||
|
|
||||||
req, _ := http.NewRequest("GET", "https://login.eveonline.com/oauth/verify", nil)
|
req, _ := http.NewRequest("GET", "https://login.eveonline.com/oauth/verify", nil)
|
||||||
|
|
Reference in a new issue