conjur-asset-dsl2 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f38c1c218b12a47f1fb2170f0cd57dc5e267e02
4
- data.tar.gz: 6b500271f6c523ad283f561575275d80cd26d2df
3
+ metadata.gz: 964f33500185235bd65a6b64faefc618ccb71994
4
+ data.tar.gz: ee1a68a365e3bc9ea036e873bacf7da1ad31844f
5
5
  SHA512:
6
- metadata.gz: 90da10c662515b1f93c8961a61a493b2a68475c9b8375d2df099363322ed5bc35d3465eb9ff028b39756daaeb32397961d0951630b34002e9baf3565b1fa10f6
7
- data.tar.gz: fd56bb4cdd2ff5f269abbb95f6716d5709df7e93f3fd0a3e655f207759f041470e786f82a5d3b7718ac35665377c88ff167cd23081fb42bc84fd35a6402d6dc3
6
+ metadata.gz: a0e879f8446c5d68520b1e38ec75f73cc0596949a475fdba8081705ed11f303f08522790e6bd2bac09b98add69ee5dd15b0d260a394503b19e6611f21058d9ee
7
+ data.tar.gz: bc5511cb4931c99a23bf1e15f8d9e7e22e272e68b116464854aceb31e65e6ae5f72dad44434a71ad88035759b102fd1091570cb5a7b7f903f483c52c93f3a6b8
data/CHANGELOG CHANGED
@@ -1,14 +1,19 @@
1
- # 0.4.0
1
+ # 0.4.3
2
2
 
3
- * Support `--context` flag to save API keys to a file.
3
+ * Fix a load error which can occur when using YAML lists inside of policies
4
+
5
+ # 0.4.2
6
+
7
+ * Support `--context` flag to save API keys to a file.
4
8
 
5
9
  # 0.3.2
6
10
 
7
- * Fix issue where webservices were being treated as core assets by the executor.
11
+ * Fix issue where webservices were being treated as core assets by the executor.
8
12
 
9
13
  # 0.3.1
10
14
 
11
- * Fix bug in executor for permissions
15
+ * Fix bug in executor for permissions
12
16
 
13
17
  # 0.3.0
14
- * Initial stable version
18
+
19
+ * Initial stable version
@@ -131,16 +131,6 @@ command. Therefore, a policy can be loaded in three steps, if desired:
131
131
  DESC
132
132
  policy.arg_name "(policy-file | STDIN)"
133
133
  policy.command :load do |c|
134
-
135
- # Undefine options which are declared in the base (default) implementation.
136
- # TODO: This code can be removed if and when dsl2 becomes the default.
137
- %w(as-group as-role collection context c).each do |switch|
138
- c.switches.delete switch.to_sym
139
- c.flags.delete switch.to_sym
140
- c.switches_declaration_order.delete_if{|s| s.name == switch.to_sym}
141
- c.flags_declaration_order.delete_if{|s| s.name == switch.to_sym}
142
- end
143
-
144
134
  acting_as_option(c)
145
135
 
146
136
  c.desc "Policy namespace (optional)"
@@ -4,6 +4,8 @@ module Conjur::DSL2
4
4
  # is an object from Conjur::DSL2::Types. Each execution action is
5
5
  # an HTTP method, a request path, and request parameters.
6
6
  class Base
7
+ include Conjur::DSL2::Logger
8
+
7
9
  attr_reader :statement, :actions, :default_account
8
10
 
9
11
  def initialize statement, actions, default_account
@@ -0,0 +1,12 @@
1
+ module Conjur::DSL2::Logger
2
+ def self.included base
3
+ base.module_eval do
4
+ # Override the logger with this method.
5
+ cattr_accessor :logger
6
+
7
+ require 'logger'
8
+ self.logger = Logger.new(STDERR)
9
+ self.logger.level = Logger::INFO
10
+ end
11
+ end
12
+ end
@@ -2,11 +2,11 @@ module Conjur
2
2
  module DSL2
3
3
  module Planner
4
4
  class Base
5
+ include Conjur::DSL2::Logger
5
6
 
6
7
  attr_reader :record, :api
7
8
  attr_accessor :plan
8
9
 
9
-
10
10
  def initialize record, api
11
11
  @record = record
12
12
  @api = api
@@ -80,7 +80,7 @@ module Conjur
80
80
  # Sort in canonical order -- basically, a `Record` or `Create` comes before everything
81
81
  # else. So the base class's sort just places those before us, and anything else gets 0.
82
82
  def <=> other
83
- other.kind_of?(Conjur::DSL2::Planner::ActsAsRecord) ? 1 : 0
83
+ (other.kind_of?(Conjur::DSL2::Planner::ActsAsRecord) or other.kind_of?(Conjur::DSL2::Planner::Array)) ? 1 : 0
84
84
  end
85
85
 
86
86
  def resource_exists? resource
@@ -101,21 +101,12 @@ module Conjur
101
101
  raise message
102
102
  end
103
103
 
104
- def trace message
105
- if trace_enabled?
106
- $stderr.puts "[trace #{record}] #{message}"
107
- end
108
- end
109
-
110
- def trace_enabled?
111
- ENV["DSL_PLANNER_TRACE"] || !!@trace_enabled
112
- end
113
-
114
- def trace_enabled= enabled
115
- @trace_enabled = enabled
104
+ def log &block
105
+ logger.debug('conjur/dsl2/planner') {
106
+ yield
107
+ }
116
108
  end
117
109
 
118
-
119
110
  def update_record
120
111
  update = Conjur::DSL2::Types::Update.new
121
112
  update.record = record
@@ -198,8 +189,13 @@ module Conjur
198
189
  end
199
190
 
200
191
  class Array < Base
