2022-01-06 10:07:21 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you 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.
|
|
|
|
|
2021-11-17 12:13:10 +08:00
|
|
|
package util
|
|
|
|
|
2022-08-05 16:28:35 +08:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
2023-05-16 17:41:22 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2022-08-05 16:28:35 +08:00
|
|
|
)
|
2022-08-04 11:04:34 +08:00
|
|
|
|
2021-12-03 17:15:33 +08:00
|
|
|
// Meta Prefix consts
|
2021-11-17 12:13:10 +08:00
|
|
|
const (
|
2022-08-11 12:12:38 +08:00
|
|
|
MetaStoreTypeEtcd = "etcd"
|
|
|
|
MetaStoreTypeMysql = "mysql"
|
|
|
|
|
2021-11-17 12:13:10 +08:00
|
|
|
SegmentMetaPrefix = "queryCoord-segmentMeta"
|
|
|
|
ChangeInfoMetaPrefix = "queryCoord-sealedSegmentChangeInfo"
|
2022-08-25 15:48:54 +08:00
|
|
|
|
2023-01-04 19:37:36 +08:00
|
|
|
// FlushedSegmentPrefix TODO @cai.zhang: remove this
|
2022-08-25 15:48:54 +08:00
|
|
|
FlushedSegmentPrefix = "flushed-segment"
|
2023-01-04 19:37:36 +08:00
|
|
|
// HandoffSegmentPrefix TODO @cai.zhang: remove this
|
2022-06-29 23:26:19 +08:00
|
|
|
HandoffSegmentPrefix = "querycoord-handoff"
|
2023-01-04 19:37:36 +08:00
|
|
|
// SegmentReferPrefix TODO @cai.zhang: remove this
|
|
|
|
SegmentReferPrefix = "segmentRefer"
|
2022-08-25 15:48:54 +08:00
|
|
|
|
|
|
|
SegmentIndexPrefix = "segment-index"
|
|
|
|
FieldIndexPrefix = "field-index"
|
|
|
|
|
|
|
|
HeaderAuthorize = "authorization"
|
2022-04-11 19:49:34 +08:00
|
|
|
// HeaderSourceID identify requests from Milvus members and client requests
|
|
|
|
HeaderSourceID = "sourceId"
|
|
|
|
// MemberCredID id for Milvus members (data/index/query node/coord component)
|
|
|
|
MemberCredID = "@@milvus-member@@"
|
|
|
|
CredentialSeperator = ":"
|
2022-04-20 13:03:40 +08:00
|
|
|
UserRoot = "root"
|
|
|
|
DefaultRootPassword = "Milvus"
|
2022-08-04 11:04:34 +08:00
|
|
|
DefaultTenant = ""
|
|
|
|
RoleAdmin = "admin"
|
|
|
|
RolePublic = "public"
|
|
|
|
|
2022-08-05 16:28:35 +08:00
|
|
|
PrivilegeWord = "Privilege"
|
2022-08-15 16:40:48 +08:00
|
|
|
AnyWord = "*"
|
2023-05-19 12:51:23 +08:00
|
|
|
|
|
|
|
IdentifierKey = "identifier"
|
2021-11-17 12:13:10 +08:00
|
|
|
)
|
2022-08-04 11:04:34 +08:00
|
|
|
|
2022-09-21 20:16:51 +08:00
|
|
|
const (
|
|
|
|
// ParamsKeyToParse is the key of the param to build index.
|
2023-05-16 17:41:22 +08:00
|
|
|
ParamsKeyToParse = common.IndexParamsKey
|
2022-09-21 20:16:51 +08:00
|
|
|
)
|
|
|
|
|
2022-08-15 16:40:48 +08:00
|
|
|
var (
|
|
|
|
DefaultRoles = []string{RoleAdmin, RolePublic}
|
2022-08-04 11:04:34 +08:00
|
|
|
|
2022-08-15 16:40:48 +08:00
|
|
|
ObjectPrivileges = map[string][]string{
|
2022-08-04 11:04:34 +08:00
|
|
|
commonpb.ObjectType_Collection.String(): {
|
2022-08-05 16:28:35 +08:00
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeLoad.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeRelease.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeCompaction.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeInsert.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeDelete.String()),
|
|
|
|
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeGetStatistics.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeCreateIndex.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeIndexDetail.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeDropIndex.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeSearch.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeFlush.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeQuery.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeLoadBalance.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeImport.String()),
|
2023-02-22 20:37:45 +08:00
|
|
|
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeGetLoadingProgress.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeGetLoadState.String()),
|
2022-08-04 11:04:34 +08:00
|
|
|
},
|
|
|
|
commonpb.ObjectType_Global.String(): {
|
2022-08-05 16:28:35 +08:00
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeAll.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeCreateCollection.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeDropCollection.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeDescribeCollection.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeShowCollections.String()),
|
|
|
|
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeCreateOwnership.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeDropOwnership.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeSelectOwnership.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeManageOwnership.String()),
|
2023-02-10 10:54:33 +08:00
|
|
|
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeCreateResourceGroup.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeDropResourceGroup.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeDescribeResourceGroup.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeListResourceGroups.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeTransferReplica.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeTransferNode.String()),
|
2022-08-05 16:28:35 +08:00
|
|
|
},
|
|
|
|
commonpb.ObjectType_User.String(): {
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeUpdateUser.String()),
|
|
|
|
MetaStore2API(commonpb.ObjectPrivilege_PrivilegeSelectUser.String()),
|
2022-08-04 11:04:34 +08:00
|
|
|
},
|
|
|
|
}
|
2022-08-15 16:40:48 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// StringSet convert array to map for conveniently check if the array contains an element
|
|
|
|
func StringSet(strings []string) map[string]struct{} {
|
|
|
|
stringsMap := make(map[string]struct{})
|
|
|
|
for _, str := range strings {
|
|
|
|
stringsMap[str] = struct{}{}
|
|
|
|
}
|
|
|
|
return stringsMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func StringList(stringMap map[string]struct{}) []string {
|
|
|
|
strs := make([]string, 0, len(stringMap))
|
|
|
|
for k := range stringMap {
|
|
|
|
strs = append(strs, k)
|
|
|
|
}
|
|
|
|
return strs
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
2022-08-05 16:28:35 +08:00
|
|
|
// MetaStore2API convert meta-store's privilege name to api's
|
|
|
|
// example: PrivilegeAll -> All
|
|
|
|
func MetaStore2API(name string) string {
|
|
|
|
return name[strings.Index(name, PrivilegeWord)+len(PrivilegeWord):]
|
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func PrivilegeNameForAPI(name string) string {
|
2022-08-05 16:28:35 +08:00
|
|
|
_, ok := commonpb.ObjectPrivilege_value[name]
|
2022-08-04 11:04:34 +08:00
|
|
|
if !ok {
|
|
|
|
return ""
|
|
|
|
}
|
2022-08-05 16:28:35 +08:00
|
|
|
return MetaStore2API(name)
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
2022-08-05 16:28:35 +08:00
|
|
|
func PrivilegeNameForMetastore(name string) string {
|
|
|
|
dbPrivilege := PrivilegeWord + name
|
|
|
|
_, ok := commonpb.ObjectPrivilege_value[dbPrivilege]
|
|
|
|
if !ok {
|
2022-08-04 11:04:34 +08:00
|
|
|
return ""
|
|
|
|
}
|
2022-08-05 16:28:35 +08:00
|
|
|
return dbPrivilege
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-08-15 16:40:48 +08:00
|
|
|
|
|
|
|
func IsAnyWord(word string) bool {
|
|
|
|
return word == AnyWord
|
|
|
|
}
|