Documentation
¶
Index ¶
- Constants
- Variables
- func ApiPath(pattern string, paras ...string) string
- func BuildLoginURL(params *LoginParams, path string, ignores ...string) (string, error)
- func CalcFileMd5(fpath string) (uint64, string, error)
- func CompareVersion(local, remote VersionNumber) int
- func FormatDuration(layout string, startTime string, endTime string) (string, error)
- func GenKeyFiles(publicFile, privateFile string) error
- func GenKeys() (pubKey, priKey []byte)
- func GetCostrictDir() string
- func Login(params *LoginParams, progress func() error) (string, error)
- func OpenBrowser(url string) error
- func PrintArray(arr []interface{}, ...) error
- func PrintFormat(dataList []*orderedmap.OrderedMap) error
- func PrintFormatByOrderMap(s interface{}) error
- func PrintYaml(s interface{}) error
- func QuantityCompare(lhs, rhs Quantity) (int, error)
- func RsaDecrypt(priKey []byte, cipherText []byte) []byte
- func RsaEncrypt(pubKey []byte, msg []byte) []byte
- func SaveAuthConfig(config AuthConfig) error
- func Sign(priKey []byte, msg []byte) ([]byte, error)
- func StructToOrderedMap(s interface{}) (*orderedmap.OrderedMap, error)
- func Time2Sec(time string) (uint32, error)
- func VerifySign(pubKey []byte, signText []byte, plainText []byte) error
- type AuthConfig
- type JWTClaims
- type Json
- type KeyValues
- type LoginParams
- type PackageList
- type PackageOverview
- type PackageType
- type PackageVersion
- type PlatformId
- type PlatformInfo
- type PlatformOverview
- type Quantity
- type RespData
- type Scale
- type Session
- func (ss *Session) Delete(apiPath string) ([]byte, error)
- func (ss *Session) DeleteJson(apiPath string, data Json) ([]byte, error)
- func (ss *Session) Get(apiPath string, params Json) ([]byte, error)
- func (ss *Session) GetBody(apiPath string, params Json) (io.ReadCloser, error)
- func (ss *Session) GetData(apiPath string, params Json) ([]byte, error)
- func (ss *Session) Post(apiPath string, body []byte) ([]byte, error)
- func (ss *Session) PostJson(apiPath string, jsonData Json) ([]byte, error)
- func (ss *Session) Put(apiPath string, data Json) ([]byte, error)
- func (ss *Session) Request(method, apiPath string, paths, querys, headers map[string]string, body []byte) ([]byte, error)
- type TokenResponse
- type UpgradeConfig
- type Upgrader
- func (u *Upgrader) ActivatePackage(pkg PackageVersion) error
- func (u *Upgrader) AddPinned(pkg PackageVersion) error
- func (u *Upgrader) AddTodo(pkg PackageVersion) error
- func (u *Upgrader) CleanupOlders(reserveNum int) error
- func (u *Upgrader) CleanupPackage(reserveNum int)
- func (u *Upgrader) Close() error
- func (u *Upgrader) GetBytes(urlStr string, params map[string]string) ([]byte, error)
- func (u *Upgrader) GetFile(urlStr string, params map[string]string, savePath string) error
- func (u *Upgrader) GetInstallPaths(pkg *PackageVersion) (dir, fname, fullpath string)
- func (u *Upgrader) GetLocalVersion(ver *VersionNumber) (pkg PackageVersion, err error)
- func (u *Upgrader) GetPackage(specVer *VersionNumber) (PackageVersion, bool, error)
- func (u *Upgrader) GetPinned() (pkg PackageVersion, err error)
- func (u *Upgrader) GetRemotePackages() (PackageList, error)
- func (u *Upgrader) GetRemotePlatforms() (PackageOverview, error)
- func (u *Upgrader) GetRemoteVersions() (PlatformInfo, error)
- func (u *Upgrader) GetTodo() (pkg PackageVersion, err error)
- func (u *Upgrader) RemovePackage(ver *VersionNumber) error
- func (u *Upgrader) RemovePinned()
- func (u *Upgrader) RemoveTodo()
- func (u *Upgrader) SyncPackage(dstDir string) error
- func (u *Upgrader) UpgradePackage(specVer *VersionNumber) (PackageVersion, bool, error)
- type VersionAddr
- type VersionNumber
- type VersionOverview
Constants ¶
const SHENMA_BASE_URL = "https://zgsm.sangfor.com/costrict"
const SHENMA_PUBLIC_KEY = `` /* 450-byte string literal not displayed */
Variables ¶
var CostrictDir string = GetCostrictDir()
(default: %USERPROFILE%/.costrict on Windows, $HOME/.costrict on Linux)
Functions ¶
func BuildLoginURL ¶ added in v0.1.3
func BuildLoginURL(params *LoginParams, path string, ignores ...string) (string, error)
"/oidc-auth/api/v1/plugin/login/token" "/oidc-auth/api/v1/plugin/login" BuildLoginURL constructs the login URL with the given parameters @Summary Build login URL with optional parameter ignoring @Description Constructs a login URL using the provided parameters, optionally ignoring specified URL parameters @param params - Login parameters object containing all login configuration @param path - Path to append to the base URL (optional, defaults to "/login") @param ignores - String array of parameter names to exclude from the URL (optional) @returns Built login URL as string, or error if URL construction fails
func FormatDuration ¶
*
- Calculate time duration between two formatted times
- Uses "2006-01-02 15:04:05" format if none specified
func GetCostrictDir ¶
func GetCostrictDir() string
*
- Get costrict directory path
- @returns {string} Returns costrict directory path
func Login ¶ added in v0.1.3
func Login(params *LoginParams, progress func() error) (string, error)
Login performs the complete login process: 1. Opens the browser with the login URL 2. Periodically polls the token endpoint until a valid token is received 3. Returns the access token or an error
func OpenBrowser ¶ added in v0.1.3
OpenBrowser opens the specified URL in the default browser
func PrintArray ¶
func PrintArray(arr []interface{}, callback func(s interface{}) (*orderedmap.OrderedMap, error)) error
*
- Print array of items using callback to format each item
- @param arr array of items to print
- @param callback function to convert item to ordered map
- @return error if conversion or printing fails
func PrintFormat ¶
func PrintFormat(dataList []*orderedmap.OrderedMap) error
*
- Format and print ordered map data as table
- @param dataList slice of ordered maps to display
- @return error if data is empty or formatting fails
func PrintFormatByOrderMap ¶
func PrintFormatByOrderMap(s interface{}) error
*
- Print single struct as formatted table using ordered map
- @param s struct to print
- @return error if conversion or printing fails
func PrintYaml ¶
func PrintYaml(s interface{}) error
*
- Print data structure in YAML format
- @param s data to print
- @return error if YAML marshaling fails
func SaveAuthConfig ¶ added in v0.1.3
func SaveAuthConfig(config AuthConfig) error
func StructToOrderedMap ¶
func StructToOrderedMap(s interface{}) (*orderedmap.OrderedMap, error)
*
- Convert struct to ordered map
- @param s struct to convert
- @return *orderedmap.OrderedMap converted map
- @return error if input is not struct type
Types ¶
type AuthConfig ¶ added in v0.1.3
type JWTClaims ¶ added in v0.1.3
type JWTClaims struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Email string `json:"email,omitempty"`
}
JWTClaims represents the decoded JWT token claims
func DecodeJWT ¶ added in v0.1.3
DecodeJWT decodes a JWT token without verifying the signature @Summary Decode JWT token without verification @description - Splits the JWT token into its three parts - Decodes the payload (second part) from base64 - Returns the claims as a JWTClaims struct @param token - The JWT token to decode @returns JWTClaims object containing user information or error if decoding fails
type LoginParams ¶ added in v0.1.3
type LoginParams struct {
BaseURL string `json:"base_url,omitempty"`
MachineCode string `json:"machine_code,omitempty"`
PluginVersion string `json:"plugin_version,omitempty"`
VSCodeVersion string `json:"vscode_version,omitempty"`
State string `json:"state,omitempty"`
Provider string `json:"provider,omitempty"`
URIScheme string `json:"uri_scheme,omitempty"`
}
LoginParams represents the parameters for building login URL
type PackageOverview ¶ added in v0.1.3
type PackageOverview struct {
PackageName string `json:"packageName"` //包名称
Platforms []PlatformId `json:"platforms"` //包支持的平台列表
Overviews map[string]PlatformOverview `json:"overviews"` //包总览
}
*
- 包目录(软件包的系统,平台,版本目录)
type PackageType ¶
type PackageType string
*
- 包类型枚举
const ( PackageTypeExec PackageType = "exec" PackageTypeConf PackageType = "conf" PackageTypeZip PackageType = "zip" )
type PackageVersion ¶ added in v0.1.3
type PackageVersion struct {
PackageName string `json:"packageName"` //包名字
PackageType PackageType `json:"packageType"` //包类型: exec/conf
FileName string `json:"fileName"` //被打包的文件的相对路径(相对.costrict目录,为空则安装到默认路径)
Os string `json:"os"` //操作系统名:linux/windows
Arch string `json:"arch"` //硬件架构
Size uint64 `json:"size"` //包文件大小
Checksum string `json:"checksum"` //Md5散列值
Sign string `json:"sign"` //签名,使用私钥签的名,需要用对应公钥验证
ChecksumAlgo string `json:"checksumAlgo"` //固定为“md5”
VersionId VersionNumber `json:"versionId"` //版本号,采用SemVer标准
Build string `json:"build"` //构建信息:Tag/Branch信息 CommitID BuildTime
ReleaseTime string `json:"releaseTime,omitempty"` //包发布时间
Description string `json:"description"` //版本描述,含有更丰富的可读信息
}
*
- 包版本的描述&签名信息,用于验证包的正确性
func (*PackageVersion) Load ¶ added in v0.1.3
func (pkg *PackageVersion) Load(fname string) error
func (*PackageVersion) Save ¶ added in v0.1.3
func (pkg *PackageVersion) Save(fname string) error
func (*PackageVersion) Verify ¶ added in v0.1.3
func (pkg *PackageVersion) Verify() error
type PlatformInfo ¶
type PlatformInfo struct {
PackageName string `json:"packageName"`
Os string `json:"os"`
Arch string `json:"arch"`
Newest VersionAddr `json:"newest"`
Versions []VersionAddr `json:"versions"`
}
*
- 指定平台的关键信息,比如,最新版本,版本列表(描述一个硬件平台/操作系统对应的包列表)
type PlatformOverview ¶ added in v0.1.3
type PlatformOverview struct {
Os string `json:"os"`
Arch string `json:"arch"`
Newest VersionOverview `json:"newest"`
Versions []VersionOverview `json:"versions"`
}
type Quantity ¶
type Session ¶
type Session struct {
HostUrl string `json:"url"`
// contains filtered or unexported fields
}
*
- HTTP Session
type TokenResponse ¶ added in v0.1.3
type TokenResponse struct {
Code int `json:"code,omitempty"`
Data struct {
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
State string `json:"state,omitempty"`
} `json:"data,omitempty"`
Message string `json:"message,omitempty"`
Success bool `json:"success,omitempty"`
}
TokenResponse represents the response from the token endpoint
func GetToken ¶ added in v0.1.3
func GetToken(params *LoginParams) (*TokenResponse, error)
GetToken sends a GET request to the token endpoint with the same parameters used for login @Summary Get authentication token from token endpoint @Description Sends a GET request to the token endpoint with login parameters @param params - Login parameters object containing all login configuration @returns TokenResponse object containing authentication token or error, or error if request fails
type UpgradeConfig ¶
type Upgrader ¶ added in v0.1.3
type Upgrader struct {
UpgradeConfig
// contains filtered or unexported fields
}
func NewUpgrader ¶ added in v0.1.3
func NewUpgrader(packageName string, cfg UpgradeConfig, client *http.Client) *Upgrader
func (*Upgrader) ActivatePackage ¶ added in v0.1.3
func (u *Upgrader) ActivatePackage(pkg PackageVersion) error
*
- 激活版本ver的包,令其成为当前版本
func (*Upgrader) AddPinned ¶ added in v0.1.3
func (u *Upgrader) AddPinned(pkg PackageVersion) error
*
- 固定版本,令自动升级忽略该包
func (*Upgrader) AddTodo ¶ added in v0.1.3
func (u *Upgrader) AddTodo(pkg PackageVersion) error
func (*Upgrader) CleanupOlders ¶ added in v0.1.3
*
- 清理package目录下过老的版本包数据
- @param {string} baseDir - costrict数据所在的基路径,如果为空则使用默认路径
- @returns {error} 返回错误对象,成功时返回nil
- @description
- - 扫描版本描述文件package/x-{ver}.json文件,提取文件中保存的版本信息
- - 保证每个模块只保留最新的三个包,过老的包需要清除
- - 删除过老的包描述文件x-{ver}.json和package/{ver}/{targetFile}
- - 支持自定义baseDir,如果为空则使用默认的.costrict目录
- - 按包名分组处理,每个包保留最新的三个版本
- @throws
- - 读取package目录失败
- - 解析版本描述文件失败
- - 删除包文件或描述文件失败
func (*Upgrader) Close ¶ added in v0.1.3
*
- Close the HTTP client and clean up resources
- @returns {error} Returns error if closing fails, nil on success
- @description
- - Closes idle HTTP connections to prevent resource leaks
- - Should be called when the Upgrader is no longer needed
- - Safe to call multiple times
- @example
- upgrader := NewUpgrader("mypkg", config)
- defer upgrader.Close()
func (*Upgrader) GetInstallPaths ¶ added in v0.1.3
func (u *Upgrader) GetInstallPaths(pkg *PackageVersion) (dir, fname, fullpath string)
func (*Upgrader) GetLocalVersion ¶ added in v0.1.3
func (u *Upgrader) GetLocalVersion(ver *VersionNumber) (pkg PackageVersion, err error)
*
- 获取本地包信息
- 如果指定了版本,则获取指定版本包信息,否则获取最新版本
func (*Upgrader) GetPackage ¶ added in v0.1.3
func (u *Upgrader) GetPackage(specVer *VersionNumber) (PackageVersion, bool, error)
*
- 获取包(需要校验保证包的合法性)
func (*Upgrader) GetPinned ¶ added in v0.1.3
func (u *Upgrader) GetPinned() (pkg PackageVersion, err error)
func (*Upgrader) GetRemotePackages ¶ added in v0.1.3
func (u *Upgrader) GetRemotePackages() (PackageList, error)
func (*Upgrader) GetRemotePlatforms ¶ added in v0.1.3
func (u *Upgrader) GetRemotePlatforms() (PackageOverview, error)
func (*Upgrader) GetRemoteVersions ¶ added in v0.1.3
func (u *Upgrader) GetRemoteVersions() (PlatformInfo, error)
*
- 从远程库获取包版本
- 如果具体的os/arch不存在,则尝试获取common/common的通用包
func (*Upgrader) GetTodo ¶ added in v0.1.3
func (u *Upgrader) GetTodo() (pkg PackageVersion, err error)
func (*Upgrader) RemovePackage ¶ added in v0.1.3
func (u *Upgrader) RemovePackage(ver *VersionNumber) error
*
- 移除指定版本或当前版本的包
func (*Upgrader) RemovePinned ¶ added in v0.1.3
func (u *Upgrader) RemovePinned()
func (*Upgrader) RemoveTodo ¶ added in v0.1.3
func (u *Upgrader) RemoveTodo()
func (*Upgrader) SyncPackage ¶ added in v0.1.3
*
- SyncPackage 将远程包目录树以镜像的方式同步到本地目录
- 下载层次结构:
- - dstDir/platforms.json ← <base-url>/<package>/platforms.json
- - 对于每个平台组合 (os/arch):
- - dstDir/<os>/<arch>/platform.json ← <base-url>/<package>/<os>/<arch>/platform.json
- - 对于每个版本:
- - dstDir/<os>/<arch>/<version>/package.json ← <base-url>/<package>/<os>/<arch>/<version>/package.json
- - dstDir/<os>/<arch>/<version>/ ← <base-url>/<package>/<os>/<arch>/<version>/<filename>
func (*Upgrader) UpgradePackage ¶ added in v0.1.3
func (u *Upgrader) UpgradePackage(specVer *VersionNumber) (PackageVersion, bool, error)
*
- 升级包
type VersionAddr ¶
type VersionAddr struct {
VersionId VersionNumber `json:"versionId"` //版本的地址信息
AppUrl string `json:"appUrl"` //包地址
InfoUrl string `json:"infoUrl"` //包描述信息(PackageVersion)文件的地址
}
*
- 一个package版本的地址信息
type VersionNumber ¶
type VersionNumber struct {
Major int `json:"major"`
Minor int `json:"minor"`
Micro int `json:"micro"`
}
*
- 版本编号
func NewVersion ¶ added in v0.1.3
func NewVersion(verStr string) (v VersionNumber, err error)
------------------------------------------------------------------------------
VersionNumber
------------------------------------------------------------------------------
func (*VersionNumber) Parse ¶ added in v0.1.3
func (ver *VersionNumber) Parse(verstr string) error
func (*VersionNumber) String ¶ added in v0.1.3
func (ver *VersionNumber) String() string
type VersionOverview ¶ added in v0.1.3
type VersionOverview struct {
VersionId VersionNumber `json:"versionId"` //版本号,采用SemVer标准
PackageType PackageType `json:"packageType"` //包类型: exec/conf
FileName string `json:"fileName"` //被打包的文件的名字
Size uint64 `json:"size"` //包文件大小
ReleaseTime string `json:"releaseTime"` //发布时间
Build string `json:"build"` //构建信息:Tag/Branch信息 CommitID BuildTime
Description string `json:"description"` //版本描述,含有更丰富的可读信息
}