Skip to content

Commit

Permalink
enhance: add DropUser, update UpdatePassword to support reset connection
Browse files Browse the repository at this point in the history
Signed-off-by: Ruichen Bao <ruichen.bao@zju.edu.cn>
  • Loading branch information
brcarry committed Jan 3, 2025
1 parent e8c7fe9 commit 2b2231a
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/impl/MilvusClientImplV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,29 @@ MilvusClientImplV2::UpdatePassword(const std::string& username, const std::strin
};

auto post = [this, reset_connection, username, new_password](const proto::common::Status& status) {
if (reset_connection) {
Disconnect();
milvus::ConnectParam connect_param(connection_->Host(), connection_->Port(), username, new_password);
Connect(connect_param);
}
return status;
};

return apiHandler<proto::milvus::UpdateCredentialRequest, proto::common::Status>(
pre, &MilvusConnection::UpdateCredential, post, GrpcOpts{timeout});
}

Status
MilvusClientImplV2::DropUser(const std::string& username, int timeout) {
auto pre = [&username]() {
proto::milvus::DeleteCredentialRequest rpc_request;
rpc_request.set_username(username);
return rpc_request;
};

return apiHandler<proto::milvus::DeleteCredentialRequest, proto::common::Status>(pre, &MilvusConnection::DeleteCredential, GrpcOpts{timeout});
}

Status
MilvusClientImplV2::CalcDistance(const CalcDistanceArguments& arguments, DistanceArray& results) {
auto validate = [&arguments]() { return arguments.Validate(); };
Expand Down
3 changes: 3 additions & 0 deletions src/impl/MilvusClientImplV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class MilvusClientImplV2 : public MilvusClientV2 {
Status
UpdatePassword(const std::string& username, const std::string& old_password, const std::string& new_password, bool reset_connection, int timeout) final;

Status
DropUser(const std::string& username, int timeout) final;

Status
CalcDistance(const CalcDistanceArguments& arguments, DistanceArray& results) final;

Expand Down
55 changes: 55 additions & 0 deletions src/impl/MilvusConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ MilvusConnection::Connect(const ConnectParam& param) {
std::chrono::milliseconds{param.ConnectTimeout()});
if (connected) {
stub_ = proto::milvus::MilvusService::NewStub(channel_);
SetHost(param.Host());
SetPort(param.Port());
SetUser(param.Username());
SetPassword(param.Password());
SetToken(param.Token());
return Status::OK();
}

Expand Down Expand Up @@ -414,4 +419,54 @@ MilvusConnection::GetAllHeaders() const {
return header_vec;
}

const std::string&
MilvusConnection::Host() const {
return host_;
}

void
MilvusConnection::SetHost(const std::string& host) {
host_ = host;
}

uint16_t
MilvusConnection::Port() const {
return port_;
}

void
MilvusConnection::SetPort(uint16_t port) {
port_ = port;
}

const std::string&
MilvusConnection::User() const {
return user_;
}

void
MilvusConnection::SetUser(const std::string& user) {
user_ = user;
}

const std::string&
MilvusConnection::Password() const {
return password_;
}

void
MilvusConnection::SetPassword(const std::string& password) {
password_ = password;
}

const std::string&
MilvusConnection::Token() const {
return token_;
}

void
MilvusConnection::SetToken(const std::string& token) {
token_ = token;
}

} // namespace milvus
35 changes: 35 additions & 0 deletions src/impl/MilvusConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,46 @@ class MilvusConnection {
std::vector<std::pair<std::string, std::string>>
GetAllHeaders() const;

const
std::string& Host() const;

void
SetHost(const std::string& host);

uint16_t
Port() const;

void
SetPort(uint16_t port);

const std::string&
User() const;

void
SetUser(const std::string& user);

const std::string&
Password() const;

void
SetPassword(const std::string& password);

const std::string&
Token() const;

void
SetToken(const std::string& token);

private:
std::unique_ptr<proto::milvus::MilvusService::Stub> stub_;
std::shared_ptr<grpc::Channel> channel_;
std::string authorization_value_{};
std::unordered_map<std::string, std::string> headers_;
std::string host_;
uint16_t port_;
std::string user_;
std::string password_;
std::string token_;

static Status
StatusByProtoResponse(const proto::common::Status& status) {
Expand Down
3 changes: 3 additions & 0 deletions src/include/milvus/MilvusClientV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ class MilvusClientV2 {
virtual Status
UpdatePassword(const std::string& username, const std::string& old_password, const std::string& new_password, bool reset_connection = false, int timeout = 0) = 0;

virtual Status
DropUser(const std::string& username, int timeout = 0) = 0;

/**
* Calculate distance between two vector arrays.
*
Expand Down

0 comments on commit 2b2231a

Please sign in to comment.