mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
fix: [GoSDK] Pass base64 passwd content instead of raw data (#40268)
Related to #40261 Also add some options for create collection options and refine some behavior Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
bc8e02df44
commit
0c74e409df
@ -68,8 +68,12 @@ func (gi GenericIndex) Params() map[string]string {
|
||||
return m
|
||||
}
|
||||
|
||||
func (gi GenericIndex) WithMetricType(metricType MetricType) {
|
||||
gi.baseIndex.metricType = metricType
|
||||
}
|
||||
|
||||
// NewGenericIndex create generic index instance
|
||||
func NewGenericIndex(name string, params map[string]string) Index {
|
||||
func NewGenericIndex(name string, params map[string]string) GenericIndex {
|
||||
return GenericIndex{
|
||||
baseIndex: baseIndex{
|
||||
name: name,
|
||||
|
||||
@ -154,6 +154,67 @@ func ExampleClient_CreateCollection_ttl() {
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleClient_CreateCollection_quickSetup() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
collectionName := `quick_setup_1`
|
||||
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
|
||||
Address: milvusAddr,
|
||||
})
|
||||
if err != nil {
|
||||
// handle err
|
||||
}
|
||||
|
||||
err = cli.CreateCollection(ctx, milvusclient.SimpleCreateCollectionOptions(collectionName, 512))
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleClient_CreateCollection_quickSetupWithIndexParams() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
collectionName := `quick_setup_2`
|
||||
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
|
||||
Address: milvusAddr,
|
||||
})
|
||||
if err != nil {
|
||||
// handle err
|
||||
}
|
||||
|
||||
err = cli.CreateCollection(ctx, milvusclient.SimpleCreateCollectionOptions(collectionName, 512).WithIndexOptions(
|
||||
milvusclient.NewCreateIndexOption(collectionName, "vector", index.NewHNSWIndex(entity.L2, 64, 128)),
|
||||
))
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
// handle error
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleClient_CreateCollection_quickSetupCustomize() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
collectionName := `quick_setup_3`
|
||||
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
|
||||
Address: milvusAddr,
|
||||
})
|
||||
if err != nil {
|
||||
// handle err
|
||||
}
|
||||
|
||||
err = cli.CreateCollection(ctx, milvusclient.SimpleCreateCollectionOptions(collectionName, 512).
|
||||
WithVarcharPK(true, 64).
|
||||
WithShardNum(1),
|
||||
)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
// handle error
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleClient_CreateCollection_consistencyLevel() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@ -245,7 +306,7 @@ func ExampleClient_RenameCollection() {
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleClient_AlterCollection_setTTL() {
|
||||
func ExampleClient_AlterCollectionProperties_setTTL() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ func (opt *createCollectionOption) WithVarcharPK(varcharPK bool, maxLen int) *cr
|
||||
}
|
||||
|
||||
func (opt *createCollectionOption) WithIndexOptions(indexOpts ...CreateIndexOption) *createCollectionOption {
|
||||
opt.indexOptions = append(opt.indexOptions, indexOpts...)
|
||||
opt.indexOptions = indexOpts
|
||||
return opt
|
||||
}
|
||||
|
||||
@ -102,6 +102,26 @@ func (opt *createCollectionOption) WithConsistencyLevel(cl entity.ConsistencyLev
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *createCollectionOption) WithMetricType(metricType entity.MetricType) *createCollectionOption {
|
||||
opt.metricType = metricType
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *createCollectionOption) WithPKFieldName(name string) *createCollectionOption {
|
||||
opt.pkFieldName = name
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *createCollectionOption) WithVectorFieldName(name string) *createCollectionOption {
|
||||
opt.vectorFieldName = name
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *createCollectionOption) WithNumPartitions(numPartitions int64) *createCollectionOption {
|
||||
opt.numPartitions = numPartitions
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *createCollectionOption) Request() *milvuspb.CreateCollectionRequest {
|
||||
// fast create collection
|
||||
if opt.isFast {
|
||||
@ -140,12 +160,12 @@ func (opt *createCollectionOption) Request() *milvuspb.CreateCollectionRequest {
|
||||
|
||||
func (opt *createCollectionOption) Indexes() []CreateIndexOption {
|
||||
// fast create
|
||||
if opt.isFast {
|
||||
if opt.isFast && opt.indexOptions == nil {
|
||||
return []CreateIndexOption{
|
||||
NewCreateIndexOption(opt.name, opt.vectorFieldName, index.NewGenericIndex("", map[string]string{})),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return opt.indexOptions
|
||||
}
|
||||
|
||||
func (opt *createCollectionOption) IsFast() bool {
|
||||
|
||||
@ -104,7 +104,9 @@ func (s *CollectionSuite) TestCreateCollectionOptions() {
|
||||
s.True(collSchema.GetEnableDynamicField())
|
||||
|
||||
collectionName = fmt.Sprintf("test_collection_%s", s.randString(6))
|
||||
opt = SimpleCreateCollectionOptions(collectionName, 128).WithVarcharPK(true, 64).WithAutoID(false).WithDynamicSchema(false)
|
||||
opt = SimpleCreateCollectionOptions(collectionName, 128).WithVarcharPK(true, 64).WithAutoID(false).
|
||||
WithPKFieldName("pk").WithVectorFieldName("embedding").WithMetricType(entity.L2).
|
||||
WithDynamicSchema(false)
|
||||
req = opt.Request()
|
||||
s.Equal(collectionName, req.GetCollectionName())
|
||||
s.EqualValues(1, req.GetShardsNum())
|
||||
|
||||
@ -18,6 +18,7 @@ package milvusclient
|
||||
|
||||
import (
|
||||
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/crypto"
|
||||
)
|
||||
|
||||
type ListUserOption interface {
|
||||
@ -71,7 +72,7 @@ type createUserOption struct {
|
||||
func (opt *createUserOption) Request() *milvuspb.CreateCredentialRequest {
|
||||
return &milvuspb.CreateCredentialRequest{
|
||||
Username: opt.userName,
|
||||
Password: opt.password,
|
||||
Password: crypto.Base64Encode(opt.password),
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,8 +96,8 @@ type updatePasswordOption struct {
|
||||
func (opt *updatePasswordOption) Request() *milvuspb.UpdateCredentialRequest {
|
||||
return &milvuspb.UpdateCredentialRequest{
|
||||
Username: opt.userName,
|
||||
OldPassword: opt.oldPassword,
|
||||
NewPassword: opt.newPassword,
|
||||
OldPassword: crypto.Base64Encode(opt.oldPassword),
|
||||
NewPassword: crypto.Base64Encode(opt.newPassword),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ import (
|
||||
|
||||
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
||||
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/crypto"
|
||||
"github.com/milvus-io/milvus/pkg/v2/util/merr"
|
||||
)
|
||||
|
||||
@ -102,7 +103,7 @@ func (s *UserSuite) TestCreateUser() {
|
||||
password := s.randString(12)
|
||||
s.mock.EXPECT().CreateCredential(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ccr *milvuspb.CreateCredentialRequest) (*commonpb.Status, error) {
|
||||
s.Equal(userName, ccr.GetUsername())
|
||||
s.Equal(password, ccr.GetPassword())
|
||||
s.Equal(crypto.Base64Encode(password), ccr.GetPassword())
|
||||
return merr.Success(), nil
|
||||
}).Once()
|
||||
|
||||
@ -121,8 +122,8 @@ func (s *UserSuite) TestUpdatePassword() {
|
||||
newPassword := s.randString(12)
|
||||
s.mock.EXPECT().UpdateCredential(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ucr *milvuspb.UpdateCredentialRequest) (*commonpb.Status, error) {
|
||||
s.Equal(userName, ucr.GetUsername())
|
||||
s.Equal(oldPassword, ucr.GetOldPassword())
|
||||
s.Equal(newPassword, ucr.GetNewPassword())
|
||||
s.Equal(crypto.Base64Encode(oldPassword), ucr.GetOldPassword())
|
||||
s.Equal(crypto.Base64Encode(newPassword), ucr.GetNewPassword())
|
||||
return merr.Success(), nil
|
||||
}).Once()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user