From c7952084b94120bc40b8470686e51389b3417d84 Mon Sep 17 00:00:00 2001 From: ioito Date: Sat, 8 Oct 2022 18:20:25 +0800 Subject: [PATCH] fix(region): add project tag short desc --- pkg/cloudcommon/db/metadata.go | 13 ++++++++++++- pkg/cloudcommon/db/virtualresource.go | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/cloudcommon/db/metadata.go b/pkg/cloudcommon/db/metadata.go index 1882a3f713..7813e74f0b 100644 --- a/pkg/cloudcommon/db/metadata.go +++ b/pkg/cloudcommon/db/metadata.go @@ -692,6 +692,17 @@ func IsMetadataKeySystemAdmin(key string) bool { return strings.HasPrefix(key, SYSTEM_ADMIN_PREFIX) } +func IsMetadataKeyPrivateKey(key string) bool { + for _, k := range []string{"admin", "project"} { + for _, v := range []string{"ssh-private-key", "ssh-public-key"} { + if key == fmt.Sprintf("%s-%s", k, v) { + return true + } + } + } + return strings.HasPrefix(key, SYSTEM_ADMIN_PREFIX) +} + func IsMetadataKeySysTag(key string) bool { return strings.HasPrefix(key, SYS_TAG_PREFIX) } @@ -701,7 +712,7 @@ func (manager *SMetadataManager) GetSysadminKey(key string) string { } func IsMetadataKeyVisiable(key string) bool { - return !(IsMetadataKeySysTag(key) || IsMetadataKeySystemAdmin(key)) + return !(IsMetadataKeySysTag(key) || IsMetadataKeySystemAdmin(key) || IsMetadataKeyPrivateKey(key)) } func GetVisiableMetadata(ctx context.Context, model IStandaloneModel, userCred mcclient.TokenCredential) (map[string]string, error) { diff --git a/pkg/cloudcommon/db/virtualresource.go b/pkg/cloudcommon/db/virtualresource.go index 012d609c19..95dfc313ae 100644 --- a/pkg/cloudcommon/db/virtualresource.go +++ b/pkg/cloudcommon/db/virtualresource.go @@ -608,6 +608,8 @@ func (model *SVirtualResourceBase) GetShortDesc(ctx context.Context) *jsonutils. tc, _ := TenantCacheManager.FetchTenantById(ctx, model.ProjectId) if tc != nil { desc.Add(jsonutils.NewString(tc.GetName()), "owner_tenant") + metadata, _ := GetVisiableMetadata(ctx, tc, nil) + desc.Set("project_tags", jsonutils.Marshal(metadata)) } return desc }