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.
-
#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)
- #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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/conjur/dsl/runner.rb', line 13 def initialize(script, filename = nil) @context = { "env" => Conjur.env, "stack" => Conjur.stack, "account" => Conjur.account, "api_keys" => {} } @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)
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/conjur/dsl/runner.rb', line 149 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 |
#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
34 35 36 |
# File 'lib/conjur/dsl/runner.rb', line 34 def api @api ||= connect end |
#api_keys ⇒ Object
42 43 44 |
# File 'lib/conjur/dsl/runner.rb', line 42 def api_keys @context["api_keys"] end |
#assets ⇒ Object
Provides a hash to export various application specific asset ids (or anything else you want)
30 31 32 |
# File 'lib/conjur/dsl/runner.rb', line 30 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
117 118 119 120 121 122 123 |
# File 'lib/conjur/dsl/runner.rb', line 117 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
46 47 48 |
# File 'lib/conjur/dsl/runner.rb', line 46 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.
51 52 53 |
# File 'lib/conjur/dsl/runner.rb', line 51 def current_scope !@scopes.empty? ? @scopes.join('/') : nil end |
#current_user_scope ⇒ Object
Current scope, used for user@scope.
56 57 58 |
# File 'lib/conjur/dsl/runner.rb', line 56 def current_user_scope current_scope ? current_scope.gsub(/[^\w]/, '-') : nil end |
#execute ⇒ Object
97 98 99 100 101 |
# File 'lib/conjur/dsl/runner.rb', line 97 def execute args = [ script ] args << filename if filename instance_eval(*args) end |
#namespace(ns = nil, &block) ⇒ Object Also known as: model
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/conjur/dsl/runner.rb', line 68 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 |
#owns ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/conjur/dsl/runner.rb', line 125 def owns @owners.push current_object begin yield ensure @owners.pop end end |
#policy(id, &block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/conjur/dsl/runner.rb', line 82 def policy id, &block self.role "policy", id do |role| context["policy"] = role.identifier self.owns do self.resource "policy", id do scope id do block.call if block_given? end end end end end |
#resource(kind, id, options = {}, &block) ⇒ Object
103 104 105 106 |
# File 'lib/conjur/dsl/runner.rb', line 103 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
108 109 110 111 |
# File 'lib/conjur/dsl/runner.rb', line 108 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
60 61 62 63 64 65 66 |
# File 'lib/conjur/dsl/runner.rb', line 60 def scope name = nil, &block if name != nil do_scope name, &block else current_scope end end |