github.com/cs3org/reva/v2@v2.27.7/pkg/siteacc/config/config.go (about)

     1  // Copyright 2018-2020 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package config
    20  
    21  import (
    22  	"strings"
    23  
    24  	"github.com/cs3org/reva/v2/pkg/smtpclient"
    25  )
    26  
    27  // Configuration holds the general service configuration.
    28  type Configuration struct {
    29  	Prefix string `mapstructure:"prefix"`
    30  
    31  	Security struct {
    32  		CredentialsPassphrase string `mapstructure:"creds_passphrase"`
    33  	} `mapstructure:"security"`
    34  
    35  	Storage struct {
    36  		Driver string `mapstructure:"driver"`
    37  
    38  		File struct {
    39  			SitesFile    string `mapstructure:"sites_file"`
    40  			AccountsFile string `mapstructure:"accounts_file"`
    41  		} `mapstructure:"file"`
    42  	} `mapstructure:"storage"`
    43  
    44  	Email struct {
    45  		SMTP              *smtpclient.SMTPCredentials `mapstructure:"smtp"`
    46  		NotificationsMail string                      `mapstructure:"notifications_mail"`
    47  	} `mapstructure:"email"`
    48  
    49  	Mentix struct {
    50  		URL                      string `mapstructure:"url"`
    51  		DataEndpoint             string `mapstructure:"data_endpoint"`
    52  		SiteRegistrationEndpoint string `mapstructure:"sitereg_endpoint"`
    53  	} `mapstructure:"mentix"`
    54  
    55  	Webserver struct {
    56  		URL string `mapstructure:"url"`
    57  
    58  		SessionTimeout      int  `mapstructure:"session_timeout"`
    59  		VerifyRemoteAddress bool `mapstructure:"verify_remote_address"`
    60  		LogSessions         bool `mapstructure:"log_sessions"`
    61  	} `mapstructure:"webserver"`
    62  
    63  	GOCDB struct {
    64  		URL      string `mapstructure:"url"`
    65  		WriteURL string `mapstructure:"write_url"`
    66  
    67  		APIKey string `mapstructure:"apikey"`
    68  	} `mapstructure:"gocdb"`
    69  }
    70  
    71  // Cleanup cleans up certain settings, normalizing them.
    72  func (cfg *Configuration) Cleanup() {
    73  	// Ensure the webserver URL ends with a slash
    74  	if cfg.Webserver.URL != "" && !strings.HasSuffix(cfg.Webserver.URL, "/") {
    75  		cfg.Webserver.URL += "/"
    76  	}
    77  
    78  	// Ensure the GOCDB URL ends with a slash
    79  	if cfg.GOCDB.URL != "" && !strings.HasSuffix(cfg.GOCDB.URL, "/") {
    80  		cfg.GOCDB.URL += "/"
    81  	}
    82  
    83  	// Ensure the GOCDB Write URL ends with a slash
    84  	if cfg.GOCDB.WriteURL != "" && !strings.HasSuffix(cfg.GOCDB.WriteURL, "/") {
    85  		cfg.GOCDB.WriteURL += "/"
    86  	}
    87  }