Skip to content

Commit 3670d31

Browse files
committed
Add uaa client for creating shadow users
1 parent 62ec2dc commit 3670d31

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

lib/cloud_controller/config_schemas/base/api_schema.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ class ApiSchema < VCAP::Config
5858
optional(:ca_file) => String,
5959
:client_timeout => Integer,
6060
optional(:symmetric_secret) => String,
61-
optional(:symmetric_secret2) => String
61+
optional(:symmetric_secret2) => String,
62+
optional(:clients) => [
63+
{
64+
'name' => String,
65+
'id' => String,
66+
'secret' => String
67+
}
68+
]
6269
},
6370

6471
logging: {

lib/cloud_controller/dependency_locator.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ def uaa_username_lookup_client
288288
)
289289
end
290290

291+
def uaa_shadow_user_creation_client
292+
client = config.get(:uaa, :clients)&.find { |client| client['name'] == 'cloud_controller_shadow_user_creation' }
293+
294+
return unless client
295+
296+
UaaClient.new(
297+
uaa_target: config.get(:uaa, :internal_url),
298+
client_id: client['id'],
299+
secret: client['secret'],
300+
ca_file: config.get(:uaa, :ca_file)
301+
)
302+
end
303+
291304
def routing_api_client
292305
return RoutingApi::DisabledClient.new if config.get(:routing_api).nil?
293306

spec/unit/lib/cloud_controller/dependency_locator_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,46 @@
568568
locator.bbs_task_client
569569
end
570570
end
571+
572+
describe 'uaa_shadow_user_creation_client' do
573+
before do
574+
TestConfig.override(
575+
uaa: {
576+
internal_url: 'https:/uaa.local',
577+
ca_file: '/var/vcap/uaa.cert',
578+
clients: [
579+
{
580+
'name' => 'cloud_controller_shadow_user_creation',
581+
'id' => 'shadow_user_creation_client_id',
582+
'secret' => 'shadow_user_creation_client_secret'
583+
}
584+
]
585+
}
586+
)
587+
end
588+
589+
it 'creates a new UAA client' do
590+
client = locator.uaa_shadow_user_creation_client
591+
expect(client).to be_an_instance_of(VCAP::CloudController::UaaClient)
592+
expect(client.uaa_target).to eq('https:/uaa.local')
593+
expect(client.ca_file).to eq('/var/vcap/uaa.cert')
594+
expect(client.client_id).to eq('shadow_user_creation_client_id')
595+
expect(client.secret).to eq('shadow_user_creation_client_secret')
596+
end
597+
598+
context 'when the client does not exist in config' do
599+
before do
600+
TestConfig.override(
601+
uaa: {
602+
internal_url: 'https:/uaa.local',
603+
ca_file: '/var/vcap/uaa.cert'
604+
}
605+
)
606+
end
607+
608+
it 'returns nil' do
609+
expect(locator.uaa_shadow_user_creation_client).to be_nil
610+
end
611+
end
612+
end
571613
end

0 commit comments

Comments
 (0)