-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cab165
commit d4db10f
Showing
11 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# frozen_string_literal: true | ||
|
||
module Milvus | ||
class Users < Base | ||
PATH = "users" | ||
|
||
# Create a user | ||
# | ||
# @param user_name [String] Username for the user | ||
# @param password [String] Password for the user | ||
# @return [Hash] Server response | ||
def create(user_name:, password:) | ||
response = client.connection.post("#{PATH}/create") do |req| | ||
req.body = { | ||
userName: user_name, | ||
password: password | ||
} | ||
end | ||
|
||
response.body | ||
end | ||
|
||
# Describe a user | ||
# | ||
# @param user_name [String] Username for the user | ||
# @return [Hash] Server response | ||
def describe(user_name:) | ||
response = client.connection.post("#{PATH}/describe") do |req| | ||
req.body = { | ||
userName: user_name | ||
} | ||
end | ||
|
||
response.body | ||
end | ||
|
||
# List users | ||
# | ||
# @return [Hash] Server response | ||
def list | ||
response = client.connection.post("#{PATH}/list") do |req| | ||
req.body = {} | ||
end | ||
|
||
response.body | ||
end | ||
|
||
# Drops a user | ||
# | ||
# @param user_name [String] Username for the user | ||
# @return [Hash] Server response | ||
def drop(user_name:) | ||
response = client.connection.post("#{PATH}/drop") do |req| | ||
req.body = { | ||
userName: user_name | ||
} | ||
end | ||
|
||
response.body | ||
end | ||
|
||
def update_password(user_name:, password:, new_password:) | ||
response = client.connection.post("#{PATH}/update_password") do |req| | ||
req.body = { | ||
userName: user_name, | ||
password: password, | ||
newPassword: new_password | ||
} | ||
end | ||
|
||
response.body | ||
end | ||
|
||
def grant_role(user_name:, role_name:) | ||
response = client.connection.post("#{PATH}/grant_role") do |req| | ||
req.body = { | ||
userName: user_name, | ||
roleName: role_name | ||
} | ||
end | ||
|
||
response.body | ||
end | ||
|
||
def revoke_role(user_name:, role_name:) | ||
response = client.connection.post("#{PATH}/revoke_role") do |req| | ||
req.body = { | ||
userName: user_name, | ||
roleName: role_name | ||
} | ||
end | ||
|
||
response.body | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code": 0, "data": {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code": 0, "data": []} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code": 0, "data": []} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code": 0, "data": {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code": 0, "data": {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# spec/milvus/users_spec.rb | ||
|
||
require "spec_helper" | ||
require "faraday" | ||
|
||
RSpec.describe Milvus::Users do | ||
let(:connection) { instance_double("Faraday::Connection") } | ||
let(:client) { instance_double("Client", connection: connection) } | ||
let(:users) { described_class.new(client: client) } | ||
|
||
describe "#create" do | ||
let(:response_body) { File.read("spec/fixtures/users/create.json") } | ||
let(:response) { instance_double("Faraday::Response", body: response_body) } | ||
|
||
it "creates a user" do | ||
expect(connection).to receive(:post) | ||
.with("users/create") | ||
.and_yield(Faraday::Request.new) | ||
.and_return(response) | ||
result = users.create(user_name: "user_name", password: "password") | ||
|
||
expect(result).to eq(response_body) | ||
end | ||
end | ||
|
||
describe "#describe" do | ||
let(:response_body) { File.read("spec/fixtures/users/describe.json") } | ||
let(:response) { instance_double("Faraday::Response", body: response_body) } | ||
|
||
it "describes the user" do | ||
expect(connection).to receive(:post) | ||
.with("users/describe") | ||
.and_yield(Faraday::Request.new) | ||
.and_return(response) | ||
result = users.describe(user_name: "root") | ||
|
||
expect(result).to eq(response_body) | ||
end | ||
end | ||
|
||
describe "#list" do | ||
let(:response_body) { File.read("spec/fixtures/users/list.json") } | ||
let(:response) { instance_double("Faraday::Response", body: response_body) } | ||
|
||
it "responds with a list of users" do | ||
expect(connection).to receive(:post) | ||
.with("users/list") | ||
.and_yield(Faraday::Request.new) | ||
.and_return(response) | ||
result = users.list | ||
|
||
expect(result).to eq(response_body) | ||
end | ||
end | ||
|
||
describe "#drop" do | ||
let(:response_body) { File.read("spec/fixtures/users/drop.json") } | ||
let(:response) { instance_double("Faraday::Response", body: response_body) } | ||
|
||
it "drops the user" do | ||
expect(connection).to receive(:post) | ||
.with("users/drop") | ||
.and_yield(Faraday::Request.new) | ||
.and_return(response) | ||
result = users.drop(user_name: "root") | ||
|
||
expect(result).to eq(response_body) | ||
end | ||
end | ||
|
||
describe "#update_password" do | ||
let(:response_body) { File.read("spec/fixtures/users/update_password.json") } | ||
let(:response) { instance_double("Faraday::Response", body: response_body) } | ||
|
||
it "updates the users's password" do | ||
expect(connection).to receive(:post) | ||
.with("users/update_password") | ||
.and_yield(Faraday::Request.new) | ||
.and_return(response) | ||
result = users.update_password user_name: "username", | ||
password: "old_password", | ||
new_password: "new_password" | ||
|
||
expect(result).to eq(response_body) | ||
end | ||
end | ||
|
||
describe "#grant_role" do | ||
let(:response_body) { File.read("spec/fixtures/users/grant_role.json") } | ||
let(:response) { instance_double("Faraday::Response", body: response_body) } | ||
|
||
it "sets role to the user" do | ||
expect(connection).to receive(:post) | ||
.with("users/grant_role") | ||
.and_yield(Faraday::Request.new) | ||
.and_return(response) | ||
result = users.grant_role user_name: "user_name", role_name: "admin" | ||
|
||
expect(result).to eq(response_body) | ||
end | ||
end | ||
|
||
describe "#revoke_role" do | ||
let(:response_body) { File.read("spec/fixtures/users/revoke_role.json") } | ||
let(:response) { instance_double("Faraday::Response", body: response_body) } | ||
|
||
it "revokes the role" do | ||
expect(connection).to receive(:post) | ||
.with("users/revoke_role") | ||
.and_yield(Faraday::Request.new) | ||
.and_return(response) | ||
result = users.revoke_role user_name: "user_name", role_name: "admin" | ||
|
||
expect(result).to eq(response_body) | ||
end | ||
end | ||
end |