config

package
v0.0.0-...-344df76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package config project config

Package config xxx

Index

Constants

View Source
const (
	// DevEnv xxx
	DevEnv = "dev"
	// StagEnv xxx
	StagEnv = "stag"
	// ProdEnv xxx
	ProdEnv = "prod"
)
View Source
const (
	APIServicePrefix   = "/api"
	QueryServicePrefix = "/query"
)

子模块前缀

View Source
const (
	// RedisStandAloneType xxx
	RedisStandAloneType = "standalone" // 单节点redis
	// RedisSentinelType xxx
	RedisSentinelType = "sentinel" // 哨兵模式redis,哨兵实例
)

Variables

View Source
var (
	// BK_SYSTEM_ID ...
	BK_SYSTEM_ID = os.Getenv("BK_SYSTEM_ID")
	// BK_APP_CODE ...
	BK_APP_CODE = os.Getenv("BK_APP_CODE")
	// BK_APP_SECRET ...
	BK_APP_SECRET = os.Getenv("BK_APP_SECRET")
	// BK_PAAS_HOST ...
	BK_PAAS_HOST = os.Getenv("BK_PAAS_HOST")
	// REDIS_PASSWORD ...
	REDIS_PASSWORD = os.Getenv("REDIS_PASSWORD")
	// BCS_APIGW_TOKEN ...
	BCS_APIGW_TOKEN = os.Getenv("BCS_APIGW_TOKEN")
	// BCS_APIGW_PUBLIC_KEY ...
	BCS_APIGW_PUBLIC_KEY = os.Getenv("BCS_APIGW_PUBLIC_KEY")
	// BCS_ETCD_HOST ...
	BCS_ETCD_HOST = os.Getenv("bcsEtcdHost")
	// BKIAM_GATEWAY_SERVER ...
	BKIAM_GATEWAY_SERVER = os.Getenv("BKIAM_GATEWAY_SERVER")
	// MONGO_ADDRESS ...
	MONGO_ADDRESS = os.Getenv("MONGO_ADDRESS")
	// MONGO_USERNAME ...
	MONGO_USERNAME = os.Getenv("MONGO_USERNAME")
	// MONGO_PASSWORD ...
	MONGO_PASSWORD = os.Getenv("MONGO_PASSWORD")
	// BKLOG_API_SERVER ...
	BKLOG_API_SERVER = os.Getenv("BKLOG_API_SERVER")
	// BK_LOG_HOST ...
	BK_LOG_HOST = os.Getenv("BK_LOG_HOST")
	// BK_BASE_HOST ...
	BK_BASE_HOST = os.Getenv("BK_BASE_HOST")
)

Functions

func NewScopeMatcher

func NewScopeMatcher(name ScopeType, value string) (*labels.Matcher, error)

NewScopeMatcher : match 4种类型实现

Types

type BCSClusterEnv

type BCSClusterEnv string

BCSClusterEnv xxx

const (
	// ProdCluster xxx
	ProdCluster BCSClusterEnv = "prod" // 正式环境
	// DebugCLuster xxx
	DebugCLuster BCSClusterEnv = "debug" // debug 环境
	// UatCluster xxx
	UatCluster BCSClusterEnv = "uat" // uat 环境
)

type BCSConf

type BCSConf struct {
	Host         string         `yaml:"host"`
	Token        string         `yaml:"token"`
	Verify       bool           `yaml:"verify"`
	JWTPubKey    string         `yaml:"jwt_public_key"`
	QueryURL     string         `yaml:"query_url"`
	JWTPubKeyObj *rsa.PublicKey `yaml:"-"`
	ClusterEnv   BCSClusterEnv  `yaml:"cluster_env"`
}

BCSConf :

func (*BCSConf) Init

func (c *BCSConf) Init() error

Init :

func (*BCSConf) InitJWTPubKey

func (c *BCSConf) InitJWTPubKey() error

InitJWTPubKey :

type BKAPIGWConf

type BKAPIGWConf struct {
	Host         string         `yaml:"host"`
	JWTPubKey    string         `yaml:"jwt_public_key"`
	JWTPubKeyObj *rsa.PublicKey `yaml:"-"`
}

BKAPIGWConf :

func (*BKAPIGWConf) Init

func (c *BKAPIGWConf) Init() error

Init :

func (*BKAPIGWConf) InitJWTPubKey

func (c *BKAPIGWConf) InitJWTPubKey() error

InitJWTPubKey :

type BKLogConf

type BKLogConf struct {
	APIServer        string `yaml:"api_server"`        // openapi 地址
	Entrypoint       string `yaml:"entrypoint"`        // bk-log 页面 host 地址,e.g: https://bklog.example.com
	BKBaseEntrypoint string `yaml:"bkbase_entrypoint"` // bkbase 页面 host 地址,e.g: https://bkbase.example.com
}

