diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index ebf59dfc21..05ea1c51b2 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -549,6 +549,12 @@ func (dispatcher *DBModelDispatcher) List(ctx context.Context, query jsonutils.J log.Errorf("Fail to list items: %s", err) return nil, httperrors.NewGeneralError(err) } + if userCred.HasSystemAdminPrivilege() && dispatcher.modelManager.ListSkipLog(ctx, userCred, query) { + appParams := appsrv.AppContextGetParams(ctx) + if appParams != nil { + appParams.SkipLog = true + } + } return items, nil } @@ -681,6 +687,12 @@ func (dispatcher *DBModelDispatcher) Get(ctx context.Context, idStr string, quer if !isAllow { return nil, httperrors.NewForbiddenError("Not allow to get details") } + if userCred.HasSystemAdminPrivilege() && dispatcher.modelManager.GetSkipLog(ctx, userCred, query) { + appParams := appsrv.AppContextGetParams(ctx) + if appParams != nil { + appParams.SkipLog = true + } + } return getModelItemDetails(dispatcher.modelManager, model, ctx, userCred, query, isHead) } diff --git a/pkg/cloudcommon/db/interface.go b/pkg/cloudcommon/db/interface.go index 2d526dc079..57f4cf7959 100644 --- a/pkg/cloudcommon/db/interface.go +++ b/pkg/cloudcommon/db/interface.go @@ -70,6 +70,8 @@ type IModelManager interface { FetchCreateHeaderData(ctx context.Context, header http.Header) (jsonutils.JSONObject, error) FetchUpdateHeaderData(ctx context.Context, header http.Header) (jsonutils.JSONObject, error) IsCustomizedGetDetailsBody() bool + ListSkipLog(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool + GetSkipLog(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool } type IModel interface { diff --git a/pkg/cloudcommon/db/modelbase.go b/pkg/cloudcommon/db/modelbase.go index c48df26c5d..67d57a789e 100644 --- a/pkg/cloudcommon/db/modelbase.go +++ b/pkg/cloudcommon/db/modelbase.go @@ -185,6 +185,14 @@ func (manager *SModelBaseManager) IsCustomizedGetDetailsBody() bool { return false } +func (manager *SModelBaseManager) ListSkipLog(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return false +} + +func (manager *SModelBaseManager) GetSkipLog(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return false +} + func (model *SModelBase) GetId() string { return "" } diff --git a/pkg/cloudcommon/policy/policy.go b/pkg/cloudcommon/policy/policy.go index 13c5aa4c7d..86bb0dcef2 100644 --- a/pkg/cloudcommon/policy/policy.go +++ b/pkg/cloudcommon/policy/policy.go @@ -322,7 +322,7 @@ func (manager *SPolicyManager) explainPolicyInternal(userCred mcclient.TokenCred if !consts.IsRbacEnabled() { if !isAdmin { return isAdmin, reqStrs, rbacutils.OwnerAllow, nil - } else if isAdmin && userCred.HasSystemAdminPrivelege() { + } else if isAdmin && userCred.HasSystemAdminPrivilege() { return isAdmin, reqStrs, rbacutils.AdminAllow, nil } else { return isAdmin, reqStrs, rbacutils.Deny, httperrors.NewForbiddenError("operation not allowed") @@ -361,7 +361,7 @@ func (manager *SPolicyManager) ExplainRpc(userCred mcclient.TokenCredential, par } func (manager *SPolicyManager) IsAdminCapable(userCred mcclient.TokenCredential) bool { - if !consts.IsRbacEnabled() && userCred.HasSystemAdminPrivelege() { + if !consts.IsRbacEnabled() && userCred.HasSystemAdminPrivilege() { return true } diff --git a/pkg/cloudcommon/policy/token.go b/pkg/cloudcommon/policy/token.go index 47fde62233..feba5052a8 100644 --- a/pkg/cloudcommon/policy/token.go +++ b/pkg/cloudcommon/policy/token.go @@ -13,11 +13,11 @@ type SPolicyTokenCredential struct { mcclient.TokenCredential } -func (self *SPolicyTokenCredential) HasSystemAdminPrivelege() bool { +func (self *SPolicyTokenCredential) HasSystemAdminPrivilege() bool { if consts.IsRbacEnabled() { return PolicyManager.IsAdminCapable(self.TokenCredential) } - return self.TokenCredential.HasSystemAdminPrivelege() + return self.TokenCredential.HasSystemAdminPrivilege() } func (self *SPolicyTokenCredential) IsAdminAllow(service string, resource string, action string, extra ...string) bool { diff --git a/pkg/compute/consts/loadbalancer_const.go b/pkg/compute/consts/loadbalancer_const.go index a35bd28b6a..2fc734aa83 100644 --- a/pkg/compute/consts/loadbalancer_const.go +++ b/pkg/compute/consts/loadbalancer_const.go @@ -255,3 +255,8 @@ const ( LB_CHARGE_TYPE_BY_BANDWIDTH = "bandwidth" LB_CHARGE_TYPE_BY_HOUR = "hour" ) + +const ( + LBAGENT_QUERY_ORIG_KEY = "_orig" + LBAGENT_QUERY_ORIG_VAL = "lbagent" +) diff --git a/pkg/compute/models/loadbalancer_common.go b/pkg/compute/models/loadbalancer_common.go index 1c9bf411a9..5e6ff57abb 100644 --- a/pkg/compute/models/loadbalancer_common.go +++ b/pkg/compute/models/loadbalancer_common.go @@ -7,6 +7,7 @@ import ( "yunion.io/x/sqlchemy" "yunion.io/x/onecloud/pkg/cloudcommon/db" + "yunion.io/x/onecloud/pkg/compute/consts" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -28,3 +29,24 @@ type SLoadbalancerNotifier struct{} func (n *SLoadbalancerNotifier) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) { return } + +type SLoadbalancerLogSkipper struct{} + +func (lls SLoadbalancerLogSkipper) skipLog(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + data, ok := query.(*jsonutils.JSONDict) + if !ok { + return false + } + if val, _ := data.GetString(consts.LBAGENT_QUERY_ORIG_KEY); val != consts.LBAGENT_QUERY_ORIG_VAL { + return false + } + return true +} + +func (lls SLoadbalancerLogSkipper) ListSkipLog(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return lls.skipLog(ctx, userCred, query) +} + +func (lls SLoadbalancerLogSkipper) GetSkipLog(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return lls.skipLog(ctx, userCred, query) +} diff --git a/pkg/compute/models/loadbalanceracls.go b/pkg/compute/models/loadbalanceracls.go index 478b51c37f..563131253d 100644 --- a/pkg/compute/models/loadbalanceracls.go +++ b/pkg/compute/models/loadbalanceracls.go @@ -83,6 +83,7 @@ func (aclEntries *SLoadbalancerAclEntries) Validate(data *jsonutils.JSONDict) er } type SLoadbalancerAclManager struct { + SLoadbalancerLogSkipper db.SSharableVirtualResourceBaseManager } diff --git a/pkg/compute/models/loadbalanceragents.go b/pkg/compute/models/loadbalanceragents.go index e9d4ff7b2e..f8b955c0a4 100644 --- a/pkg/compute/models/loadbalanceragents.go +++ b/pkg/compute/models/loadbalanceragents.go @@ -19,6 +19,7 @@ import ( ) type SLoadbalancerAgentManager struct { + SLoadbalancerLogSkipper db.SStandaloneResourceBaseManager } @@ -78,9 +79,10 @@ type SLoadbalancerAgentParamsHaproxy struct { } type SLoadbalancerAgentParamsTelegraf struct { - InfluxDbOutputUrl string - InfluxDbOutputName string - HaproxyInputInterval int + InfluxDbOutputUrl string + InfluxDbOutputName string + InfluxDbOutputUnsafeSsl bool + HaproxyInputInterval int } type SLoadbalancerAgentParams struct { @@ -525,6 +527,7 @@ listen stats [[outputs.influxdb]] urls = ["{{ .telegraf.influx_db_output_url }}"] database = "{{ .telegraf.influx_db_output_name }}" + insecure_skip_verify = {{ .telegraf.influx_db_output_unsafe_ssl }} [[inputs.haproxy]] interval = "{{ .telegraf.haproxy_input_interval }}s" diff --git a/pkg/compute/models/loadbalancerbackendgroups.go b/pkg/compute/models/loadbalancerbackendgroups.go index e9b8827845..f917d70d6b 100644 --- a/pkg/compute/models/loadbalancerbackendgroups.go +++ b/pkg/compute/models/loadbalancerbackendgroups.go @@ -21,6 +21,7 @@ import ( ) type SLoadbalancerBackendGroupManager struct { + SLoadbalancerLogSkipper db.SVirtualResourceBaseManager } diff --git a/pkg/compute/models/loadbalancerbackends.go b/pkg/compute/models/loadbalancerbackends.go index 95548a8568..473f264f36 100644 --- a/pkg/compute/models/loadbalancerbackends.go +++ b/pkg/compute/models/loadbalancerbackends.go @@ -20,6 +20,7 @@ import ( ) type SLoadbalancerBackendManager struct { + SLoadbalancerLogSkipper db.SVirtualResourceBaseManager } diff --git a/pkg/compute/models/loadbalancercertificates.go b/pkg/compute/models/loadbalancercertificates.go index 81e12b6ec9..ba80c444ec 100644 --- a/pkg/compute/models/loadbalancercertificates.go +++ b/pkg/compute/models/loadbalancercertificates.go @@ -26,6 +26,7 @@ import ( ) type SLoadbalancerCertificateManager struct { + SLoadbalancerLogSkipper db.SVirtualResourceBaseManager } diff --git a/pkg/compute/models/loadbalancerlistenerrules.go b/pkg/compute/models/loadbalancerlistenerrules.go index 4b2f9f1d7d..700d636bd1 100644 --- a/pkg/compute/models/loadbalancerlistenerrules.go +++ b/pkg/compute/models/loadbalancerlistenerrules.go @@ -20,6 +20,7 @@ import ( ) type SLoadbalancerListenerRuleManager struct { + SLoadbalancerLogSkipper db.SVirtualResourceBaseManager } diff --git a/pkg/compute/models/loadbalancerlisteners.go b/pkg/compute/models/loadbalancerlisteners.go index 705be1d2e1..4580ae9d64 100644 --- a/pkg/compute/models/loadbalancerlisteners.go +++ b/pkg/compute/models/loadbalancerlisteners.go @@ -22,6 +22,7 @@ import ( ) type SLoadbalancerListenerManager struct { + SLoadbalancerLogSkipper db.SVirtualResourceBaseManager } diff --git a/pkg/compute/models/loadbalancers.go b/pkg/compute/models/loadbalancers.go index 2e0e8d723f..d542079431 100644 --- a/pkg/compute/models/loadbalancers.go +++ b/pkg/compute/models/loadbalancers.go @@ -21,6 +21,7 @@ import ( ) type SLoadbalancerManager struct { + SLoadbalancerLogSkipper db.SVirtualResourceBaseManager } diff --git a/pkg/hostimage/host_image_service.go b/pkg/hostimage/host_image_service.go index 1dd1855af3..4b6d1b4e62 100644 --- a/pkg/hostimage/host_image_service.go +++ b/pkg/hostimage/host_image_service.go @@ -71,7 +71,7 @@ func getSnapshotPath(diskId, snapshotId string) string { func inputCheck(ctx context.Context) (string, error) { var userCred = auth.FetchUserCredential(ctx, nil) - if !userCred.HasSystemAdminPrivelege() { + if !userCred.HasSystemAdminPrivilege() { return "", httperrors.NewForbiddenError("System admin only") } diff --git a/pkg/lbagent/api.go b/pkg/lbagent/api.go index d55468c429..1d77ecb439 100644 --- a/pkg/lbagent/api.go +++ b/pkg/lbagent/api.go @@ -6,8 +6,10 @@ import ( "sync" "time" + "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/compute/consts" agentmodels "yunion.io/x/onecloud/pkg/lbagent/models" agentutils "yunion.io/x/onecloud/pkg/lbagent/utils" "yunion.io/x/onecloud/pkg/mcclient" @@ -71,7 +73,9 @@ func (h *ApiHelper) adminClientSession(ctx context.Context) *mcclient.ClientSess func (h *ApiHelper) agentPeekOnce(ctx context.Context) (*models.LoadbalancerAgent, error) { s := h.adminClientSession(ctx) - data, err := modules.LoadbalancerAgents.Get(s, h.opts.ApiLbagentId, nil) + params := jsonutils.NewDict() + params.Set(consts.LBAGENT_QUERY_ORIG_KEY, jsonutils.NewString(consts.LBAGENT_QUERY_ORIG_VAL)) + data, err := modules.LoadbalancerAgents.Get(s, h.opts.ApiLbagentId, params) if err != nil { err := fmt.Errorf("agent get error: %s", err) return nil, err diff --git a/pkg/lbagent/models/agentparams.go b/pkg/lbagent/models/agentparams.go index 6f8d51ea18..91032e1060 100644 --- a/pkg/lbagent/models/agentparams.go +++ b/pkg/lbagent/models/agentparams.go @@ -55,9 +55,10 @@ func NewAgentParams(agent *models.LoadbalancerAgent) (*AgentParams, error) { "log_normal": agent.Params.Haproxy.LogNormal, } dataTelegraf := map[string]interface{}{ - "influx_db_output_url": agent.Params.Telegraf.InfluxDbOutputUrl, - "influx_db_output_name": agent.Params.Telegraf.InfluxDbOutputName, - "haproxy_input_interval": agent.Params.Telegraf.HaproxyInputInterval, + "influx_db_output_url": agent.Params.Telegraf.InfluxDbOutputUrl, + "influx_db_output_name": agent.Params.Telegraf.InfluxDbOutputName, + "influx_db_output_unsafe_ssl": agent.Params.Telegraf.InfluxDbOutputUnsafeSsl, + "haproxy_input_interval": agent.Params.Telegraf.HaproxyInputInterval, } data := map[string]map[string]interface{}{ "agent": dataAgent, diff --git a/pkg/lbagent/models/corpus.go b/pkg/lbagent/models/corpus.go index 04f539ab03..799d06400a 100644 --- a/pkg/lbagent/models/corpus.go +++ b/pkg/lbagent/models/corpus.go @@ -24,6 +24,7 @@ type LoadbalancerCorpus struct { func NewEmptyLoadbalancerCorpus() *LoadbalancerCorpus { return &LoadbalancerCorpus{ + CorpusVersion: CORPUS_VERSION, ModelSets: NewModelSets(), ModelSetsMaxUpdatedAt: NewModelSetsMaxUpdatedAt(), } diff --git a/pkg/lbagent/models/reflect.go b/pkg/lbagent/models/reflect.go index 0d129638ea..6060aacb66 100644 --- a/pkg/lbagent/models/reflect.go +++ b/pkg/lbagent/models/reflect.go @@ -10,6 +10,7 @@ import ( "yunion.io/x/pkg/util/timeutils" "yunion.io/x/pkg/utils" + "yunion.io/x/onecloud/pkg/compute/consts" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/models" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -105,6 +106,7 @@ func GetModels(opts *GetModelsOptions) error { if err != nil { return fmt.Errorf("%s: making list params: %s", manKeyPlural, err) } + params.Set(consts.LBAGENT_QUERY_ORIG_KEY, jsonutils.NewString(consts.LBAGENT_QUERY_ORIG_VAL)) entriesJson := []jsonutils.JSONObject{} for { diff --git a/pkg/mcclient/models/loadbalancers.go b/pkg/mcclient/models/loadbalancers.go index 2c1b2cc6be..603f0799c8 100644 --- a/pkg/mcclient/models/loadbalancers.go +++ b/pkg/mcclient/models/loadbalancers.go @@ -195,9 +195,10 @@ type LoadbalancerAgentParamsHaproxy struct { } type LoadbalancerAgentParamsTelegraf struct { - InfluxDbOutputUrl string - InfluxDbOutputName string - HaproxyInputInterval int + InfluxDbOutputUrl string + InfluxDbOutputName string + InfluxDbOutputUnsafeSsl bool + HaproxyInputInterval int } type LoadbalancerAgentParams struct { diff --git a/pkg/mcclient/modules/base.go b/pkg/mcclient/modules/base.go index c082c42eb2..d3c2ff35b1 100644 --- a/pkg/mcclient/modules/base.go +++ b/pkg/mcclient/modules/base.go @@ -34,7 +34,7 @@ func NewBaseManager(serviceType, endpointType, version string, columns, adminCol func (this *BaseManager) GetColumns(session *mcclient.ClientSession) []string { cols := this.columns - if session.HasSystemAdminPrivelege() && len(this.adminColumns) > 0 { + if session.HasSystemAdminPrivilege() && len(this.adminColumns) > 0 { cols = append(cols, this.adminColumns...) } return cols diff --git a/pkg/mcclient/options/loadbalanceracls.go b/pkg/mcclient/options/loadbalanceracls.go index 3064116497..4f1bbcbb6d 100644 --- a/pkg/mcclient/options/loadbalanceracls.go +++ b/pkg/mcclient/options/loadbalanceracls.go @@ -63,7 +63,7 @@ type LoadbalancerAclCreateOptions struct { } type LoadbalancerAclGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerAclListOptions struct { diff --git a/pkg/mcclient/options/loadbalanceragents.go b/pkg/mcclient/options/loadbalanceragents.go index ab3b230818..a35b48651a 100644 --- a/pkg/mcclient/options/loadbalanceragents.go +++ b/pkg/mcclient/options/loadbalanceragents.go @@ -10,6 +10,7 @@ import ( type LoadbalancerAgentParamsOptions struct { KeepalivedConfTmpl string HaproxyConfTmpl string + TelegrafConfTmpl string VrrpPriority *int // required VrrpVirtualRouterId *int // required @@ -25,9 +26,10 @@ type LoadbalancerAgentParamsOptions struct { HaproxyLogTcp string `choices:"true|false"` HaproxyLogNormal string `choices:"true|false"` - TelegrafInfluxDbOutputUrl string - TelegrafInfluxDbOutputName string - TelegrafHaproxyInputInterval int + TelegrafInfluxDbOutputUrl string + TelegrafInfluxDbOutputName string + TelegrafInfluxDbOutputUnsafeSsl *bool + TelegrafHaproxyInputInterval int } func (opts *LoadbalancerAgentParamsOptions) setPrefixedParams(params *jsonutils.JSONDict, pref string) { @@ -82,11 +84,11 @@ type LoadbalancerAgentListOptions struct { } type LoadbalancerAgentGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerAgentUpdateOptions struct { - ID string + ID string `json:-` Name string HbTimeout *int @@ -101,15 +103,15 @@ type LoadbalancerAgentUpdateOptions struct { } type LoadbalancerAgentDeleteOptions struct { - ID string + ID string `json:-` } type LoadbalancerAgentActionHbOptions struct { - ID string + ID string `json:-` } type LoadbalancerAgentActionPatchParamsOptions struct { - ID string + ID string `json:-` LoadbalancerAgentParamsOptions } diff --git a/pkg/mcclient/options/loadbalancerbackendgroups.go b/pkg/mcclient/options/loadbalancerbackendgroups.go index 1c33e15ff8..0553ab46da 100644 --- a/pkg/mcclient/options/loadbalancerbackendgroups.go +++ b/pkg/mcclient/options/loadbalancerbackendgroups.go @@ -94,16 +94,16 @@ func (opts *LoadbalancerBackendGroupCreateOptions) Params() (*jsonutils.JSONDict } type LoadbalancerBackendGroupGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerBackendGroupUpdateOptions struct { - ID string + ID string `json:-` Name string } type LoadbalancerBackendGroupDeleteOptions struct { - ID string + ID string `json:-` } type LoadbalancerBackendGroupListOptions struct { diff --git a/pkg/mcclient/options/loadbalancerbackends.go b/pkg/mcclient/options/loadbalancerbackends.go index 7e9f66527a..b87fe04c45 100644 --- a/pkg/mcclient/options/loadbalancerbackends.go +++ b/pkg/mcclient/options/loadbalancerbackends.go @@ -19,7 +19,7 @@ type LoadbalancerBackendListOptions struct { } type LoadbalancerBackendUpdateOptions struct { - ID string + ID string `json:-` Name string Weight *int @@ -27,9 +27,9 @@ type LoadbalancerBackendUpdateOptions struct { } type LoadbalancerBackendGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerBackendDeleteOptions struct { - ID string + ID string `json:-` } diff --git a/pkg/mcclient/options/loadbalancercertificates.go b/pkg/mcclient/options/loadbalancercertificates.go index a88a441952..d943452521 100644 --- a/pkg/mcclient/options/loadbalancercertificates.go +++ b/pkg/mcclient/options/loadbalancercertificates.go @@ -56,11 +56,11 @@ func (opts *LoadbalancerCertificateCreateOptions) Params() (*jsonutils.JSONDict, } type LoadbalancerCertificateGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerCertificateDeleteOptions struct { - ID string + ID string `json:-` } type LoadbalancerCertificateListOptions struct { @@ -72,7 +72,7 @@ type LoadbalancerCertificateListOptions struct { } type LoadbalancerCertificateUpdateOptions struct { - ID string + ID string `json:-` Name string Cert string `json:"-" help:"path to certificate file"` diff --git a/pkg/mcclient/options/loadbalancerlistenerrules.go b/pkg/mcclient/options/loadbalancerlistenerrules.go index 352450dfd5..b1d8899669 100644 --- a/pkg/mcclient/options/loadbalancerlistenerrules.go +++ b/pkg/mcclient/options/loadbalancerlistenerrules.go @@ -18,21 +18,21 @@ type LoadbalancerListenerRuleListOptions struct { } type LoadbalancerListenerRuleUpdateOptions struct { - ID string + ID string `json:-` Name string BackendGroup string } type LoadbalancerListenerRuleGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerListenerRuleDeleteOptions struct { - ID string + ID string `json:-` } type LoadbalancerListenerRuleActionStatusOptions struct { - ID string + ID string `json:-` Status string `choices:"enabled|disabled"` } diff --git a/pkg/mcclient/options/loadbalancerlisteners.go b/pkg/mcclient/options/loadbalancerlisteners.go index 567409e549..ee1daa932d 100644 --- a/pkg/mcclient/options/loadbalancerlisteners.go +++ b/pkg/mcclient/options/loadbalancerlisteners.go @@ -102,7 +102,7 @@ type LoadbalancerListenerListOptions struct { } type LoadbalancerListenerUpdateOptions struct { - ID string + ID string `json:-` Name string BackendGroup string @@ -150,18 +150,18 @@ type LoadbalancerListenerUpdateOptions struct { } type LoadbalancerListenerGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerListenerDeleteOptions struct { - ID string + ID string `json:-` } type LoadbalancerListenerActionStatusOptions struct { - ID string + ID string `json:-` Status string `choices:"enabled|disabled"` } type LoadbalancerListenerActionSyncStatusOptions struct { - ID string + ID string `json:-` } diff --git a/pkg/mcclient/options/loadbalancers.go b/pkg/mcclient/options/loadbalancers.go index 0e27c8cfb6..9aa01b3db1 100644 --- a/pkg/mcclient/options/loadbalancers.go +++ b/pkg/mcclient/options/loadbalancers.go @@ -12,22 +12,22 @@ type LoadbalancerCreateOptions struct { } type LoadbalancerGetOptions struct { - ID string + ID string `json:-` } type LoadbalancerUpdateOptions struct { - ID string + ID string `json:-` Name string BackendGroup string } type LoadbalancerDeleteOptions struct { - ID string + ID string `json:-` } type LoadbalancerPurgeOptions struct { - ID string + ID string `json:-` } type LoadbalancerListOptions struct { @@ -41,10 +41,10 @@ type LoadbalancerListOptions struct { } type LoadbalancerActionStatusOptions struct { - ID string + ID string `json:-` Status string `choices:"enabled|disabled"` } type LoadbalancerActionSyncStatusOptions struct { - ID string + ID string `json:-` } diff --git a/pkg/mcclient/session.go b/pkg/mcclient/session.go index 4f09e8b03d..46b5c0e42d 100644 --- a/pkg/mcclient/session.go +++ b/pkg/mcclient/session.go @@ -218,8 +218,8 @@ func (this *ClientSession) ParseJSONResponse(resp *http.Response, err error) (ht return httputils.ParseJSONResponse(resp, err, this.client.debug) } -func (this *ClientSession) HasSystemAdminPrivelege() bool { - return this.token.HasSystemAdminPrivelege() +func (this *ClientSession) HasSystemAdminPrivilege() bool { + return this.token.HasSystemAdminPrivilege() } func (this *ClientSession) GetRegion() string { diff --git a/pkg/mcclient/token.go b/pkg/mcclient/token.go index a2a0ab7ad8..df26bea4a8 100644 --- a/pkg/mcclient/token.go +++ b/pkg/mcclient/token.go @@ -45,7 +45,7 @@ type TokenCredential interface { IsValid() bool ValidDuration() time.Duration // IsAdmin() bool - HasSystemAdminPrivelege() bool + HasSystemAdminPrivilege() bool IsAdminAllow(service string, resource string, action string, extra ...string) bool GetRegions() []string diff --git a/pkg/mcclient/token2.go b/pkg/mcclient/token2.go index d5188353ad..97b85b56d3 100644 --- a/pkg/mcclient/token2.go +++ b/pkg/mcclient/token2.go @@ -130,12 +130,12 @@ func (this *TokenCredentialV2) GetRegions() []string { return this.ServiceCatalog.getRegions() } -func (this *TokenCredentialV2) HasSystemAdminPrivelege() bool { +func (this *TokenCredentialV2) HasSystemAdminPrivilege() bool { return this.IsAdmin() && this.GetTenantName() == "system" } func (this *TokenCredentialV2) IsAdminAllow(service string, resource string, action string, extra ...string) bool { - return this.HasSystemAdminPrivelege() + return this.HasSystemAdminPrivilege() } func (this *TokenCredentialV2) GetServiceURL(service, region, zone, endpointType string) (string, error) { diff --git a/pkg/mcclient/token3.go b/pkg/mcclient/token3.go index c7d063fede..26c46dbc70 100644 --- a/pkg/mcclient/token3.go +++ b/pkg/mcclient/token3.go @@ -135,12 +135,12 @@ func (this *TokenCredentialV3) IsAdmin() bool { return false } -func (this *TokenCredentialV3) HasSystemAdminPrivelege() bool { +func (this *TokenCredentialV3) HasSystemAdminPrivilege() bool { return this.IsAdmin() && this.GetTenantName() == "system" } func (this *TokenCredentialV3) IsAdminAllow(service string, resource string, action string, extra ...string) bool { - return this.HasSystemAdminPrivelege() + return this.HasSystemAdminPrivilege() } func (this *TokenCredentialV3) GetRegions() []string { diff --git a/pkg/mcclient/tokensimple.go b/pkg/mcclient/tokensimple.go index 15a8badbfb..26d761b181 100644 --- a/pkg/mcclient/tokensimple.go +++ b/pkg/mcclient/tokensimple.go @@ -84,12 +84,12 @@ func (self *SSimpleToken) IsAdmin() bool { return false } -func (self *SSimpleToken) HasSystemAdminPrivelege() bool { +func (self *SSimpleToken) HasSystemAdminPrivilege() bool { return self.IsAdmin() && self.Project == "system" } func (this *SSimpleToken) IsAdminAllow(service string, resource string, action string, extra ...string) bool { - return this.HasSystemAdminPrivelege() + return this.HasSystemAdminPrivilege() } func (self *SSimpleToken) GetRegions() []string {