Skip to content

Commit

Permalink
Roles API
Browse files Browse the repository at this point in the history
  • Loading branch information
Rukomoynikov committed Jul 27, 2024
1 parent 057888f commit 2a43018
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/volumes

.env
.idea
3 changes: 2 additions & 1 deletion lib/milvus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module Milvus
autoload :Entities, "milvus/entities"
autoload :Indexes, "milvus/indexes"
autoload :Partitions, "milvus/partitions"
end
autoload :Roles, "milvus/roles"
end
4 changes: 4 additions & 0 deletions lib/milvus/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def indexes
@indexes ||= Milvus::Indexes.new(client: self)
end

def roles
@roles ||= Milvus::Roles.new(client: self)
end

def connection
@connection ||= Faraday.new(url: "#{url}/#{API_VERSION}/") do |faraday|
if api_key
Expand Down
25 changes: 25 additions & 0 deletions lib/milvus/roles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Milvus
class Roles < Base
PATH = "roles"

def list
response = client.connection.post("#{PATH}/list") do |req|
req.body = {}
end

response.body
end

def describe(role_name:)
response = client.connection.post("#{PATH}/describe") do |req|
req.body = {
roleName: role_name
}
end

response.body
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/roles/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"code": 0, "data": ["admin", "public"]}
1 change: 1 addition & 0 deletions spec/fixtures/users/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "code": 0, "data": ["root"] }
40 changes: 40 additions & 0 deletions spec/milvus/roles_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# spec/milvus/users_spec.rb

require "spec_helper"
require "faraday"

RSpec.describe Milvus::Roles do
let(:connection) { instance_double("Faraday::Connection") }
let(:client) { instance_double("Client", connection: connection) }
let(:roles) { described_class.new(client: client) }

describe "#list" do
let(:response_body) { File.read("spec/fixtures/roles/list.json") }
let(:response) { instance_double("Faraday::Response", body: response_body) }

it 'lists users' do
expect(connection).to receive(:post)
.with("roles/list")
.and_yield(Faraday::Request.new)
.and_return(response)
result = roles.list

expect(result).to eq(response_body)
end
end

describe "#describe" do
let(:response_body) { File.read("spec/fixtures/roles/describe.json") }
let(:response) { instance_double("Faraday::Response", body: response_body) }

it 'describes the role' do
expect(connection).to receive(:post)
.with("roles/describe")
.and_yield(Faraday::Request.new)
.and_return(response)
result = roles.describe(role_name: 'public')

expect(result).to eq(response_body)
end
end
end

0 comments on commit 2a43018

Please sign in to comment.