config

Imports

Imports #

"errors"
"flag"
"fmt"
"net/url"
"os"
"strconv"
"time"

Interfaces

OAuthProvider interface #

OAuth Provider

type OAuthProvider interface {
Name() string
AuthURL() string
TokenURL() string
AppCallbackURL() string
AppTokenEndpoint() string
ClientID() string
ClientSecret() string
}

Structs

Config struct #

Config

type Config struct {
Version string
Port int
EnableTLS bool
CertFile string
KeyFile string
APIRate int
APIBurst int
SolverTimeout time.Duration
OAuth bool
JWTSecret string
JWTTokenValidity time.Duration
OAuthProviders map[string]OAuthProvider
}

GithubProvider struct #

Github OAuth provider

type GithubProvider struct {
ProviderName string
ProviderAuthURL string
ProviderTokenURL string
CallbackURL string
AppClientId string
AppClientSecret string
}

Functions

AppCallbackURL method #

Returns callback URL where Github will redirect the user

func (p GithubProvider) AppCallbackURL() string

AppTokenEndpoint method #

Returns code<>token exchange URL where client can exchange code for JWT token

func (p GithubProvider) AppTokenEndpoint() string

AuthURL method #

Returns URL where client can authenticate with the OAuth Provider

func (p GithubProvider) AuthURL() string

ClientID method #

Returns Client ID

func (p GithubProvider) ClientID() string

ClientSecret method #

Returns Client Secret

func (p GithubProvider) ClientSecret() string

LoadConfig function #

Load configuration from command line and environment Returns Configuration and list of load errors TODO: JSON config

func LoadConfig() (Config, []error)

Name method #

Returns Name

func (p GithubProvider) Name() string

NewConfig function #

Constructor with defaults

func NewConfig() Config

StripHost function #

func StripHost(raw string) (string, error)

TokenURL method #

Returns URl where app can exchange client code for a token

func (p GithubProvider) TokenURL() string

ValidateConfig method #

Validates configuration. Returns if configuration is valid or list of validation errors

func (cfg *Config) ValidateConfig() (bool, []error)

envOrDefault function #

Returns value of env variable or default if not set

func envOrDefault(env string, def string) string

isValidURL function #

Check if string is valid URL

func isValidURL(s string) bool