mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix(region): remove secret level resource
This commit is contained in:
@@ -49,8 +49,6 @@ func init() {
|
||||
cmd.BatchDelete(&options.BaseIdsOptions{})
|
||||
cmd.Perform("remove-all-netifs", &options.BaseIdOptions{})
|
||||
cmd.Perform("probe-isolated-devices", &options.BaseIdOptions{})
|
||||
cmd.Perform("set-secret-level", &compute.HostSetSecretLevelOptions{})
|
||||
cmd.Perform("remove-secret-level", &compute.HostSetSecretLevelOptions{})
|
||||
|
||||
cmd.BatchPerform("enable", &options.BaseIdsOptions{})
|
||||
cmd.BatchPerform("disable", &options.BaseIdsOptions{})
|
||||
|
||||
@@ -419,30 +419,6 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type ImageSetSecretLevelOptions struct {
|
||||
ID string `json:"-"`
|
||||
SecretLevel string `json:"secret_level"`
|
||||
}
|
||||
R(&ImageSetSecretLevelOptions{}, "image-set-secret-level", "Set secret level", func(s *mcclient.ClientSession, args *ImageSetSecretLevelOptions) error {
|
||||
result, err := modules.Images.PerformAction(s, args.ID, "set-secret-level", jsonutils.Marshal(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
type ImageRemoveSecretLevelOptions struct {
|
||||
ID string `json:"-"`
|
||||
}
|
||||
R(&ImageRemoveSecretLevelOptions{}, "image-remove-secret-level", "remove secret level", func(s *mcclient.ClientSession, args *ImageRemoveSecretLevelOptions) error {
|
||||
result, err := modules.Images.PerformAction(s, args.ID, "remove-secret-level", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ImagePublicOptions struct {
|
||||
ID []string `help:"ID or name of image" json:"-"`
|
||||
Scope string `help:"sharing scope" choices:"system|domain|project"`
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package db
|
||||
|
||||
const (
|
||||
SECRET_KEY = "secret_level"
|
||||
)
|
||||
@@ -208,9 +208,6 @@ type DiskConfig struct {
|
||||
|
||||
//swagger:ignore
|
||||
DiskId string `json:"disk_id"`
|
||||
|
||||
//swagger: ignore
|
||||
SecretLevel string `json:"secret_level"`
|
||||
}
|
||||
|
||||
type IsolatedDeviceConfig struct {
|
||||
|
||||
@@ -392,16 +392,6 @@ type HostCreateInput struct {
|
||||
BootMode string `json:"boot_mode"`
|
||||
}
|
||||
|
||||
type HostSetSecretLevelInput struct {
|
||||
// description: 秘密级别
|
||||
SecretLevel string `json:"secret_level"`
|
||||
Force bool `json:"force"`
|
||||
}
|
||||
|
||||
type HostRemoveSecretLevelInput struct {
|
||||
Force bool `json:"force"`
|
||||
}
|
||||
|
||||
type HostUpdateInput struct {
|
||||
apis.EnabledStatusInfrasResourceBaseUpdateInput
|
||||
|
||||
|
||||
@@ -106,17 +106,5 @@ type ImageUpdateStatusInput struct {
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
type ImageSetSecretLevelInput struct {
|
||||
// description: 秘密级别
|
||||
SecretLevel string `json:"secret_level"`
|
||||
}
|
||||
|
||||
type ImageGetClassMetadataInput struct {
|
||||
}
|
||||
|
||||
type ImageGetClassMetadataOutput struct {
|
||||
ClassMetadata map[string]string `json:"class_metadata"`
|
||||
}
|
||||
|
||||
type PerformProbeInput struct {
|
||||
}
|
||||
|
||||
@@ -246,17 +246,11 @@ type MetadataResourceListInput struct {
|
||||
WithMeta *bool `json:"with_meta"`
|
||||
}
|
||||
|
||||
type SecretResourceListInput struct {
|
||||
SecretLevel string
|
||||
}
|
||||
|
||||
type StandaloneAnonResourceListInput struct {
|
||||
ResourceBaseListInput
|
||||
|
||||
MetadataResourceListInput
|
||||
|
||||
SecretResourceListInput
|
||||
|
||||
// 显示所有的资源,包括模拟的资源
|
||||
ShowEmulated *bool `json:"show_emulated" help:"show emulated resources" negative:"do not show emulated resources"`
|
||||
|
||||
|
||||
@@ -133,10 +133,6 @@ type MetadataResourceInfo struct {
|
||||
Metadata map[string]string `json:"metadata"`
|
||||
}
|
||||
|
||||
type SecretResourceInfo struct {
|
||||
SecretLevel string `json:"secret_level"`
|
||||
}
|
||||
|
||||
type StatusDomainLevelUserResourceDetails struct {
|
||||
StatusDomainLevelResourceDetails
|
||||
|
||||
@@ -155,7 +151,6 @@ type StandaloneAnonResourceDetails struct {
|
||||
ResourceBaseDetails
|
||||
|
||||
MetadataResourceInfo
|
||||
SecretResourceInfo
|
||||
}
|
||||
|
||||
type StandaloneResourceDetails struct {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
dbapi "yunion.io/x/onecloud/pkg/apis/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/tagutils"
|
||||
)
|
||||
|
||||
type SSecretResourceBaseModelManager struct{}
|
||||
|
||||
func (secret *SSecretResourceBaseModelManager) ListItemFilter(manager IModelManager, q *sqlchemy.SQuery, input apis.SecretResourceListInput) *sqlchemy.SQuery {
|
||||
if input.SecretLevel == "" {
|
||||
return q
|
||||
}
|
||||
inputTagFilters := tagutils.STagFilters{}
|
||||
tag := tagutils.STag{
|
||||
Key: CLASS_TAG_PREFIX + dbapi.SECRET_KEY,
|
||||
Value: input.SecretLevel,
|
||||
}
|
||||
var tagSet tagutils.TTagSet = []tagutils.STag{tag}
|
||||
inputTagFilters.AddFilter(tagSet)
|
||||
return ObjectIdQueryWithTagFilters(q, "id", manager.Keyword(), inputTagFilters)
|
||||
}
|
||||
|
||||
func (secret *SSecretResourceBaseModelManager) FetchCustomizeColumns(manager IModelManager, userCred mcclient.TokenCredential, objs []interface{}, fields stringutils2.SSortedStrings) []apis.SecretResourceInfo {
|
||||
ret := make([]apis.SecretResourceInfo, len(objs))
|
||||
resIds := make([]string, len(objs))
|
||||
for i := range objs {
|
||||
resIds[i] = GetModelIdstr(objs[i].(IModel))
|
||||
}
|
||||
if fields == nil || fields.Contains("secret_level") {
|
||||
q := Metadata.Query("id", "key", "value").Equals("key", CLASS_TAG_PREFIX+dbapi.SECRET_KEY)
|
||||
metaKeyValues := make(map[string][]SMetadata)
|
||||
err := FetchQueryObjectsByIds(q, "id", resIds, &metaKeyValues)
|
||||
if err != nil {
|
||||
log.Errorf("FetchQueryObjectsByIds metadata fail %s", err)
|
||||
return ret
|
||||
}
|
||||
for i := range objs {
|
||||
if metaList, ok := metaKeyValues[resIds[i]]; ok {
|
||||
ret[i].SecretLevel = metaList[0].Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (secret *SSecretResourceBaseModelManager) SetSecretLevel(ctx context.Context, userCred mcclient.TokenCredential, model *SStandaloneAnonResourceBase, secretLevel string) error {
|
||||
return model.SetClassMetadataAll(ctx, map[string]interface{}{
|
||||
dbapi.SECRET_KEY: secretLevel,
|
||||
}, userCred)
|
||||
}
|
||||
|
||||
func (secret *SSecretResourceBaseModelManager) RemoveSecretLevel(ctx context.Context, userCred mcclient.TokenCredential, model *SStandaloneAnonResourceBase) error {
|
||||
return model.RemoveMetadata(ctx, CLASS_TAG_PREFIX+dbapi.SECRET_KEY, userCred)
|
||||
}
|
||||
@@ -64,7 +64,6 @@ func (model *SStandaloneAnonResourceBase) BeforeInsert() {
|
||||
type SStandaloneAnonResourceBaseManager struct {
|
||||
SResourceBaseManager
|
||||
SMetadataResourceBaseModelManager
|
||||
SSecretResourceBaseModelManager
|
||||
}
|
||||
|
||||
func NewStandaloneAnonResourceBaseManager(
|
||||
@@ -141,8 +140,6 @@ func (manager *SStandaloneAnonResourceBaseManager) ListItemFilter(
|
||||
|
||||
q = manager.SMetadataResourceBaseModelManager.ListItemFilter(manager.GetIModelManager(), q, input.MetadataResourceListInput)
|
||||
|
||||
q = manager.SSecretResourceBaseModelManager.ListItemFilter(manager.GetIModelManager(), q, input.SecretResourceListInput)
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -599,12 +596,10 @@ func (manager *SStandaloneAnonResourceBaseManager) FetchCustomizeColumns(
|
||||
ret := make([]apis.StandaloneAnonResourceDetails, len(objs))
|
||||
upperRet := manager.SResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
metaRet := manager.SMetadataResourceBaseModelManager.FetchCustomizeColumns(manager.GetIModelManager(), userCred, objs, fields)
|
||||
secretRet := manager.SSecretResourceBaseModelManager.FetchCustomizeColumns(manager.GetIModelManager(), userCred, objs, fields)
|
||||
for i := range objs {
|
||||
ret[i] = apis.StandaloneAnonResourceDetails{
|
||||
ResourceBaseDetails: upperRet[i],
|
||||
MetadataResourceInfo: metaRet[i],
|
||||
SecretResourceInfo: secretRet[i],
|
||||
}
|
||||
}
|
||||
return ret
|
||||
|
||||
@@ -5801,31 +5801,6 @@ func (manager *SHostManager) initHostname() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (host *SHost) PerformSetSecretLevel(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.HostSetSecretLevelInput) (jsonutils.JSONObject, error) {
|
||||
if input.SecretLevel == "" {
|
||||
return nil, httperrors.NewMissingParameterError("secret_level")
|
||||
}
|
||||
count, err := host.GetGuestCount()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to GetGuestCount")
|
||||
}
|
||||
if !input.Force && count > 0 {
|
||||
return nil, httperrors.NewForbiddenError("It is forbidden to modify the security level of the host with virtual machines")
|
||||
}
|
||||
return nil, HostManager.SSecretResourceBaseModelManager.SetSecretLevel(ctx, userCred, &host.SStandaloneAnonResourceBase, input.SecretLevel)
|
||||
}
|
||||
|
||||
func (host *SHost) PerformRemoveSecretLevel(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.HostRemoveSecretLevelInput) (jsonutils.JSONObject, error) {
|
||||
count, err := host.GetGuestCount()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to GetGuestCount")
|
||||
}
|
||||
if !input.Force && count > 0 {
|
||||
return nil, httperrors.NewForbiddenError("It is forbidden to modify the security level of the host with virtual machines")
|
||||
}
|
||||
return nil, HostManager.SSecretResourceBaseModelManager.RemoveSecretLevel(ctx, userCred, &host.SStandaloneAnonResourceBase)
|
||||
}
|
||||
|
||||
func (manager *SHostManager) InitializeData() error {
|
||||
return manager.initHostname()
|
||||
}
|
||||
|
||||
@@ -1536,37 +1536,6 @@ func (img *SImage) PerformUpdateStatus(ctx context.Context, userCred mcclient.To
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (img *SImage) PerformSetSecretLevel(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ImageSetSecretLevelInput) (jsonutils.JSONObject, error) {
|
||||
if input.SecretLevel == "" {
|
||||
return nil, httperrors.NewMissingParameterError("secret_level")
|
||||
}
|
||||
err := ImageManager.SSecretResourceBaseModelManager.SetSecretLevel(ctx, userCred, &img.SStandaloneAnonResourceBase, input.SecretLevel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "ImageSyncClassMetadataTask", img, userCred, nil, "", "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
task.ScheduleRun(nil)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (img *SImage) PerformRemoveSecretLevel(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := ImageManager.SSecretResourceBaseModelManager.RemoveSecretLevel(ctx, userCred, &img.SStandaloneAnonResourceBase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "ImageSyncClassMetadataTask", img, userCred, nil, "", "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
task.ScheduleRun(nil)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (img *SImage) PerformSetClassMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformSetClassMetadataInput) (jsonutils.JSONObject, error) {
|
||||
ret, err := img.SStandaloneAnonResourceBase.PerformSetClassMetadata(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
|
||||
@@ -85,22 +85,3 @@ type HostStatusStatisticsOptions struct {
|
||||
HostListOptions
|
||||
options.StatusStatisticsOptions
|
||||
}
|
||||
|
||||
type HostSetSecretLevelOptions struct {
|
||||
options.BaseIdOptions
|
||||
SecretLevel string `json:"secret_level"`
|
||||
Force bool `json:"force"`
|
||||
}
|
||||
|
||||
func (opt *HostSetSecretLevelOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(opt), nil
|
||||
}
|
||||
|
||||
type HostRemoveSecretLevelOptions struct {
|
||||
options.BaseIdOptions
|
||||
Force bool `json:"force"`
|
||||
}
|
||||
|
||||
func (opt *HostRemoveSecretLevelOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(opt), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user