cmd

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Copyright © 2022 NAME HERE <EMAIL ADDRESS>

Index

Constants

View Source
const (
	ModeSSO = "sso"
	ModeAK  = "ak"

	ConfigFile = "config.json"
)

定义模式枚举常量

Variables

This section is empty.

Functions

func Execute

func Execute()

func GetServiceMapping

func GetServiceMapping(s string) (string, bool)

func SetServiceMapping added in v1.0.12

func SetServiceMapping(s1, s2 string)

func WriteConfigToFile

func WriteConfigToFile(config *Configure) error

WriteConfigToFile store config

Types

type AccountInfo added in v1.0.39

type AccountInfo struct {
	AccountID   string `json:"AccountId"`
	AccountName string `json:"AccountName"`
}

AccountInfo 表示 ListAccounts 返回的账号信息。

type ApiInfo

type ApiInfo struct {
	Method      string
	ContentType string
	ServiceName string
	ParamTypes  map[string]string
}

type ApiMeta

type ApiMeta struct {
	Request  *Meta
	Response *Meta
}

func (*ApiMeta) GetReqRequired

func (m *ApiMeta) GetReqRequired(pattern string) bool

func (*ApiMeta) GetReqTypeName

func (m *ApiMeta) GetReqTypeName(pattern string) string

type Configure

type Configure struct {
	Current     string                 `json:"current"`
	Profiles    map[string]*Profile    `json:"profiles"`
	EnableColor bool                   `json:"enableColor"`
	SsoSession  map[string]*SsoSession `json:"sso-session"`
}

func LoadConfig

func LoadConfig() *Configure

LoadConfig from CONFIG_FILE_DIR(default ~/.volcengine)

func (*Configure) SetRandomCurrentProfile

func (config *Configure) SetRandomCurrentProfile()

type Context

type Context struct {
	// contains filtered or unexported fields
}

func NewContext

func NewContext() *Context

func (*Context) SetConfig

func (c *Context) SetConfig(cfg *Configure)

type CreateTokenRequest added in v1.0.39

type CreateTokenRequest struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	RefreshToken string `json:"refresh_token,omitempty"`
	DeviceCode   string `json:"device_code,omitempty"`
}

CreateTokenRequest 对应 CreateToken API 的请求参数。

type CreateTokenResponse added in v1.0.39

type CreateTokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	RefreshToken string `json:"refresh_token,omitempty"`
	ExpiresIn    int    `json:"expires_in"`
}

CreateTokenResponse 表示获取 Token 成功后的返回结构。

type DeviceCodeFetcher added in v1.0.39

type DeviceCodeFetcher struct {
	// contains filtered or unexported fields
}

DeviceCodeFetcher 负责基于设备码的 OAuth 授权流程。

func (*DeviceCodeFetcher) GetToken added in v1.0.39

func (f *DeviceCodeFetcher) GetToken() (*SsoTokenCache, error)

GetToken 协调设备码流程、refresh token 刷新及缓存复用。

type Flag

type Flag struct {
	Name string
	// contains filtered or unexported fields
}

func (*Flag) GetValue

func (f *Flag) GetValue() string

func (*Flag) SetValue

func (f *Flag) SetValue(value string)

type FlagSet

type FlagSet struct {
	// contains filtered or unexported fields
}

func NewFlagSet

func NewFlagSet() *FlagSet

func (*FlagSet) AddByName

func (fs *FlagSet) AddByName(name string) (*Flag, error)

func (*FlagSet) AddFlag

func (fs *FlagSet) AddFlag(f *Flag)

func (*FlagSet) GetFlags

func (fs *FlagSet) GetFlags() []*Flag

type GetRoleCredentialsRequest added in v1.0.39

type GetRoleCredentialsRequest struct {
	AccessToken string
	AccountID   string
	RoleName    string
	PageSize    int
	PageNumber  int
}

GetRoleCredentialsRequest 为 GetRoleCredentials 的请求参数封装。

type GetRoleCredentialsResponse added in v1.0.39

type GetRoleCredentialsResponse struct {
	RoleCredentials RoleCredentials
	RequestID       string
}

GetRoleCredentialsResponse 返回临时凭证及请求 ID。

type ListAccountRolesRequest added in v1.0.39

type ListAccountRolesRequest struct {
	AccessToken string
	AccountID   string
	PageSize    int
	PageNumber  int
	NextToken   string
}

ListAccountRolesRequest 为 ListAccountRoles 的请求参数封装。

type ListAccountRolesResponse added in v1.0.39

type ListAccountRolesResponse struct {
	Total      int
	PageNumber int
	PageSize   int
	RoleList   []RoleInfo
	NextToken  string
	RequestID  string
}

