github.com/harryzcy/snuuze@v0.3.3-0.20240314015559-83a8fc5627a8/types/hosting.go (about)

     1  package types
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  )
     7  
     8  type HostingConfig struct {
     9  	Data    DataConfig    `yaml:"data"`
    10  	Network NetworkConfig `yaml:"network"`
    11  	GitHub  GitHubConfig  `yaml:"github"`
    12  	Gitea   []GiteaConfig `yaml:"gitea"`
    13  }
    14  
    15  type DataConfig struct {
    16  	TempDir string `yaml:"tempDir"`
    17  	// Timeout for accessing files and running commands
    18  	Timeout int64 `yaml:"timeout"` // in seconds
    19  }
    20  
    21  func (d DataConfig) GetTimeout() time.Duration {
    22  	if d.Timeout <= 0 {
    23  		return 100 * time.Second // default to 100 seconds
    24  	}
    25  	return time.Duration(d.Timeout) * time.Second
    26  }
    27  
    28  type NetworkConfig struct {
    29  	Timeout int64 `yaml:"timeout"` // in seconds
    30  }
    31  
    32  func (n NetworkConfig) GetTimeout() time.Duration {
    33  	if n.Timeout <= 0 {
    34  		return 10 * time.Second // default to 10 seconds
    35  	}
    36  	return time.Duration(n.Timeout) * time.Second
    37  }
    38  
    39  type GitHubConfig struct {
    40  	AuthType string `yaml:"authType"` // token, github-app
    41  	// if auth-type is token
    42  	Token string `yaml:"token"`
    43  
    44  	// if auth-type is github-app
    45  	AppID          int64  `yaml:"appID"`
    46  	PEMFile        string `yaml:"pemFile"`
    47  	ClientID       string `yaml:"clientID"`
    48  	InstallationID int64  `yaml:"installationID"`
    49  	AppName        string `yaml:"appName"`
    50  	AppUserID      int64  `yaml:"appUserID"`
    51  }
    52  
    53  type GiteaConfig struct {
    54  	Host     string `yaml:"host"`
    55  	AuthType string `yaml:"authType"` // token
    56  
    57  	// if auth-type is token
    58  	Token string `yaml:"token"`
    59  }
    60  
    61  func (c *GiteaConfig) GetHost() string {
    62  	return strings.TrimSuffix(c.Host, "/")
    63  }
    64  
    65  const (
    66  	AuthTypeToken     = "token"
    67  	AuthTypeGithubApp = "github-app"
    68  )