Make network interface configurable

master
Hugo Thunnissen 4 years ago
parent 184273e6e6
commit 43f4e92f0c

@ -46,6 +46,8 @@ type AppConfig struct {
DBPath string `yaml:"db_path"`
AppScopes []string `yaml:"app_scopes"`
Website string `yaml:"website"`
Interface string `yaml:"network_interface"`
Port string `yaml:"network_port"`
}
type AuthToken struct {
@ -291,6 +293,14 @@ func (c *AppConfig) FromFile(filePath string) error {
c.AppScheme = "https"
}
if c.Port == "" {
c.Port = "9569"
}
if c.Interface == "" {
c.Interface = "127.0.0.1"
}
return nil
}
@ -313,6 +323,41 @@ func (a *App) InitializeDB() error {
return nil
}
func (a *App) GetCredentialsFromInstanceHost(host string) (*Instance, error) {
postData := &map[string]string{
"client_name": a.Config.AppName,
"redirect_uris": a.Config.AppScheme + "://" + a.Config.AppHost + "/confirm",
"scopes": strings.Join(a.Config.AppScopes, " "),
"website": a.Config.Website,
}
data, err := json.Marshal(postData)
if err != nil {
return nil, err
}
response, err := http.Post("https://"+host+"/api/v1/apps", "application/json", bytes.NewBuffer(data))
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
instance := &Instance{
Host: host,
}
err = json.Unmarshal(body, instance)
return instance, err
}
func main() {
arguments := os.Args[1:]
@ -359,40 +404,6 @@ func main() {
e.GET("/ws", a.AuthRequestWebSocket)
e.GET("/auth/:request_id", a.AuthRequestRedirect)
e.GET("/confirm", a.AuthRequestConfirm)
e.Logger.Fatal(e.Start(":1323"))
}
func (a *App) GetCredentialsFromInstanceHost(host string) (*Instance, error) {
postData := &map[string]string{
"client_name": a.Config.AppName,
"redirect_uris": a.Config.AppScheme + "://" + a.Config.AppHost + "/confirm",
"scopes": strings.Join(a.Config.AppScopes, " "),
"website": a.Config.Website,
}
data, err := json.Marshal(postData)
if err != nil {
return nil, err
}
response, err := http.Post("https://"+host+"/api/v1/apps", "application/json", bytes.NewBuffer(data))
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
instance := &Instance{
Host: host,
}
err = json.Unmarshal(body, instance)
return instance, err
e.Logger.Fatal(e.Start(a.Config.Interface + ":" + a.Config.Port))
}

Loading…
Cancel
Save