zuora_connect 3.1.0.pre.c → 3.1.0.pre.g
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/zuora_connect/api/v1/app_instance_controller.rb +5 -0
- data/app/controllers/zuora_connect/application_controller.rb +5 -3
- data/app/models/zuora_connect/app_instance_base.rb +25 -19
- data/app/views/zuora_connect/application/ldap_login.html.erb +3 -2
- data/lib/zuora_connect/controllers/helpers.rb +10 -25
- data/lib/zuora_connect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4e2a1cd708b1c3c361604650519282a485b16b9995bc9b4f202025483241686
|
4
|
+
data.tar.gz: 9c74913350e9fecc2c09221145bb3a17d99406fc869c7dfbd6d905f681f4dff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb9acf273feece3615c01183118fc8c3848d0e75019dfcf02da9d94e0d5d51fbd27bebde5832c86ff0fb3fcb77394b57189ea19003f1d122baf76749f577ad57
|
7
|
+
data.tar.gz: e4a24d248536c517797499550bc107f07c7bee479dd7621fc0d051b97f7ba10de40bd8d6490d08b66b9a1743a86c5cb415b4337257cbc26e6b9bcc309bcf29b2
|
@@ -43,7 +43,12 @@ module ZuoraConnect
|
|
43
43
|
|
44
44
|
def cache_bust
|
45
45
|
if defined?(Redis.current)
|
46
|
+
@appinstance.fetch_connect_data #Fetch data and set in database if kms key is used
|
47
|
+
@appinstance.cache_app_instance(force_cache: true) #Update cache in redis
|
46
48
|
Redis.current.del("AppInstance:#{@appinstance.id}")
|
49
|
+
@appinstance.cache_app_instance(force_cache: true) #Update cache in redis
|
50
|
+
#TODO: Could be a chance another thread cache back to old value, but will eventually cache will get consitent, move to nolonger needing redis cache
|
51
|
+
|
47
52
|
respond_to do |format|
|
48
53
|
format.json {render json: {}, status: :ok}
|
49
54
|
end
|
@@ -12,7 +12,9 @@ module ZuoraConnect
|
|
12
12
|
|
13
13
|
begin
|
14
14
|
if ZuoraConnect::LDAP::Adapter.valid_credentials?(username, password)
|
15
|
-
|
15
|
+
id = ZuoraConnect::AppInstance.first.id
|
16
|
+
session["appInstance"] = ZuoraConnect::AppInstance.first.id
|
17
|
+
session["#{id}::admin"] = true
|
16
18
|
respond_to do |format|
|
17
19
|
format.html { redirect_to '/admin/app_instances' }
|
18
20
|
end
|
@@ -20,13 +22,13 @@ module ZuoraConnect
|
|
20
22
|
render 'zuora_connect/application/ldap_login', locals: {
|
21
23
|
title: 'LDAP Authentication Failed',
|
22
24
|
message: 'Invalid username or password'
|
23
|
-
}
|
25
|
+
}, :layout => false
|
24
26
|
end
|
25
27
|
rescue Net::LDAP::Error
|
26
28
|
render 'zuora_connect/application/ldap_login', locals: {
|
27
29
|
title: 'LDAP Authentication Net Error',
|
28
30
|
message: 'Failed to connect to server while authenticating the LDAP credentials. Please retry later.'
|
29
|
-
}
|
31
|
+
}, :layout => false
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -264,6 +264,7 @@ module ZuoraConnect
|
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
267
|
+
tenants = (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).select {|entity| !entity['skip'].to_bool}.map{|e| e['entityId']}.uniq if tenants.blank?
|
267
268
|
params = {
|
268
269
|
name: self.task_data.dig('name'),
|
269
270
|
zuora_entity_ids: (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).select {|entity| !entity['skip'].to_bool}.map{|e| e['id']}.uniq,
|
@@ -351,28 +352,33 @@ module ZuoraConnect
|
|
351
352
|
self.id >= 25000000
|
352
353
|
end
|
353
354
|
|
355
|
+
def fetch_connect_data(session: {})
|
356
|
+
self.check_oauth_state
|
357
|
+
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
358
|
+
|
359
|
+
if response.code == 200
|
360
|
+
begin
|
361
|
+
parsed_json = JSON.parse(response.body)
|
362
|
+
rescue JSON::ParserError => ex
|
363
|
+
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("JSON parse error", response.body, response.code)
|
364
|
+
end
|
365
|
+
|
366
|
+
self.build_task(task_data: parsed_json, session: session)
|
367
|
+
self.set_backup_creds
|
368
|
+
self.save(validate: false) if self.changed?
|
369
|
+
else
|
370
|
+
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
|
354
375
|
def refresh(session: {})
|
355
376
|
refresh_count ||= 0
|
356
377
|
skip_connect ||= ZuoraConnect.configuration.skip_connect
|
357
378
|
begin
|
358
379
|
#Check how app was deployed
|
359
|
-
if !self.auto_deployed? && !skip_connect
|
360
|
-
self.
|
361
|
-
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
362
|
-
|
363
|
-
if response.code == 200
|
364
|
-
begin
|
365
|
-
parsed_json = JSON.parse(response.body)
|
366
|
-
rescue JSON::ParserError => ex
|
367
|
-
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("JSON parse error", response.body, response.code)
|
368
|
-
end
|
369
|
-
|
370
|
-
self.build_task(task_data: parsed_json, session: session)
|
371
|
-
self.set_backup_creds
|
372
|
-
self.save(validate: false) if self.changed?
|
373
|
-
else
|
374
|
-
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
375
|
-
end
|
380
|
+
if !self.auto_deployed? && (!skip_connect || self['zuora_logins'].blank?)
|
381
|
+
self.fetch_connect_data(session: session)
|
376
382
|
else
|
377
383
|
self.build_task(task_data: self.zuora_logins, session: session)
|
378
384
|
end
|
@@ -775,10 +781,10 @@ module ZuoraConnect
|
|
775
781
|
Redis.current.del("AppInstance:#{self.id}")
|
776
782
|
end
|
777
783
|
|
778
|
-
def cache_app_instance
|
784
|
+
def cache_app_instance(force_cache: false)
|
779
785
|
if defined?(Redis.current)
|
780
786
|
#Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
|
781
|
-
if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
|
787
|
+
if self.task_data.present? && ((self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i ) || force_cache)
|
782
788
|
ZuoraConnect.logger.debug("Caching AppInstance", self.default_ougai_items)
|
783
789
|
Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
|
784
790
|
end
|
@@ -305,7 +305,7 @@ module ZuoraConnect
|
|
305
305
|
private
|
306
306
|
def setup_instance_via_prod_mode
|
307
307
|
zuora_entity_id = request.headers['ZuoraCurrentEntity'] || cookies['ZuoraCurrentEntity']
|
308
|
-
ZuoraConnect::ZuoraUser.current_user_id =
|
308
|
+
ZuoraConnect::ZuoraUser.current_user_id = '3'
|
309
309
|
|
310
310
|
if zuora_entity_id.present?
|
311
311
|
zuora_tenant_id = cookies['Zuora-Tenant-Id']
|
@@ -320,11 +320,6 @@ module ZuoraConnect
|
|
320
320
|
elsif cookies['ZSession'].present?
|
321
321
|
zuora_client = ZuoraAPI::Basic.new(url: "https://#{zuora_host}", session: cookies['ZSession'], entity_id: zuora_entity_id)
|
322
322
|
auth_headers.merge!({'Authorization' => "ZSession-a3N2w #{zuora_client.get_session(prefix: false, auth_type: :basic)}"})
|
323
|
-
elsif session["ldapAdmin"]
|
324
|
-
ZuoraConnect::logger.debug("Admin session found")
|
325
|
-
elsif ZuoraConnect::AppInstance::INTERNAL_HOSTS.include?(request.headers.fetch("HOST", nil))
|
326
|
-
render "zuora_connect/application/ldap_login"
|
327
|
-
return
|
328
323
|
else
|
329
324
|
render "zuora_connect/static/error_handled", :locals => {
|
330
325
|
:title => "Missing Authorization Token",
|
@@ -341,7 +336,7 @@ module ZuoraConnect
|
|
341
336
|
missmatched_entity = session["ZuoraCurrentEntity"] != zuora_entity_id
|
342
337
|
missing_identity = session["ZuoraCurrentIdentity"].blank?
|
343
338
|
|
344
|
-
if (missing_identity || missmatched_entity || different_zsession)
|
339
|
+
if (missing_identity || missmatched_entity || different_zsession)
|
345
340
|
zuora_details.merge!({'identity' => {'different_zsession' => different_zsession, 'missing_identity' => missing_identity, 'missmatched_entity' => missmatched_entity}})
|
346
341
|
identity, response = zuora_client.rest_call(
|
347
342
|
url: zuora_client.rest_endpoint("identity"),
|
@@ -382,10 +377,7 @@ module ZuoraConnect
|
|
382
377
|
end
|
383
378
|
end
|
384
379
|
|
385
|
-
if
|
386
|
-
appinstances = ZuoraConnect::AppInstance.pluck(:id, :name)
|
387
|
-
#Find matching app instances.
|
388
|
-
elsif zuora_instance_id.present?
|
380
|
+
if zuora_instance_id.present?
|
389
381
|
appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host AND id = :id", entities: [zuora_entity_id], host: zuora_client.rest_domain, id: zuora_instance_id.to_i).pluck(:id, :name)
|
390
382
|
else
|
391
383
|
#if app_instance_ids is present then permissions still controlled by connect
|
@@ -423,23 +415,11 @@ module ZuoraConnect
|
|
423
415
|
appinstances ||= ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
|
424
416
|
end
|
425
417
|
|
426
|
-
|
427
|
-
zuora_user_id = "3"
|
428
|
-
else
|
429
|
-
zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId'] || request.headers["Zuora-User-Id"]
|
430
|
-
end
|
418
|
+
zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId'] || request.headers["Zuora-User-Id"]
|
431
419
|
|
432
420
|
if appinstances.size == 1
|
433
421
|
ZuoraConnect.logger.debug("Instance is #{appinstances.to_h.keys.first}")
|
434
422
|
@appinstance = ZuoraConnect::AppInstance.find(appinstances.to_h.keys.first)
|
435
|
-
session["appInstance"] = @appinstance.id
|
436
|
-
ZuoraConnect::ZuoraUser.current_user_id = zuora_user_id
|
437
|
-
end
|
438
|
-
|
439
|
-
if session["ldapAdmin"]
|
440
|
-
# Maybe error. Should we return because of condition?
|
441
|
-
session["#{@appinstance.id}::admin"] = true
|
442
|
-
return
|
443
423
|
end
|
444
424
|
|
445
425
|
# One deployed instance with credentials
|
@@ -643,7 +623,12 @@ module ZuoraConnect
|
|
643
623
|
if session["appInstance"].present?
|
644
624
|
@appinstance = ZuoraConnect::AppInstance.find_by(:id => session["appInstance"])
|
645
625
|
else
|
646
|
-
|
626
|
+
if ZuoraConnect::AppInstance::INTERNAL_HOSTS.include?(request.headers.fetch("HOST", nil))
|
627
|
+
render "zuora_connect/application/ldap_login", :layout => false
|
628
|
+
return
|
629
|
+
else
|
630
|
+
raise ZuoraConnect::Exceptions::AccessDenied.new("No application state or session found.")
|
631
|
+
end
|
647
632
|
end
|
648
633
|
end
|
649
634
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.0.pre.
|
4
|
+
version: 3.1.0.pre.g
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apartment
|