BKLogConf bk log config

type BKMonitorConf

type BKMonitorConf struct {
	URL             string   `yaml:"url"`              // unify-query 访问地址
	MetadataURL     string   `yaml:"metadata_url"`     // 元数据地址
	DisableClusters []string `yaml:"disable_clusters"` // 集群黑名单,不使用蓝鲸监控
}

BKMonitorConf :

type BaseConf

type BaseConf struct {
	AppCode      string              `yaml:"app_code"`
	AppSecret    string              `yaml:"app_secret"`
	SystemID     string              `yaml:"system_id"`
	BKUsername   string              `yaml:"bk_username"`
	TimeZone     string              `yaml:"time_zone"`
	LanguageCode string              `yaml:"language_code"`
	Managers     []string            `yaml:"managers"`
	ManagerMap   map[string]struct{} `yaml:"-"`
	Debug        bool                `yaml:"debug"`
	RunEnv       string              `yaml:"run_env"`
	Location     *time.Location      `yaml:"-"`
}

BaseConf :

func (*BaseConf) Init

func (c *BaseConf) Init() error

Init :

func (*BaseConf) InitManagers

func (c *BaseConf) InitManagers() error

InitManagers :

type Configuration

type Configuration struct {
	Viper *viper.Viper

	Base        *BaseConf                `yaml:"base_conf"`
	Redis       *RedisConf               `yaml:"redis"`
	Mongo       *MongoConf               `yaml:"mongo"`
	StoreGWList []*StoreConf             `yaml:"storegw"`
	Logging     *conf.LogConfig          `yaml:"logging"`
	BKAPIGW     *BKAPIGWConf             `yaml:"bkapigw_conf"`
	BKMonitor   *BKMonitorConf           `yaml:"bk_monitor_conf"`
	BKLog       *BKLogConf               `yaml:"bk_log_conf"`
	BCS         *BCSConf                 `yaml:"bcs_conf"`
	IAM         *IAMConfig               `yaml:"iam_conf"`
	Credentials map[string][]*Credential `yaml:"-"`
	Web         *WebConf                 `yaml:"web"`
	QueryStore  *QueryStoreConf          `yaml:"query_store_conf"`
	TracingConf *TracingConf             `yaml:"tracing_conf"`
	// contains filtered or unexported fields
}

Configuration 配置

var G *Configuration

G : Global Configurations

func (*Configuration) IsDevMode

func (c *Configuration) IsDevMode() bool

IsDevMode 是否本地开发模式

func (*Configuration) ReadCredViper

func (c *Configuration) ReadCredViper(name string, v *viper.Viper) error

ReadCredViper 使用 viper 读取配置

func (*Configuration) ReadFrom

func (c *Configuration) ReadFrom(content []byte) error

ReadFrom : read from file

func (*Configuration) ReadFromViper

func (c *Configuration) ReadFromViper(v *viper.Viper) error

ReadFromViper : read from viper

type Credential

type Credential struct {
	ProjectId      string         `yaml:"project_id"`
	CredentialType CredentialType `yaml:"credential_type"`
	Credential     string         `yaml:"credential"`
	CredentialList []string       `yaml:"credential_list"`
	Scopes         []Scope        `yaml:"scopes"` // 多个取或关系
	ExpireTime     time.Time      `yaml:"expire_time"`
	Enabled        bool           `yaml:"enabled"`
	Operator       string         `yaml:"operator"`
	Comment        string         `yaml:"comment"`
	// contains filtered or unexported fields
}

Credential 鉴权

func (*Credential) InitCred

func (c *Credential) InitCred() error

InitCred :

func (*Credential) Matches

func (c *Credential) Matches(credType CredentialType, cred string, scopeType ScopeType, scopeValue string) bool

Matches 是否匹配

type CredentialType

type CredentialType string

CredentialType 凭证类型

const (
	// CredentialBasicAuth
	CredentialBasicAuth CredentialType = "basic_auth" // Basic验证
	// CredentialBearerToken
	CredentialBearerToken CredentialType = "bearer_token" // Token验证
	// CredentialAppCode
	CredentialAppCode CredentialType = "app_code" // 蓝鲸App
	// CredentialManager
	CredentialManager CredentialType = "manager" // 管理员
)

Credential 支持的类型, 配置 Unmarshal 会通过, 但是不会有匹配

type IAMConfig

type IAMConfig struct {
	External      bool   `yaml:"external"`
	GatewayServer string `yaml:"gateway_server"`
	IAMServer     string `yaml:"iam_server"`
	BkIAMServer   string `yaml:"bk_iam_erver"`
	Metric        bool   `yaml:"metric"`
	Debug         bool   `yaml:"debug"`
}

IAMConfig for perm interface

type LabelMatchers

