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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/lds-cf-plugin/lds_account_service.rb', line 17
def create_lds_account_service
offerings = client.services
offerings.keep_if { |s| s.label == 'lds-account-service' && s.provider.start_with?('ICS') && s.active }
service = offerings.first
if !service
fail "Cannot find LDS Account service on #{client.target}"
end
if service.version != "0.1"
fail "Your lds-cf-plugin version is out of date. To update execute `gem update lds-cf-plugin`"
end
rest_client = CFoundry::RestClient.new(service.url, client.token)
rest_client.trace = client.trace
instance_name = input[:name]
if !instance_name
instance_name = ask("Name")
end
plan = service.service_plans.first
choices = ["prod", "stage", "community"]
env = input[:env]
if !env || !choices.include?(env)
options = {
:choices => choices,
:display => proc { |choice|
if choice == "prod"
"Prod (gdir)"
elsif choice == "stage"
"Stage (gdirstage)"
elsif choice == "community"
"Community (cdir)"
end
},
:default => "prod",
:allow_other => false
}
env = ask("LDS Account environment to use", options)
end
cn = input[:cn]
while !cn || !is_valid_cn(cn)
if cn && !is_valid_cn(cn)
line c("The cn you provided #{b("'#{cn}'")} is invalid.", :bad)
line c("Perhaps you tried providing a fully qualified principal? We only want the cn= portion. Try again.", :bad)
end
cn = ask("Application account principal Common Name (cn)")
end
password = input[:password]
if !password
password = ask("Application account password", :echo => "*", :forget => true)
end
payload = {
:space_guid => client.current_space.guid,
:name => instance_name,
:env => env,
:cn => cn,
:password => password
}
options = {
:payload => JSON.generate(payload)
}
request, response = rest_client.request("POST", "/register", options)
if response[:status].to_i != 200
fail "Error registering LDS Account service with gateway:\n#{response[:body]}"
end
instance = client.managed_service_instance
instance.name = instance_name
instance.service_plan = plan
instance.space = client.current_space
with_progress("Creating service #{c(instance.name, :name)}") do
instance.create!
end
instance
end
|