conjur-asset-ui-api 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,10 @@
3
3
  */
4
4
  var namespace = NamespaceModel();
5
5
 
6
+ function errback(err) {
7
+ console.log("error:", err);
8
+ }
9
+
6
10
  var kind = "";
7
11
  var lists = {
8
12
  "groups": new ResourceListModel("group"),
@@ -13,6 +17,7 @@ var lists = {
13
17
  "hosts": new ResourceListModel("host")
14
18
  };
15
19
  var conjurConfiguration;
20
+ var userId;
16
21
  var components = {};
17
22
  var router;
18
23
  var globalIds;
@@ -48,6 +53,7 @@ $(document).ready(function() {
48
53
  }
49
54
 
50
55
  conjurConfiguration = JSON.parse(decodeURIComponent(readCookie('conjur_configuration')).replace(/\+/g, ' '));
56
+ userId = decodeURIComponent(readCookie('conjur_userid'));
51
57
 
52
58
  function createEndpoints(){
53
59
  endpoints = {};
@@ -113,25 +119,25 @@ $(document).ready(function() {
113
119
  });
114
120
  }
115
121
 
116
- function activateRecord(id, componentFunction) {
117
- /* console.log("Record", kind, " :", id); */
122
+ function activateRecord(k, id, componentFunction) {
123
+ /* console.log("Record", k, " :", id); */
124
+
125
+ $('#inlineSearchContainer').show();
126
+ kind = pluralize(k);
118
127
  setActiveNav(kind);
119
- new RecordModel(kind, id).fetch(function(record) {
120
- /* console.log(record.object); */
121
-
122
- function doRenderComponent(component) {
123
- React.renderComponent(
124
- component,
125
- document.getElementById('content')
126
- );
127
- }
128
+
129
+ var model;
130
+ if ( Record[_.capitalize(k)] )
131
+ model = new Record[_.capitalize(k)](id);
132
+ else
133
+ model = new Record.Generic(kind, id);
128
134
 
129
- var component = componentFunction(record.object, function(result) {
130
- doRenderComponent(result);
131
- });
132
- if ( component ) {
133
- doRenderComponent(component);
134
- }
135
+ model.fetch(function(record) {
136
+ var component = componentFunction(record);
137
+ React.renderComponent(
138
+ component,
139
+ document.getElementById('content')
140
+ );
135
141
  }, function(status, text, xhr){
136
142
  if(status == 403){
137
143
  window.flash = "You are not authorized to view " + kind + ":" + id + ".";
@@ -176,9 +182,7 @@ $(document).ready(function() {
176
182
  },
177
183
 
178
184
  user: function(user){
179
- $('#inlineSearchContainer').show();
180
- kind = "users";
181
- activateRecord(user, function(record, callback){
185
+ activateRecord("user", user, function(record){
182
186
  return <User data={record}/>;
183
187
  });
184
188
  },
@@ -192,16 +196,8 @@ $(document).ready(function() {
192
196
  },
193
197
 
194
198
  group: function(group) {
195
- $('#inlineSearchContainer').show();
196
- kind = "groups";
197
- activateRecord(group, function(record, callback) {
198
- $.ajax({
199
- url: "/api/authz/" + conjurConfiguration.account + "/roles/group/" + record.id + "?members",
200
- success: function(result) {
201
- callback(<Group data={{group: record, members: result}} />);
202
- },
203
- error: error
204
- });
199
+ activateRecord("group", group, function(record) {
200
+ return <Group data={record} />;
205
201
  });
206
202
  },
207
203
 
@@ -214,9 +210,9 @@ $(document).ready(function() {
214
210
  },
215
211
 
216
212
  host: function(host){
217
- $('#inlineSearchContainer').show();
218
- kind = "hosts";
219
- activateRecord(host, function(record){ return <Host data={record}/>;});
213
+ activateRecord("host", host, function(record) {
214
+ return <Host data={record}/>;
215
+ });
220
216
  },
221
217
 
222
218
  hosts: function() {
@@ -228,24 +224,8 @@ $(document).ready(function() {
228
224
  },
229
225
 
230
226
  layer: function(layer) {
231
- $('#inlineSearchContainer').show();
232
- kind = "layers";
233
- activateRecord(layer, function(record, callback) {
234
- var id = record.id.split(':')[2];
235
- async.map(['@/layer/' + record.id + '/use_host', '@/layer/' + record.id + '/admin_host' ],
236
- function(role, cb) {
237
- $.ajax({
238
- url: "/api/authz/" + conjurConfiguration.account + "/roles/" + role + "?members",
239
- success: function(result) { cb(null, result) },
240
- error: cb
241
- });
242
- },
243
- function(err, results) {
244
- if ( err )
245
- error(err);
246
- else
247
- callback(<Layer data={{layer: record, users: _.pluck(results[0], 'member'), admins: _.pluck(results[1], 'member')}} />);
248
- });
227
+ activateRecord("layer", layer, function(record) {
228
+ return <Layer data={record} />;
249
229
  });
250
230
  },
251
231
 
@@ -258,25 +238,8 @@ $(document).ready(function() {
258
238
  },
259
239
 
260
240
  variable: function(variable) {
261
- $('#inlineSearchContainer').show();
262
- kind = "variables";
263
- activateRecord(variable, function(record, callback) {
264
- async.map(['execute', 'update'], function(privilege, cb) {
265
- $.ajax({
266
- url: "/api/authz/" + conjurConfiguration.account + "/roles/allowed_to/" + privilege + "/variable/" + record.id,
267
- success: function(result) {
268
- cb(null, result);
269
- },
270
- error: cb
271
- });
272
- },
273
- function(err, results) {
274
- if ( err ) return error(err);
275
-
276
- var updaters = results[1];
277
- var fetchers = _.difference(results[0], updaters);
278
- callback(<Variable data={{variable: record, fetchers: fetchers, updaters: updaters}} />);
279
- });
241
+ activateRecord("variable", variable, function(record) {
242
+ return <Variable data={record} />;
280
243
  });
281
244
  },
282
245
 
@@ -0,0 +1,35 @@
1
+ if (typeof $ === "undefined") { throw new Error("jQuery is required") }
2
+
3
+ Record.Group = function(args) {
4
+ var superArguments = Array.prototype.slice.call(arguments);
5
+ superArguments.unshift("group");
6
+ Record.Generic.apply(this, superArguments);
7
+ }
8
+
9
+ Record.Group.prototype = Object.create(Record.Generic.prototype);
10
+ Record.Group.prototype.constructor = Record.Group;
11
+
12
+ Record.Group.prototype.fetch = function(callback) {
13
+ var self = this;
14
+ var id = this.id;
15
+
16
+ async.parallel([
17
+ this.attributes.bind(this),
18
+ this.ownedResources.bind(this),
19
+ function(cb) {
20
+ $.ajax({
21
+ url: "/api/authz/" + conjurConfiguration.account + "/roles/group/" + id + "?members",
22
+ success: function(result) {
23
+ cb(null, result);
24
+ },
25
+ error: cb
26
+ });
27
+ }
28
+ ],
29
+ function(err, results) {
30
+ if ( err )
31
+ return errback(err);
32
+
33
+ callback({ group: results[0], owned: results[1], members: results[2] });
34
+ });
35
+ }
@@ -0,0 +1,26 @@
1
+ if (typeof $ === "undefined") { throw new Error("jQuery is required") }
2
+
3
+ Record.Host = function(args) {
4
+ var superArguments = Array.prototype.slice.call(arguments);
5
+ superArguments.unshift("host");
6
+ Record.Generic.apply(this, superArguments);
7
+ }
8
+
9
+ Record.Host.prototype = Object.create(Record.Generic.prototype);
10
+ Record.Host.prototype.constructor = Record.Host;
11
+
12
+ Record.Host.prototype.fetch = function(callback) {
13
+ var self = this;
14
+ var id = this.id;
15
+
16
+ async.parallel([
17
+ this.attributes.bind(this),
18
+ this.ownedResources.bind(this)
19
+ ],
20
+ function(err, results) {
21
+ if ( err )
22
+ return errback(err);
23
+
24
+ callback({host: results[0], owned: results[1]});
25
+ });
26
+ }
@@ -0,0 +1,38 @@
1
+ if (typeof $ === "undefined") { throw new Error("jQuery is required") }
2
+
3
+ Record.Layer = function(args) {
4
+ var superArguments = Array.prototype.slice.call(arguments);
5
+ superArguments.unshift("layer");
6
+ Record.Generic.apply(this, superArguments);
7
+ }
8
+
9
+ Record.Layer.prototype = Object.create(Record.Generic.prototype);
10
+ Record.Layer.prototype.constructor = Record.Layer;
11
+
12
+ Record.Layer.prototype.fetch = function(callback) {
13
+ var self = this;
14
+ var id = this.id;
15
+
16
+ function members(role) {
17
+ return function(cb) {
18
+ $.ajax({
19
+ url: "/api/authz/" + conjurConfiguration.account + "/roles/" + role + "?members",
20
+ success: function(result) { cb(null, result) },
21
+ error: cb
22
+ });
23
+ }
24
+ }
25
+
26
+ async.parallel([
27
+ this.attributes.bind(this),
28
+ this.ownedResources.bind(this),
29
+ members('@/layer/' + id + '/use_host'),
30
+ members('@/layer/' + id + '/use_host')
31
+ ],
32
+ function(err, results) {
33
+ if ( err )
34
+ return errback(err);
35
+
36
+ callback({ layer: results[0], owned: results[1], users: _.pluck(results[2], 'member'), admins: _.pluck(results[3], 'member') });
37
+ });
38
+ }
@@ -1,26 +1,39 @@
1
1
  if (typeof $ === "undefined") { throw new Error("jQuery is required") }
2
2
 
3
- var RecordModel = function(kind, id){
4
- var Record = function() {
5
- this.object = null;
6
- }
7
-
8
- Record.prototype.fetch = function(callback, errback) {
9
- errback || (errback = function(status, text, xhr){
10
- alert("Error fetching " + kind + ":" + id + " " + status + " " + text);
11
- });
12
- var self = this;
13
- $.ajax({
14
- url: "/api/" + kind + "/" + encodeURIComponent(id),
15
- success: function(data) {
16
- self.object = data;
17
- callback(self);
18
- },
19
- error: function(xhr, textStatus, errorThrown){
20
- errback(xhr.status, errorThrown, xhr);
21
- }
22
- });
23
- }
24
-
25
- return new Record();
3
+ Record = {};
4
+
5
+ Record.Generic = function(kind, id) {
6
+ this.kind = kind;
7
+ this.id = id;
8
+ }
9
+
10
+ Record.Generic.prototype.attributes = function(callback) {
11
+ var id = this.id;
12
+ $.ajax({
13
+ url: "/api/" + kind + "/" + encodeURIComponent(id),
14
+ success: function(data) {
15
+ callback(null, data);
16
+ },
17
+ error: callback
18
+ });
19
+ }
20
+
21
+ Record.Generic.prototype.ownedResources = function(callback) {
22
+ var id = this.id;
23
+ var roleid = [ this.kind, this.id ].join(':')
24
+ $.ajax({
25
+ url: "/api/authz/" + conjurConfiguration.account + "/resources?owner=" + roleid,
26
+ success: function(result) {
27
+ callback(null, result);
28
+ },
29
+ error: callback
30
+ });
31
+ }
32
+
33
+ Record.Generic.prototype.fetch = function(callback) {
34
+ this.attributes(function(err, data) {
35
+ if ( err )
36
+ return errback(err);
37
+ callback(data);
38
+ });
26
39
  }
@@ -0,0 +1,26 @@
1
+ if (typeof $ === "undefined") { throw new Error("jQuery is required") }
2
+
3
+ Record.User = function(args) {
4
+ var superArguments = Array.prototype.slice.call(arguments);
5
+ superArguments.unshift("user");
6
+ Record.Generic.apply(this, superArguments);
7
+ }
8
+
9
+ Record.User.prototype = Object.create(Record.Generic.prototype);
10
+ Record.User.prototype.constructor = Record.User;
11
+
12
+ Record.User.prototype.fetch = function(callback) {
13
+ var self = this;
14
+ var id = this.id;
15
+
16
+ async.parallel([
17
+ this.attributes.bind(this),
18
+ this.ownedResources.bind(this)
19
+ ],
20
+ function(err, results) {
21
+ if ( err )
22
+ return errback(err);
23
+
24
+ callback({user: results[0], owned: results[1]});
25
+ });
26
+ }
@@ -0,0 +1,39 @@
1
+ if (typeof $ === "undefined") { throw new Error("jQuery is required") }
2
+
3
+ Record.Variable = function(args) {
4
+ var superArguments = Array.prototype.slice.call(arguments);
5
+ superArguments.unshift("variable");
6
+ Record.Generic.apply(this, superArguments);
7
+ }
8
+
9
+ Record.Variable.prototype = Object.create(Record.Generic.prototype);
10
+ Record.Variable.prototype.constructor = Record.Variable;
11
+
12
+ Record.Variable.prototype.fetch = function(callback) {
13
+ var self = this;
14
+ var id = this.id;
15
+
16
+ function members(privilege) {
17
+ return function(cb) {
18
+ $.ajax({
19
+ url: "/api/authz/" + conjurConfiguration.account + "/roles/allowed_to/" + privilege + "/variable/" + id,
20
+ success: function(result) {
21
+ cb(null, result);
22
+ },
23
+ error: cb
24
+ });
25
+ }
26
+ }
27
+
28
+ async.parallel([
29
+ this.attributes.bind(this),
30
+ members("execute"),
31
+ members("update")
32
+ ],
33
+ function(err, results) {
34
+ if ( err )
35
+ return errback(err);
36
+
37
+ callback({variable: results[0], fetchers: results[1], updaters: results[2]});
38
+ });
39
+ }
@@ -1,10 +1,21 @@
1
1
  // Generated by LiveScript 1.2.0
2
2
  (function(){
3
- var ref$, table, div, th, tr, td, thead, tbody, section, h3, time, map, each, unique, isType, join, fields, AuditTableHeader, Timestamp, wrapArray, AuditEntry, newEventSet, AuditTable, GlobalAudit, urlOfRole, urlOfResource, AuditBox, out$ = typeof exports != 'undefined' && exports || this;
3
+ var ref$, table, div, th, tr, td, thead, tbody, section, h3, time, map, each, unique, isType, join, compact_fields, extended_fields, FieldsMixin, AuditTableHeader, Timestamp, wrapArray, AuditEntry, newEventSet, AuditTable, GlobalAudit, urlOfRole, urlOfResource, AuditBox, out$ = typeof exports != 'undefined' && exports || this, slice$ = [].slice;
4
4
  ref$ = React.DOM, table = ref$.table, div = ref$.div, th = ref$.th, tr = ref$.tr, td = ref$.td, thead = ref$.thead, tbody = ref$.tbody, section = ref$.section, h3 = ref$.h3, time = ref$.time;
5
5
  ref$ = require('prelude-ls'), map = ref$.map, each = ref$.each, unique = ref$.unique, isType = ref$.isType, join = ref$.join;
6
- fields = ['timestamp', 'user', 'acting_as', 'action', 'kind', 'entity', 'privilege'];
6
+ compact_fields = ['user', 'action', 'entities'];
7
+ extended_fields = ['timestamp', 'user', 'acting_as', 'action', 'entities', 'privilege'];
8
+ FieldsMixin = {
9
+ fields: function(){
10
+ if (this.props.compact) {
11
+ return compact_fields;
12
+ } else {
13
+ return extended_fields;
14
+ }
15
+ }
16
+ };
7
17
  AuditTableHeader = React.createClass({
18
+ mixins: [FieldsMixin],
8
19
  displayName: 'AuditTableHeader',
9
20
  render: function(){
10
21
  return thead({}, tr({}, map(function(it){
@@ -12,7 +23,7 @@
12
23
  key: it
13
24
  }, it.replace('_', ' '));
14
25
  })(
15
- fields)));
26
+ this.fields())));
16
27
  }
17
28
  });
18
29
  Timestamp = React.createClass({
@@ -21,7 +32,7 @@
21
32
  var ts;
22
33
  ts = moment(this.props.time);
23
34
  return time({
24
- datetime: ts.format(),
35
+ dateTime: ts.format(),
25
36
  title: ts.calendar()
26
37
  }, [ts.fromNow()]);
27
38
  }
@@ -33,43 +44,49 @@
33
44
  return [it];
34
45
  }
35
46
  };
36
- AuditEntry = React.createClass({
47
+ out$.AuditEntry = AuditEntry = React.createClass({
48
+ mixins: [FieldsMixin],
37
49
  displayName: 'AuditEntry',
38
- transformedProps: function(){
39
- var ref$;
40
- return ref$ = clone$(this.props), ref$.entity = this.props.resource || this.props.role, ref$;
41
- },
42
50
  transformField: function(key, value){
43
- switch (false) {
44
- case !!value:
45
- return value;
46
- case key !== 'user' && key !== 'acting_as':
47
- return RoleLink({
48
- id: value
49
- });
50
- case key !== 'entity':
51
- return ResourceLink({
52
- data: value
53
- });
54
- case key !== 'timestamp':
55
- return Timestamp({
56
- time: value
57
- });
51
+ var that;
52
+ switch (key) {
53
+ case 'entities':
54
+ return [
55
+ (that = this.props.resource) != null ? ResourceLink({
56
+ data: that
57
+ }) : void 8, (that = this.props.role) != null ? RoleLink({
58
+ id: that
59
+ }) : void 8
60
+ ];
61
+ case 'user':
62
+ case 'acting_as':
63
+ if (value != null) {
64
+ return RoleLink({
65
+ id: value
66
+ });
67
+ }
68
+ break;
69
+ case 'timestamp':
70
+ if (value != null) {
71
+ return Timestamp({
72
+ time: value
73
+ });
74
+ }
75
+ break;
58
76
  default:
59
77
  return value;
60
78
  }
61
79
  },
62
80
  render: function(){
63
- var props, this$ = this;
64
- props = this.transformedProps();
81
+ var this$ = this;
65
82
  return tr({
66
83
  className: this.props.action
67
84
  }, map(function(it){
68
- return td({
85
+ return td.apply(null, [{
69
86
  key: it
70
- }, [this$.transformField(it, props[it])]);
87
+ }].concat(slice$.call(wrapArray(this$.transformField(it, this$.props[it])))));
71
88
  })(
72
- fields));
89
+ this.fields()));
73
90
  }
74
91
  });
75
92
  newEventSet = function(){
@@ -88,7 +105,7 @@
88
105
  };
89
106
  return evts;
90
107
  };
91
- AuditTable = React.createClass({
108
+ out$.AuditTable = AuditTable = React.createClass({
92
109
  displayName: 'AuditTable',
93
110
  getInitialState: function(){
94
111
  return {
@@ -96,6 +113,8 @@
96
113
  };
97
114
  },
98
115
  render: function(){
116
+ var compact;
117
+ compact = this.props.compact;
99
118
  return section({
100
119
  className: 'audit'
101
120
  }, [
@@ -103,12 +122,13 @@
103
122
  className: 'audit-table'
104
123
  }, [
105
124
  AuditTableHeader({
106
- key: 'thead'
125
+ key: 'thead',
126
+ compact: compact
107
127
  }), tbody({
108
128
  key: 'tbody'
109
129
  }, this.state.events.map(function(it){
110
130
  var ref$;
111
- return new AuditEntry((ref$ = clone$(it), ref$.key = it.id, ref$));
131
+ return new AuditEntry((ref$ = clone$(it), ref$.key = it.id, ref$.compact = compact, ref$));
112
132
  }))
113
133
  ])
114
134
  ]);
@@ -180,7 +200,7 @@
180
200
  roles.concat(resources)));
181
201
  return AuditTable({
182
202
  src: roleSrcs.concat(resSrcs),
183
- caption: "Recent audit events for " + things
203
+ caption: "Recent Activity"
184
204
  });
185
205
  }
186
206
  });