Skip to content

Commit

Permalink
Offload user filtering to Azure API to avoid resource problems in a l…
Browse files Browse the repository at this point in the history
…arge AD

 - Modify Azure::Graph.users to pass a filter parameter to Azure REST API
 - Modify AzurermAdUsers to pass a filter parameter to Azure::Graph.users

Signed-off-by: Richard Nixon <richard.nixon@btinternet.com>
  • Loading branch information
trickyearlobe authored and Stuart Paterson committed Dec 17, 2019
1 parent f1eee20 commit c266b59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions libraries/azurerm_ad_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class AzurermAdUsers < AzurermPluralResource
.register_column(:user_types, field: :userType)
.install_filter_methods_on_resource(self, :table)

def initialize
resp = graph.users
def initialize(params = {})
@params = params
resp = graph.users(@params)
return if has_error?(resp)

@table = resp
Expand All @@ -35,6 +36,10 @@ def guest_accounts
end

def to_s
'Azure Active Directory Users'
if @params[:filter]
"Azure Active Directory Users with filter( #{@params[:filter]} )"
else
'Azure Active Directory Users'
end
end
end
5 changes: 4 additions & 1 deletion libraries/support/azure/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ def user(id)
)
end

def users
def users(raw_params = {})
cooked_params = {}
cooked_params['$filter'] = raw_params[:filter] unless raw_params[:filter].nil?
get(
url: "/#{tenant_id}/users",
api_version: '1.6',
error_handler: handle_error,
unwrap: unwrap,
params: cooked_params,
)
end

Expand Down

0 comments on commit c266b59

Please sign in to comment.