ListAccountRolesResponse 返回角色列表及分页信息。

type ListAccountsRequest added in v1.0.39

type ListAccountsRequest struct {
	AccessToken string
	PageSize    int
	PageNumber  int
	NextToken   string
}

ListAccountsRequest 为 ListAccounts 的请求参数封装。

type ListAccountsResponse added in v1.0.39

type ListAccountsResponse struct {
	Total       int
	PageNumber  int
	PageSize    int
	AccountList []AccountInfo
	NextToken   string
	RequestID   string
}

ListAccountsResponse 返回账号列表及分页信息。

type Meta

type Meta struct {
	MetaTypes  map[string]*MetaType `json:"MetaTypes,omitempty"`
	ChildMetas map[string]*Meta     `json:"ChildMetas,omitempty"`
}

func (*Meta) GetReqBody

func (m *Meta) GetReqBody() map[string]interface{}

type MetaInfo

type MetaInfo struct {
	Basic     *[]string
	Structure *map[string]MetaInfo
}

type MetaType

type MetaType struct {
	TypeName string `json:"TypeName,omitempty"`
	TypeOf   string `json:"TypeOf,omitempty"`
	Required bool   `json:"Required,omitempty"`
}

type OAuthAPIError added in v1.0.39

type OAuthAPIError struct {
	StatusCode int
	Response   oauthErrorResponse
	RawBody    string
}

OAuthAPIError 用于承载 OAuth API 非 2xx 响应时的结构化错误信息。

func (*OAuthAPIError) Error added in v1.0.39

func (e *OAuthAPIError) Error() string

type OAuthClient added in v1.0.39

type OAuthClient struct {
	// contains filtered or unexported fields
}

OAuthClient 缓存拼好的 URL 和 HTTP 客户端,避免每次调用重新计算。

func NewOAuthClient added in v1.0.39

func NewOAuthClient(cfg *OAuthClientConfig) *OAuthClient

NewOAuthClient 根据配置创建 OAuthClient,包含默认值和可选覆盖项。

func (*OAuthClient) CreateToken added in v1.0.39

CreateToken 调用 CreateToken API,获取 access/refresh token。

func (*OAuthClient) RegisterClient added in v1.0.39

RegisterClient 调用 RegisterClient API,返回注册后的 client_id/client_secret。

func (*OAuthClient) RevokeToken added in v1.0.39

func (c *OAuthClient) RevokeToken(ctx context.Context, req *RevokeTokenRequest) error

RevokeToken 调用 RevokeToken API 撤销 access/refresh token。

func (*OAuthClient) StartDeviceAuthorization added in v1.0.39

StartDeviceAuthorization 发起设备码授权流程。

type OAuthClientAPI added in v1.0.39

type OAuthClientAPI interface {
	RegisterClient(ctx context.Context, req *RegisterClientRequest) (*RegisterClientResponse, error)
	CreateToken(ctx context.Context, req *CreateTokenRequest) (*CreateTokenResponse, error)
	RevokeToken(ctx context.Context, req *RevokeTokenRequest) error
	StartDeviceAuthorization(ctx context.Context, req *StartDeviceAuthorizationRequest) (*StartDeviceAuthorizationResponse, error)
}

OAuthClientAPI 定义 OAuth 客户端对外暴露的方法集合,便于测试或替换实现。

type OAuthClientConfig added in v1.0.39

type OAuthClientConfig struct {
	// Region 控制使用的区域(默认:cn-beijing)。
	Region string
	// HTTPClient 允许注入自定义 HTTP 客户端(例如代理、超时)。
	HTTPClient *http.Client
}

OAuthClientConfig 用于配置 OAuth 客户端的可选项。

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(args []string) *Parser

func (*Parser) ReadArgs

func (p *Parser) ReadArgs(ctx *Context) ([]string, error)

type PortalAPIError added in v1.0.39

type PortalAPIError struct {
	StatusCode int
	RequestID  string
	Message    string
	RawBody    string
}

PortalAPIError 用于承载 Portal API 非 2xx 响应时的结构化错误信息。

func (*PortalAPIError) Error added in v1.0.39

func (e *PortalAPIError) Error() string

type PortalClient added in v1.0.39

type PortalClient struct {
	// contains filtered or unexported fields
}

PortalClient 封装 CloudIdentity Portal API 调用,集中管理 URL、HTTP 客户端和默认分页参数。

func NewPortalClient added in v1.0.39

func NewPortalClient(cfg *PortalClientConfig) *PortalClient

NewPortalClient 根据配置创建 PortalClient,包含默认值和可选覆盖项。

func (*PortalClient) GetRoleCredentials added in v1.0.39