192
+ # Array sorts before everything because sanity.
193
+ def <=> other
194
+ -1
195
+ end
201
196
 
202
197
  def do_plan
198
+
203
199
  planners = record.map do |item|
204
200
  Planner.planner_for(item, api)
205
201
  end.sort
@@ -10,7 +10,6 @@ module Conjur
10
10
  # be granted every role. If the +replace+ option is set, then any existing
11
11
  # grant on a role that is *not* given should be revoked, except for role admins.
12
12
  def do_plan
13
-
14
13
  roles = Array(record.roles)
15
14
  members = Array(record.members)
16
15
  given_grants = Hash.new { |hash, key| hash[key] = [] }
@@ -51,7 +51,7 @@ module Conjur
51
51
  (Set.new(requested) - Set.new(given)).each do |p|
52
52
  role, admin = p
53
53
 
54
- error("role not found: #{role}") unless role_exists?(role)
54
+ error(%Q(Role "#{role}" not found")) unless role_exists?(role)
55
55
 
56
56
  permit = Conjur::DSL2::Types::Permit.new
57
57
  permit.resource = resource_record target
@@ -72,7 +72,10 @@ module Conjur
72
72
  Planner.planner_for(record, api)
73
73
  end.sort
74
74
 
75
+ log{ "Planing policy with body #{planners.map{|p| p.class.name}}" }
76
+
75
77
  planners.each do |planner|
78
+ planner.log{ "Planning #{planner}"}
76
79
  ownerid = plan.ownerid
77
80
  begin
78
81
  plan.policy = self.record
@@ -87,9 +90,9 @@ module Conjur
87
90
  plan.ownerid = ownerid
88
91
 
89
92
  planner.plan = plan
90
- planner.trace("planning...")
93
+ planner.log { "Planning policy record #{record}" }
91
94
  planner.do_plan
92
- planner.trace("ok!")
95
+ planner.log { "Done" }
93
96
  ensure
94
97
  plan.policy = nil
95
98
  plan.ownerid = ownerid
@@ -10,13 +10,16 @@ module Conjur
10
10
  def plan records, api, options = {}
11
11
  namespace = options[:namespace]
12
12
  ownerid = options[:ownerid]
13
- Plan.new.tap do |plan|
13
+ plan = options[:plan] || Plan.new
14
+ plan.tap do |plan|
14
15
  plan.namespace = namespace if namespace
15
16
  plan.ownerid = ownerid if ownerid
16
- records.map{ |record| planner_for(record, api) }.sort.each do |planner|
17
+ Array(records).map{ |record| planner_for(record, api) }.sort.each do |planner|
17
18
  planner.plan = plan
19
+ planner.log { %Q(Planning "#{planner.record} using #{planner.class}") }
18
20
  begin
19
21
  planner.do_plan
22
+ planner.log { "\tFinished \"#{planner.record}\"" }
20
23
  ensure
21
24
  planner.plan = nil
22
25
  end
@@ -14,7 +14,7 @@ module Conjur
14
14
  end
15
15
 
16
16
  def to_s
17
- "Permit #{role.role} to '#{privilege}' #{resource}#{role.admin ? ' with grant option' : ''}"
17
+ "Permit #{role.role} to [#{Array(privilege).join(', ')}] on #{Array(resource).join(', ')}#{role.admin ? ' with grant option' : ''}"
18
18
  end
19
19
  end
20
20
  end
@@ -2,16 +2,10 @@ module Conjur
2
2
  module DSL2
3
3
  module YAML
4
4
  class Handler < Psych::Handler
5
+ include Conjur::DSL2::Logger
6
+
5
7
  attr_accessor :parser, :filename, :result
6
8
 
7
- # Override the logger with this method.
8
- cattr_accessor :logger
9
-
10
- require 'logger'
11
-
12
- self.logger = Logger.new(STDERR)
13
- self.logger.level = Logger::INFO
14
-
15
9
  # An abstract Base handler. The handler will receive each document message within
16
10
  # its particular context (sequence, mapping, etc).
17
11
  #
@@ -14,7 +14,7 @@ module Conjur
14
14
  rescue
15
15
  handler.log { $!.message }
16
16
  handler.log { $!.backtrace.join(" \n") }
17
- raise Invalid.new($!.message, filename, parser.mark)
17
+ raise Invalid.new($!.message || "(no message)", filename, parser.mark)
18
18
  end
19
19
  handler.result
20
20
  end
@@ -1,7 +1,7 @@
1
1
  module Conjur
2
2
  module Asset
3
3
  module DSL2
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.3"
5
5
  end
6
6
  end
7
7
  end
@@ -6,7 +6,13 @@ require 'active_support/core_ext'
6
6
  SafeYAML::OPTIONS[:default_mode] = :safe
7
7
  SafeYAML::OPTIONS[:deserialize_symbols] = false
8
8
 
9
+ module Conjur
10
+ module DSL2
11
+ end
12
+ end
13
+
9
14
  require 'rest-client'
15
+ require 'conjur/dsl2/logger'
10
16
  require 'conjur/dsl2/invalid'
11
17
  require 'conjur/dsl2/types/base'
12
18
  require 'conjur/dsl2/types/records'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-asset-dsl2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-05 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
@@ -201,6 +201,7 @@ files:
201
201
  - lib/conjur/dsl2/executor/revoke.rb
202
202
  - lib/conjur/dsl2/executor/update.rb
203
203
  - lib/conjur/dsl2/invalid.rb
204
+ - lib/conjur/dsl2/logger.rb
204
205
  - lib/conjur/dsl2/plan.rb
205
206
  - lib/conjur/dsl2/planner.rb
206
207
  - lib/conjur/dsl2/planner/base.rb