code.gitea.io/gitea@v1.19.3/modules/setting/federation.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package setting
     5  
     6  import (
     7  	"code.gitea.io/gitea/modules/log"
     8  
     9  	"github.com/go-fed/httpsig"
    10  )
    11  
    12  // Federation settings
    13  var (
    14  	Federation = struct {
    15  		Enabled             bool
    16  		ShareUserStatistics bool
    17  		MaxSize             int64
    18  		Algorithms          []string
    19  		DigestAlgorithm     string
    20  		GetHeaders          []string
    21  		PostHeaders         []string
    22  	}{
    23  		Enabled:             false,
    24  		ShareUserStatistics: true,
    25  		MaxSize:             4,
    26  		Algorithms:          []string{"rsa-sha256", "rsa-sha512", "ed25519"},
    27  		DigestAlgorithm:     "SHA-256",
    28  		GetHeaders:          []string{"(request-target)", "Date"},
    29  		PostHeaders:         []string{"(request-target)", "Date", "Digest"},
    30  	}
    31  )
    32  
    33  // HttpsigAlgs is a constant slice of httpsig algorithm objects
    34  var HttpsigAlgs []httpsig.Algorithm
    35  
    36  func loadFederationFrom(rootCfg ConfigProvider) {
    37  	if err := rootCfg.Section("federation").MapTo(&Federation); err != nil {
    38  		log.Fatal("Failed to map Federation settings: %v", err)
    39  	} else if !httpsig.IsSupportedDigestAlgorithm(Federation.DigestAlgorithm) {
    40  		log.Fatal("unsupported digest algorithm: %s", Federation.DigestAlgorithm)
    41  		return
    42  	}
    43  
    44  	// Get MaxSize in bytes instead of MiB
    45  	Federation.MaxSize = 1 << 20 * Federation.MaxSize
    46  
    47  	HttpsigAlgs = make([]httpsig.Algorithm, len(Federation.Algorithms))
    48  	for i, alg := range Federation.Algorithms {
    49  		HttpsigAlgs[i] = httpsig.Algorithm(alg)
    50  	}
    51  }