GetRoleCredentials 使用 Portal 访问令牌换取指定账号和角色的临时凭证。

func (*PortalClient) ListAccountRoles added in v1.0.39

ListAccountRoles 调用 ListAccountRoles API,返回指定账号下当前令牌可用的角色列表。

func (*PortalClient) ListAccounts added in v1.0.39

ListAccounts 调用 ListAccounts API,返回当前访问令牌可见的账号列表。

type PortalClientAPI added in v1.0.39

type PortalClientAPI interface {
	ListAccounts(ctx context.Context, req *ListAccountsRequest) (*ListAccountsResponse, error)
	ListAccountRoles(ctx context.Context, req *ListAccountRolesRequest) (*ListAccountRolesResponse, error)
	GetRoleCredentials(ctx context.Context, req *GetRoleCredentialsRequest) (*GetRoleCredentialsResponse, error)
}

PortalClientAPI 定义 Portal 客户端对外暴露的方法集合,便于测试或替换实现。

type PortalClientConfig added in v1.0.39

type PortalClientConfig struct {
	Region          string       // 区域标识(当前逻辑未使用)
	BaseURL         string       // 自定义 Portal 基础地址
	HTTPClient      *http.Client // 自定义 HTTP 客户端(可注入超时、代理等)
	DefaultPageSize int          // 默认分页大小
}

PortalClientConfig 用于配置 Portal 客户端的可选项,比如自定义 BaseURL、HTTPClient 或分页大小。

type Profile

type Profile struct {
	Name             string `json:"name"`
	Mode             string `json:"mode"`
	AccessKey        string `json:"access-key"`
	SecretKey        string `json:"secret-key"`
	Region           string `json:"region"`
	Endpoint         string `json:"endpoint"`
	EndpointResolver string `json:"endpoint-resolver,omitempty"`
	UseDualStack     *bool  `json:"use-dual-stack,omitempty"`
	SessionToken     string `json:"session-token"`
	DisableSSL       *bool  `json:"disable-ssl"`
	SsoSessionName   string `json:"sso-session-name"`
	AccountId        string `json:"account-id"`
	RoleName         string `json:"role-name"`
	StsExpiration    int64  `json:"sts-expiration"`
}

func (*Profile) String

func (p *Profile) String() string

func (*Profile) ToMap

func (p *Profile) ToMap() map[string]interface{}

type RegisterClientRequest added in v1.0.39

type RegisterClientRequest struct {
	ClientName string   `json:"client_name"`
	ClientType string   `json:"client_type"`
	GrantTypes []string `json:"grant_types,omitempty"`
	Scopes     []string `json:"scopes,omitempty"`
}

RegisterClientRequest 对应 RegisterClient API 的请求参数。

type RegisterClientResponse added in v1.0.39

type RegisterClientResponse struct {
	ClientID              string `json:"client_id"`
	ClientSecret          string `json:"client_secret"`
	ClientIDIssuedAt      int64  `json:"client_id_issued_at,omitempty"`
	ClientSecretExpiresAt int64  `json:"client_secret_expires_at,omitempty"`
}

RegisterClientResponse 表示注册客户端成功后的返回结构。

type ResponseMetadata added in v1.0.39

type ResponseMetadata struct {
	RequestID string `json:"RequestId"`
}

ResponseMetadata 表示 Portal API 返回的基础元信息。

type RevokeTokenRequest added in v1.0.39

type RevokeTokenRequest struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Token        string `json:"token"`
}

RevokeTokenRequest 为撤销 token 的请求参数。

type RoleCredentials added in v1.0.39

type RoleCredentials struct {
	AccessKeyID     string `json:"AccessKeyId"`
	Expiration      int64  `json:"Expiration"`
	SecretAccessKey string `json:"SecretAccessKey"`
	SessionToken    string `json:"sessionToken"`
}

RoleCredentials 表示 GetRoleCredentials 返回的临时凭证信息。

type RoleInfo added in v1.0.39

type RoleInfo struct {
	AccountID string `json:"AccountId"`
	RoleName  string `json:"RoleName"`
}

RoleInfo 表示 ListAccountRoles 返回的角色信息。

type RootSupport

type RootSupport struct {
	SupportSvc    []string
	SupportAction map[string]map[string]*VolcengineMeta
	Versions      map[string]string
	SupportTypes  map[string]map[string]*ApiMeta
}

func NewRootSupport

func NewRootSupport() *RootSupport

func (*RootSupport) GetAllAction

func (r *RootSupport) GetAllAction(svc string) []string

func (*RootSupport) GetAllSvc

func (r *RootSupport) GetAllSvc() []string

func (*RootSupport) GetAllSvcCompatible added in v1.0.15

