-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
51 lines (46 loc) · 1.7 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using Newtonsoft.Json;
namespace Rabbit
{
class Program
{
static void Main(string[] args)
{
HttpClientHandler httpClientHandler = new HttpClientHandler()
{
Credentials = new NetworkCredential("oaf_admin", "oaf_admin1"),
};
HttpClient _client = new HttpClient(httpClientHandler);
HttpResponseMessage response = _client.GetAsync("http://localhost:15672/api/users/").Result;
var users = response.Content.ReadAsStringAsync().Result;
var allUsers = JsonConvert.DeserializeObject<List<RabbitUser>>(users);
HttpResponseMessage permissions;
foreach(var user in allUsers)
{
permissions = _client.GetAsync($"http://localhost:15672/api/users/{user.name}/permissions").Result;
user.permissions = JsonConvert.DeserializeObject<List<Permissions>>(permissions.Content.ReadAsStringAsync().Result).FirstOrDefault();
Console.WriteLine(JsonConvert.SerializeObject(user.permissions));
}
}
}
public class RabbitUser
{
public string name {get; set;}
public string password_hash {get; set;}
public string hashing_algorithm {get; set;}
public string tags {get; set;}
public Permissions permissions {get; set;}
}
public class Permissions
{
public string user {get; set;}
public string vhost {get; set;}
public string configure {get; set;}
public string write {get; set; }
public string read {get; set; }
}
}