Class: Entitlements::Backend::GitHubOrg::Controller

Inherits:
BaseController
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/entitlements/backend/github_org/controller.rb

Constant Summary collapse

C =
::Contracts
AVAILABLE_FEATURES =
%w[invite remove]
DEFAULT_FEATURES =
%w[invite remove]
ROLES =
Entitlements::Backend::GitHubOrg::ORGANIZATION_ROLES.keys.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_name, config = nil) ⇒ Controller

Returns a new instance of Controller.



68
69
70
71
# File 'lib/entitlements/backend/github_org/controller.rb', line 68

def initialize(group_name, config = nil)
  super
  @provider = Entitlements::Backend::GitHubOrg::Provider.new(config: @config)
end

Class Method Details

.priorityObject

Controller priority and registration



50
51
52
# File 'lib/entitlements/backend/github_org/controller.rb', line 50

def self.priority
  30
end

Instance Method Details

#apply(action) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/entitlements/backend/github_org/controller.rb', line 99

def apply(action)
  unless action.existing.is_a?(Entitlements::Models::Group) && action.updated.is_a?(Entitlements::Models::Group)
    logger.fatal "#{action.dn}: GitHub entitlements interface does not support creating or removing a GitHub org"
    raise RuntimeError, "Invalid Operation"
  end

  if provider.commit(action)
    logger.debug "APPLY: Updating GitHub organization #{action.dn}"
  else
    logger.warn "DID NOT APPLY: Changes not needed to #{action.dn}"
    logger.debug "Old: #{action.existing.inspect}"
    logger.debug "New: #{action.updated.inspect}"
  end
end

#calculateObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/entitlements/backend/github_org/controller.rb', line 79

def calculate
  @actions = []

  validate_github_org_ous! # calls read_all() for the OU
  validate_no_dupes!       # calls read() for each group

  if changes.any?
    print_differences(key: group_name, added: [], removed: [], changed: changes, ignored_users:)
    @actions.concat(changes)
  else
    logger.debug "UNCHANGED: No GitHub organization changes for #{group_name}"
  end
end

#prefetchObject



143
144
145
# File 'lib/entitlements/backend/github_org/controller.rb', line 143

def prefetch
  existing_groups
end

#validate_config!(key, data) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/entitlements/backend/github_org/controller.rb', line 121

def validate_config!(key, data)
  spec = COMMON_GROUP_CONFIG.merge({
    "base"             => { required: true, type: String },
    "addr"             => { required: false, type: String },
    "org"              => { required: true, type: String },
    "token"            => { required: true, type: String },
    "features"         => { required: false, type: Array },
    "ignore"           => { required: false, type: Array },
    "ignore_not_found" => { required: false, type: [FalseClass, TrueClass] },
  })
  text = "GitHub organization group #{key.inspect}"
  Entitlements::Util::Util.validate_attr!(spec, data, text)

  # Validate any features against the list of known features.
  if data["features"].is_a?(Array)
    invalid_flags = data["features"] - AVAILABLE_FEATURES
    if invalid_flags.any?
      raise "Invalid feature(s) in #{text}: #{invalid_flags.join(', ')}"
    end
  end
end