Skip to content
Snippets Groups Projects
Select Git revision
  • dee5a19d36554a8f9a365efd65d13b134889bf63
  • ballinvoher default protected
  • client-http-server-for-token
  • master
  • gitlab-auth-issue
  • windows
  • microsoft
  • message
  • azure_auth
  • prometheus
  • permission-templates
  • no-datastore
  • save-public-keys
  • gitlab-group-level-start
  • v1.1.0
  • v1.0.0
  • v0.1
17 results

mem.go

Blame
  • config.go 1.64 KiB
    package config
    
    import (
    	"io"
    
    	"github.com/spf13/viper"
    )
    
    // Config holds the values from the json config file.
    type Config struct {
    	Server Server `mapstructure:"server"`
    	Auth   Auth   `mapstructure:"auth"`
    	SSH    SSH    `mapstructure:"ssh"`
    }
    
    // Server holds the configuration specific to the web server and sessions.
    type Server struct {
    	UseTLS       bool   `mapstructure:"use_tls"`
    	TLSKey       string `mapstructure:"tls_key"`
    	TLSCert      string `mapstructure:"tls_cert"`
    	Port         int    `mapstructure:"port"`
    	CookieSecret string `mapstructure:"cookie_secret"`
    }
    
    // Auth holds the configuration specific to the OAuth provider.
    type Auth struct {
    	OauthClientID     string            `mapstructure:"oauth_client_id"`
    	OauthClientSecret string            `mapstructure:"oauth_client_secret"`
    	OauthCallbackURL  string            `mapstructure:"oauth_callback_url"`
    	Provider          string            `mapstructure:"provider"`
    	ProviderOpts      map[string]string `mapstructure:"provider_opts"`
    }
    
    // SSH holds the configuration specific to signing ssh keys.
    type SSH struct {
    	SigningKey           string   `mapstructure:"signing_key"`
    	AdditionalPrincipals []string `mapstructure:"additional_principals"`
    	MaxAge               string   `mapstructure:"max_age"`
    	Permissions          []string `mapstructure:"permissions"`
    }
    
    // ReadConfig parses a JSON configuration file into a Config struct.
    func ReadConfig(r io.Reader) (*Config, error) {
    	config := &Config{}
    	v := viper.New()
    	v.SetConfigType("json")
    	if err := v.ReadConfig(r); err != nil {
    		return nil, err
    	}
    	if err := v.Unmarshal(config); err != nil {
    		return nil, err
    	}
    	return config, nil
    }