Class: Conjur::DSL::Runner
- Inherits:
-
Object
- Object
- Conjur::DSL::Runner
- Includes:
- IdentifierManipulation
- Defined in:
- lib/conjur/dsl/runner.rb
Overview
Entry point for the Conjur DSL.
Methods are available in two categories: name scoping and asset building.
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#policy_resource ⇒ Object
readonly
Returns the value of attribute policy_resource.
-
#policy_role ⇒ Object
readonly
Returns the value of attribute policy_role.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Instance Method Summary collapse
- #api ⇒ Object
- #api_keys ⇒ Object
-
#assets ⇒ Object
Provides a hash to export various application specific asset ids (or anything else you want).
-
#create_variable(id = nil, options = {}, &block) ⇒ Object
purpose and existence of this method are unobvious for model designer just “variable” in DSL works fine through method_missing is this method OBSOLETED ? basecamp.com/1949725/projects/4268938-api-version-4-x/todos/84972543-low-variable.
- #current_object ⇒ Object
-
#current_scope ⇒ Object
Current scope, used as a path/delimited/prefix to a role or resource id.
-
#current_user_scope ⇒ Object
Current scope, used for user@scope.
- #execute ⇒ Object
-
#initialize(script, filename = nil) ⇒ Runner
constructor
A new instance of Runner.
- #namespace(ns = nil, &block) ⇒ Object (also: #model)
- #owner=(owner) ⇒ Object
- #owns ⇒ Object
- #policy(id, &block) ⇒ Object
- #resource(kind, id, options = {}, &block) ⇒ Object
- #role(kind, id, options = {}, &block) ⇒ Object
- #scope(name = nil, &block) ⇒ Object
Methods included from IdentifierManipulation
#conjur_account, #full_resource_id, #get_kind_and_id_from_args
Constructor Details
#initialize(script, filename = nil) ⇒ Runner
Returns a new instance of Runner.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/conjur/dsl/runner.rb', line 14 def initialize(script, filename = nil) @context = { "account" => Conjur.account, "api_keys" => {} } @context['env'] = Conjur.env unless Conjur.env == 'production' @context['stack'] = Conjur.stack unless Conjur.stack == 'v4' @context['appliance_url'] = Conjur.configuration.appliance_url unless Conjur.configuration.appliance_url.nil? @context['ssl_certificate'] = File.read(Conjur::Config[:cert_file]) unless Conjur::Config[:cert_file].nil? @script = script @filename = filename @api = nil @scopes = Array.new @owners = Array.new @objects = Array.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (protected)
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/conjur/dsl/runner.rb', line 161 def method_missing(sym, *args, &block) if create_compatible_args?(args) && api.respond_to?(sym) id = args[0] id = qualify_id(id, sym) find_or_create sym, id, args[1] || {}, &block elsif current_object && current_object.respond_to?(sym) current_object.send(sym, *args, &block) else super end end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
11 12 13 |
# File 'lib/conjur/dsl/runner.rb', line 11 def context @context end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
11 12 13 |
# File 'lib/conjur/dsl/runner.rb', line 11 def filename @filename end |
#policy_resource ⇒ Object (readonly)
Returns the value of attribute policy_resource.
12 13 14 |
# File 'lib/conjur/dsl/runner.rb', line 12 def policy_resource @policy_resource end |
#policy_role ⇒ Object (readonly)
Returns the value of attribute policy_role.
12 13 14 |
# File 'lib/conjur/dsl/runner.rb', line 12 def policy_role @policy_role end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
11 12 13 |
# File 'lib/conjur/dsl/runner.rb', line 11 def script @script end |
Instance Method Details
#api ⇒ Object
44 45 46 |
# File 'lib/conjur/dsl/runner.rb', line 44 def api @api ||= connect end |
#api_keys ⇒ Object
52 53 54 |
# File 'lib/conjur/dsl/runner.rb', line 52 def api_keys @context["api_keys"] end |
#assets ⇒ Object
Provides a hash to export various application specific asset ids (or anything else you want)
40 41 42 |
# File 'lib/conjur/dsl/runner.rb', line 40 def assets @context['assets'] ||= {} end |
#create_variable(id = nil, options = {}, &block) ⇒ Object
purpose and existence of this method are unobvious for model designer just “variable” in DSL works fine through method_missing is this method OBSOLETED ?
https://basecamp.com/1949725/projects/4268938-api-version-4-x/todos/84972543-low-variable
129 130 131 132 133 134 135 |
# File 'lib/conjur/dsl/runner.rb', line 129 def create_variable id = nil, = {}, &block [:id] = id if id mime_type = .delete(:mime_type) || 'text/plain' kind = .delete(:kind) || 'secret' var = api.create_variable(mime_type, kind, ) do_object var, &block end |
#current_object ⇒ Object
56 57 58 |
# File 'lib/conjur/dsl/runner.rb', line 56 def current_object !@objects.empty? ? @objects.last : nil end |
#current_scope ⇒ Object
Current scope, used as a path/delimited/prefix to a role or resource id.
61 62 63 |
# File 'lib/conjur/dsl/runner.rb', line 61 def current_scope !@scopes.empty? ? @scopes.join('/') : nil end |
#current_user_scope ⇒ Object
Current scope, used for user@scope.
66 67 68 |
# File 'lib/conjur/dsl/runner.rb', line 66 def current_user_scope current_scope ? current_scope.gsub(/[^\w]/, '-') : nil end |
#execute ⇒ Object
109 110 111 112 113 |
# File 'lib/conjur/dsl/runner.rb', line 109 def execute args = [ script ] args << filename if filename instance_eval(*args) end |
#namespace(ns = nil, &block) ⇒ Object Also known as: model
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/conjur/dsl/runner.rb', line 78 def namespace ns = nil, &block if block_given? ns ||= context["namespace"] if ns.nil? require 'conjur/api/variables' ns = context["namespace"] = api.create_variable("text/plain", "namespace").id end do_scope ns, &block context else @scopes[0] end end |
#owner=(owner) ⇒ Object
33 34 35 36 |
# File 'lib/conjur/dsl/runner.rb', line 33 def owner=(owner) raise "Owner should only be set once" unless @owners.empty? @owners.push owner end |
#owns ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/conjur/dsl/runner.rb', line 137 def owns @owners.push current_object begin yield ensure @owners.pop end end |
#policy(id, &block) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/conjur/dsl/runner.rb', line 92 def policy id, &block self.role "policy", id do |role| @policy_role = role context["policy"] = role.identifier self.owns do self.resource "policy", id do |resource| @policy_resource = resource scope id do block.call if block_given? end end end end end |
#resource(kind, id, options = {}, &block) ⇒ Object
115 116 117 118 |
# File 'lib/conjur/dsl/runner.rb', line 115 def resource kind, id, = {}, &block id = full_resource_id([kind, qualify_id(id, kind) ].join(':')) find_or_create :resource, id, , &block end |
#role(kind, id, options = {}, &block) ⇒ Object
120 121 122 123 |
# File 'lib/conjur/dsl/runner.rb', line 120 def role kind, id, = {}, &block id = full_resource_id([ kind, qualify_id(id, kind) ].join(':')) find_or_create :role, id, , &block end |
#scope(name = nil, &block) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/conjur/dsl/runner.rb', line 70 def scope name = nil, &block if name != nil do_scope name, &block else current_scope end end |