type LabelMatchers []*labels.Matcher

LabelMatchers :

func (*LabelMatchers) Matches

func (m *LabelMatchers) Matches(name ScopeType, value string) bool

Matches 多个是且的关系, 注意, 只匹配单个

type MongoConf

type MongoConf struct {
	Address        string `yaml:"address"`
	AuthDatabase   string `yaml:"authdatabase"`
	Database       string `yaml:"database"`
	Username       string `yaml:"username"`
	Password       string `yaml:"password"`
	ConnectTimeout uint   `yaml:"connecttimeout"`
	MaxPoolSize    uint   `yaml:"maxpoolsize"`
	MinPoolSize    uint   `yaml:"minpoolsize"`
}

MongoConf mongo config

func DefaultMongoConf

func DefaultMongoConf() *MongoConf

DefaultMongoConf :

type QueryStoreConf

type QueryStoreConf struct {
	StaticConfigs []*targetgroup.Group      `yaml:"static_configs,omitempty"`
	HTTPSDConfigs []*httpdiscovery.SDConfig `yaml:"http_sd_configs,omitempty"`
}

QueryStoreConf 配置

type RedisConf

type RedisConf struct {
	Type             string   `yaml:"type" mapstructure:"type"`
	Host             string   `yaml:"host" mapstructure:"host"`
	Port             int      `yaml:"port" mapstructure:"port"`
	Password         string   `yaml:"password" mapstructure:"password"`
	DB               int      `yaml:"db" mapstructure:"db"`
	MasterName       string   `yaml:"master_name" mapstructure:"master_name"`
	SentinelAddrs    []string `yaml:"sentinel_addrs" mapstructure:"sentinel_addrs"`
	SentinelPassword string   `yaml:"sentinel_password" mapstructure:"sentinel_password"`
	MaxPoolSize      int      `yaml:"max_pool_size" mapstructure:"max_pool_size"`
	MaxConnTimeout   int      `yaml:"max_conn_timeout" mapstructure:"max_conn_timeout"`
	IdleTimeout      int      `yaml:"idle_timeout" mapstructure:"idle_timeout"`
	ReadTimeout      int      `yaml:"read_timeout" mapstructure:"read_timeout"`
	WriteTimeout     int      `yaml:"write_timeout" mapstructure:"write_timeout"`
}

RedisConf :

func DefaultRedisConf

func DefaultRedisConf() *RedisConf

DefaultRedisConf :

func (*RedisConf) IsSentinelType

func (r *RedisConf) IsSentinelType() bool

IsSentinelType 是否是哨兵模式

type Scope

type Scope map[ScopeType]string

Scope 权限控制,格式如cluster_id: "RE_BCS-K8S-40000", 多个取且关系

type ScopeType

type ScopeType string

ScopeType 类型, 配置 Unmarshal 会通过, 但是不会有匹配

const (
	// ScopeProjectId xxx
	ScopeProjectId ScopeType = "project_id" // 项目Id
	// ScopeProjectCode xxx
	ScopeProjectCode ScopeType = "project_code" // 项目Code
	// ScopeClusterId xxx
	ScopeClusterId ScopeType = "cluster_id" // 集群Id
)

type StoreConf

type StoreConf struct {
	Type   StoreProvider `yaml:"type"`
	Config interface{}   `yaml:"config,omitempty"`
}

StoreConf :

type StoreProvider

type StoreProvider string

StoreProvider :

const (
	// BKMONITOR 蓝鲸监控数据源
	BKMONITOR StoreProvider = "BK_MONITOR"
	// BCS_SYSTEM bcs 自定义 metrics
	BCS_SYSTEM StoreProvider = "BCS_SYSTEM"
	// PROMETHEUS prometheus 原生数据源
	PROMETHEUS StoreProvider = "PROMETHEUS"
	// SUANLI_CPU 算力 cpu 数据源
	SUANLI_CPU StoreProvider = "SUANLI_CPU"
	// SUANLI_GPU_NATIVE 算力 gpu 数据源
	SUANLI_GPU_NATIVE StoreProvider = "SUANLI_GPU_NATIVE"
)

type TracingConf

type TracingConf struct {
	Enabled       bool              `json:"enabled" usage:"enable trace"`
	Endpoint      string            `json:"endpoint" usage:"Collector service endpoint"`
	Token         string            `json:"token" usage:"token for collector service"`
	ResourceAttrs map[string]string `json:"resource_attrs" usage:"attributes of traced service"`
}

TracingConf tracing config

type WebConf

type WebConf struct {
	Host        string   `yaml:"host"`
	RoutePrefix string   `yaml:"route_prefix"`
	BaseURL     *url.URL `yaml:"-"`
}

WebConf web 相关配置

Directories

Path Synopsis
Package watch load config
Package watch load config

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL