Module: Neetob::CLI::WorkspacePermissions::PermissionHelpers
- Included in:
- AddMemberToAllApps, AddMemberToAllWorkspaces
- Defined in:
- lib/neetob/cli/workspace_permissions/permission_helpers.rb
Instance Method Summary collapse
- #build_url(workspace, app) ⇒ Object
- #parse_api_keys(group_by:) ⇒ Object
- #post_member_to(url:, api_key:, email:, role:, workspace:, app:) ⇒ Object
Instance Method Details
#build_url(workspace, app) ⇒ Object
8 9 10 |
# File 'lib/neetob/cli/workspace_permissions/permission_helpers.rb', line 8 def build_url(workspace, app) "https://#{workspace}.#{app}.com/api/external/v1/team_members" end |
#parse_api_keys(group_by:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/neetob/cli/workspace_permissions/permission_helpers.rb', line 12 def parse_api_keys(group_by:) ENV.each_with_object({}) do |(key, value), acc| next unless key.end_with?("_API_KEY") && key.include?("__") workspace_part, app_part = key.split("__", 2) next unless app_part && workspace_part workspace = workspace_part.downcase app = app_part.gsub("_API_KEY", "").downcase case group_by when :workspace acc[workspace] ||= {} acc[workspace][app] = value when :app acc[app] ||= {} acc[app][workspace] = value end end end |
#post_member_to(url:, api_key:, email:, role:, workspace:, app:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/neetob/cli/workspace_permissions/permission_helpers.rb', line 33 def post_member_to(url:, api_key:, email:, role:, workspace:, app:) body = { organization_role: role, emails: [email] } headers = { "X-Api-Key" => api_key, "Content-Type" => "application/json" } response = HTTParty.post(url, body: body.to_json, headers:, follow_redirects: false) if response.code == 200 ui.success("✅ Successfully added #{email} to #{workspace}.#{app} with the role #{role}.\n\n") elsif response.code == 302 ui.error("❌ Could not add #{email} to #{workspace}.#{app} with role #{role}.") ui.say("ℹ️ The #{app} app is not enabled for the workspace #{workspace}.\n\n") elsif response.code == 422 ui.error("❌ Could not add #{email} to #{workspace}.#{app} with role #{role}.") ui.say("Reason: #{response['error']}\n\n") else ui.error("❌ Failed to add #{email} to #{workspace}.#{app} Response status: #{response.code}.\n\n") end end |