This repository has been archived by the owner on Aug 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
credentials_requests.rb
56 lines (47 loc) · 1.85 KB
/
credentials_requests.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'json'
require 'date'
def get_service_key(guid)
JSON.parse(`cf curl /v2/service_keys/#{guid}`)
end
def find_service_key(service_instance_guid, username, password)
service_key = nil
service_keys = get_service_keys(service_instance_guid)
while !service_key
service_key = service_keys['resources'].to_a.select{|keys| (keys['entity']['credentials']['username'] == username) && (keys['entity']['credentials']['password'] == password)}.first
break unless service_keys['next_url']
service_keys = JSON.parse(`cf curl "#{service_keys['next_url']}"`)
end
service_key
end
def get_service_keys(service_instance_guid, page = 0)
JSON.parse(`cf curl /v2/service_instances/#{service_instance_guid}/service_keys`).to_h
end
def get_service_instance(service_instance_guid)
si = JSON.parse(`cf curl /v2/service_instances/#{service_instance_guid}`).to_h
if si.empty?
si = JSON.parse(`cf curl /v2/service_instances?q=name:#{service_instance_guid}`).to_h['resources'].to_a.first.to_h
end
si
end
def refresh_service_key(service_instance_name)
service_key = "#{service_instance_name}-#{DateTime.now.strftime("%Y%m%d%H%M%S")}"
`cf create-service-key #{service_instance_name} #{service_key}`
# puts "fetching => service-key #{service_instance_name} #{service_key}"
sk = `cf service-key #{service_instance_name} #{service_key}`
JSON.parse(sk[(sk.index("\n\n")),1000])
end
def get_user_provided_service(service_instance_guid = nil)
endpoint = "cf curl /v2/user_provided_service_instances"
if service_instance_guid
ups = JSON.parse(`#{endpoint}/#{service_instance_guid}`).to_h
unless ups['entity']
ups = JSON.parse(`#{endpoint}?q=name:#{service_instance_guid}`).to_h['resources'].first
end
else
ups = JSON.parse(`#{endpoint}`).to_h
end
ups
end
def delete_service_key(server_instance_name, service_key)
`cf delete-service-key #{server_instance_name} #{service_key} -f`
end