func (r *RootSupport) GetAllSvcCompatible() []string

func (*RootSupport) GetApiInfo

func (r *RootSupport) GetApiInfo(svc string, action string) *ApiInfo

func (*RootSupport) GetVersion

func (r *RootSupport) GetVersion(svc string) string

func (*RootSupport) IsValidAction

func (r *RootSupport) IsValidAction(svc, action string) bool

func (*RootSupport) IsValidSvc

func (r *RootSupport) IsValidSvc(svc string) bool

type SSOService added in v1.0.39

type SSOService interface {
	SetProfile() error
	Login() error
	Logout() error
	GetAccessToken() (string, error)
	GetRoleCredentials() (*RoleCredentials, error)
}

SSOService 定义对外暴露的 SSO 操作接口。

type SdkClient

type SdkClient struct {
	Config  *volcengine.Config
	Session *session.Session
}

func NewSimpleClient

func NewSimpleClient(ctx *Context) (*SdkClient, error)

NewSimpleClient 鍒涘缓绠€鍗曠殑SDK瀹㈡埛绔?

func (*SdkClient) CallSdk

func (s *SdkClient) CallSdk(info SdkClientInfo, input interface{}) (output *map[string]interface{}, err error)

type SdkClientInfo

type SdkClientInfo struct {
	ServiceName string
	Action      string
	Version     string
	Method      string
	ContentType string
}

type Sso added in v1.0.39

type Sso struct {
	Profile        *Profile
	SsoSessionName string
	StartURL       string
	Region         string
	UseDeviceCode  bool
	NoBrowser      bool
	Scopes         []string
}

Sso 持有 SSO 运行时所需的配置与状态。

func (*Sso) EnsureValidStsToken added in v1.0.39

func (s *Sso) EnsureValidStsToken(ctx *Context) error

EnsureValidStsToken 确保 SSO 模式下的 STS Token 有效(过期或缺失则刷新)。

func (*Sso) GetAccessToken added in v1.0.39

func (s *Sso) GetAccessToken() (string, error)

GetAccessToken 从缓存获取有效的 access token。

func (*Sso) GetRoleCredentials added in v1.0.39

func (s *Sso) GetRoleCredentials() (*RoleCredentials, error)

GetRoleCredentials 获取当前 profile 对应角色的临时凭证。

func (*Sso) Login added in v1.0.39

func (s *Sso) Login() error

Login 执行 SSO 登录并写入缓存。

func (*Sso) Logout added in v1.0.39

func (s *Sso) Logout() error

Logout 撤销缓存 token 并清理本地凭据。

func (*Sso) SetProfile added in v1.0.39

func (s *Sso) SetProfile() error

SetProfile 通过 SSO 登录并写入配置文件。

type SsoSession added in v1.0.39

type SsoSession struct {
	Name               string   `json:"name"`
	StartURL           string   `json:"start-url"`
	Region             string   `json:"region"`
	RegistrationScopes []string `json:"registration-scopes,omitempty"`
}

type SsoTokenCache added in v1.0.39

type SsoTokenCache struct {
	StartURL              string `json:"start_url"`
	SessionName           string `json:"session_name"`
	AccessToken           string `json:"access_token"`
	ExpiresAt             string `json:"expires_at"`
	ClientId              string `json:"client_id"`
	ClientSecret          string `json:"client_secret"`
	ClientIdIssuedAt      int64  `json:"client_id_issued_at,omitempty"`
	ClientSecretExpiresAt int64  `json:"client_secret_expires_at,omitempty"`
	RefreshToken          string `json:"refresh_token,omitempty"`
	Region                string `json:"region"`
}

SsoTokenCache 保存 SSO 访问令牌及客户端凭据的缓存结构。

type StartDeviceAuthorizationRequest added in v1.0.39

type StartDeviceAuthorizationRequest struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	Scopes       []string `json:"scopes,omitempty"`
	PortalUrl    string   `json:"portal_url,omitempty"`
}

StartDeviceAuthorizationRequest 为设备码授权的请求参数。

type StartDeviceAuthorizationResponse added in v1.0.39

type StartDeviceAuthorizationResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval,omitempty"`
}

StartDeviceAuthorizationResponse 表示设备码授权成功后的返回结构。

type StructInfo added in v1.0.15

type StructInfo struct {
	PkgName     string
	ServiceName string
	Version     string
}

type VolcengineMeta

type VolcengineMeta struct {
	ApiInfo  *ApiInfo
	Request  *MetaInfo
	Response *MetaInfo
}

func (*VolcengineMeta) GetRequestParams

func (meta *VolcengineMeta) GetRequestParams(apiMeta *ApiMeta) (params []param)

Jump to

Keyboard shortcuts

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