code.gitea.io/gitea@v1.21.7/services/auth/source/pam/source.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package pam
     5  
     6  import (
     7  	"code.gitea.io/gitea/models/auth"
     8  	"code.gitea.io/gitea/modules/json"
     9  )
    10  
    11  // __________  _____      _____
    12  // \______   \/  _  \    /     \
    13  //  |     ___/  /_\  \  /  \ /  \
    14  //  |    |  /    |    \/    Y    \
    15  //  |____|  \____|__  /\____|__  /
    16  //                  \/         \/
    17  
    18  // Source holds configuration for the PAM login source.
    19  type Source struct {
    20  	ServiceName    string // pam service (e.g. system-auth)
    21  	EmailDomain    string
    22  	SkipLocalTwoFA bool `json:",omitempty"` // Skip Local 2fa for users authenticated with this source
    23  
    24  	// reference to the authSource
    25  	authSource *auth.Source
    26  }
    27  
    28  // FromDB fills up a PAMConfig from serialized format.
    29  func (source *Source) FromDB(bs []byte) error {
    30  	return json.UnmarshalHandleDoubleEncode(bs, &source)
    31  }
    32  
    33  // ToDB exports a PAMConfig to a serialized format.
    34  func (source *Source) ToDB() ([]byte, error) {
    35  	return json.Marshal(source)
    36  }
    37  
    38  // SetAuthSource sets the related AuthSource
    39  func (source *Source) SetAuthSource(authSource *auth.Source) {
    40  	source.authSource = authSource
    41  }
    42  
    43  func init() {
    44  	auth.RegisterTypeConfig(auth.PAM, &Source{})
    45  }