github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/tests/system/lib/bitwarden/user.rb (about) 1 class Bitwarden 2 class User 3 attr_reader :id, :name, :email, :type, :status 4 5 def initialize(opts) 6 @id = opts[:id] 7 @name = opts[:name] 8 @email = opts[:email] 9 @type = opts[:type] 10 @status = opts[:status] 11 end 12 13 def self.list(inst, org_id) 14 token = inst.token_for Bitwarden::Organization.doctype 15 opts = { 16 accept: "application/json", 17 authorization: "Bearer #{token}" 18 } 19 path = "/bitwarden/api/organizations/#{org_id}/users" 20 res = inst.client[path].get opts 21 body = JSON.parse(res.body) 22 body["Data"].map do |data| 23 Bitwarden::User.new( 24 id: data["UserId"], 25 type: data["Type"], 26 status: data["Status"], 27 name: data["Name"], 28 email: data["Email"] 29 ) 30 end 31 end 32 33 def fetch_public_key(inst) 34 token = inst.token_for Bitwarden::Organization.doctype 35 opts = { 36 accept: "application/json", 37 authorization: "Bearer #{token}" 38 } 39 path = "/bitwarden/api/users/#{id}/public-key" 40 res = inst.client[path].get opts 41 body = JSON.parse(res.body) 42 body["PublicKey"] 43 end 44 45 def confirm(inst, org_id, encrypted_key) 46 token = inst.token_for Bitwarden::Organization.doctype 47 opts = { 48 accept: "application/json", 49 content_type: "application/json", 50 authorization: "Bearer #{token}" 51 } 52 data = { key: encrypted_key } 53 body = JSON.generate data 54 path = "/bitwarden/api/organizations/#{org_id}/users/#{id}/confirm" 55 inst.client[path].post body, opts 56 end 57 end 58 end