-
Notifications
You must be signed in to change notification settings - Fork 9
/
fix-shock-acls
62 lines (47 loc) · 1.74 KB
/
fix-shock-acls
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
52
53
54
55
56
57
58
59
60
61
#
# fix up shock acls where owner not in the read acl
#
use Data::Dumper;
use strict;
use MongoDB;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
# use Config::Simple;
# @ARGV == 1 or die "Usage: $0 config-file\n";
# my $conf_file = shift;
# my $conf = Config::Simple->new($conf_file);
# my $ws_mongo = MongoDB::MongoClient->new(host => $conf->param("Workspace.mongodb-host"),
# db_name => $conf->param("Workspace.mongodb-database"),
# username => $conf->param("Workspace.mongodb-user"),
# password => $conf->param("Workspace.mongodb-pwd"));
# $ws_mongo or die;
my $shock_mongo = MongoDB::MongoClient->new(host => 'localhost',
db_name => 'HemlockShock',
port => 27018,
);
my $nodes = $shock_mongo->get_database("HemlockShock")->get_collection("Nodes");
# my $ws = $ws_mongo->get_database($conf->param("Workspace.mongodb-database"));
# my $objs = $ws->get_collection("objects");
my $token = 'un=reviewer|GET A REVIEWER TOKEN';
my @auth = ("Authorization" => "OAuth $token");
my $base_url = "http://localhost:7078";
#
# Find nodes where reviewer id not in the read acl
#
my $owner = "0e6adb8b-0eaa-4742-b27d-79ed25d094ba";
my $owner_name = "reviewer";
my @extra = ( id => 'd2ddeb37-a4ba-4c5c-a0a6-85c810fe99ce');
@extra = ();
my $res = $nodes->find({ 'acl.owner' => $owner, 'acl.read' => { '$nin' => [ $owner ] }, @extra});
$res = $res->fields({acl => 1, public => 1, file => 1, id => 1, created_on => 1 });
while (my $elt = $res->next())
{
print join("\t", $elt->{id}, scalar @{$elt->{acl}->{read}}), "\n";
next;
my $url = "$base_url/node/$elt->{id}/acl/read?users=$owner_name";
my $res = $ua->put($url, @auth);
if (!$res->is_success)
{
die "Failed on $elt->{id} " . $res->status_line;
}
}