Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amqp/event_logging_listener.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Forkr.new(Listeners::EventLoggingListener, 1).run
Listeners::EventLoggingListener.run
2 changes: 1 addition & 1 deletion amqp/keycloak_account_creation_listener.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Forkr.new(Listeners::KeycloakAccountCreationListener, 2).run
Listeners::KeycloakAccountCreationListener.run
16 changes: 13 additions & 3 deletions app/models/listeners/event_log_shipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ def on_message(delivery_info, properties, payload)
"#{ec.hbx_id}.#{ec.environment}.q.graylog.events",
{ :durable => true }
)
utf8_payload = payload.nil? ? "" : payload.force_encoding("utf-8")
utf8_payload = payload.nil? ? "" : fix_encoding(payload)
published_queue.publish(JSON.dump(publishing_hash.merge("full_message" => utf8_payload)), {})
channel.acknowledge(delivery_info.delivery_tag, false)
end

def fix_encoding(val)
return val if val.nil? || val.blank?
return val unless val.respond_to?(:encoding)
if [Encoding::ASCII_8BIT].include?(val.encoding)
val.force_encoding(Encoding::UTF_8)
else
val
end
end

def level_from_hash(level_name)
levels = {
"emergency" => 0,
Expand Down Expand Up @@ -47,11 +57,11 @@ def extract_gelf_hash(delivery_info, properties)
}.merge(extract_host(properties))
properties.to_hash.each_pair do |k,v|
if ![:headers, "headers"].include?(k)
new_properties["_#{k.to_s}"] = v
new_properties["_#{k.to_s}"] = fix_encoding(v)
end
end
headers.each_pair do |k,v|
new_properties["_#{k.to_s}"] = v
new_properties["_#{k.to_s}"] = fix_encoding(v)
end
new_properties
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/listeners/keycloak_account_creation_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def self.queue_name

def log_failure(key, code, headers, body)
r_channel = connection.create_channel
r_channel.confirm_select
ex = r_channel.fanout(ExchangeInformation.event_publish_exchange, {:durable => true})
response_properties = {
:timestamp => Time.now.to_i,
Expand All @@ -35,11 +36,13 @@ def log_failure(key, code, headers, body)
})
}
ex.publish(body.to_s || "", response_properties)
r_channel.wait_for_confirms
r_channel.close
end

def send_response(status, headers, r_body)
r_channel = connection.create_channel
r_channel.confirm_select
ex = r_channel.fanout(ExchangeInformation.event_publish_exchange, {:durable => true})
response_properties = {
:timestamp => Time.now.to_i,
Expand All @@ -49,6 +52,7 @@ def send_response(status, headers, r_body)
})
}
ex.publish(r_body.to_s || "", response_properties)
r_channel.wait_for_confirms
r_channel.close
end

Expand Down
16 changes: 13 additions & 3 deletions app/models/listeners/request_log_shipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ def on_message(delivery_info, properties, payload)
"#{ec.hbx_id}.#{ec.environment}.q.graylog.events",
{ :durable => true }
)
utf8_payload = payload.nil? ? "" : payload.force_encoding("utf-8")
utf8_payload = payload.nil? ? "" : fix_encoding(payload)
published_queue.publish(JSON.dump(publishing_hash.merge("full_message" => utf8_payload)), {})
channel.acknowledge(delivery_info.delivery_tag, false)
end

def fix_encoding(val)
return val if val.nil? || val.blank?
return val unless val.respond_to?(:encoding)
if [Encoding::ASCII_8BIT].include?(val.encoding)
val.force_encoding(Encoding::UTF_8)
else
val
end
end

def extract_host(props)
props_strings = props.to_hash.stringify_keys
return({}) if !props_strings.has_key?("host")
Expand All @@ -31,11 +41,11 @@ def extract_gelf_hash(delivery_info, properties)
}.merge(extract_host(properties))
properties.to_hash.each_pair do |k,v|
if ![:headers, "headers"].include?(k)
new_properties["_#{k.to_s}"] = v
new_properties["_#{k.to_s}"] = fix_encoding(v)
end
end
headers.each_pair do |k,v|
new_properties["_#{k.to_s}"] = v
new_properties["_#{k.to_s}"] = fix_encoding(v)
end
new_properties
end
Expand Down
53 changes: 16 additions & 37 deletions app/models/proxies/keycloak_account_creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,30 @@ def endpoint
"hbxstaff" => HBX_STAFF_URI
}

=begin
def initiate_call(data)
data = r_data.stringify_keys
first_name = data["first_name"]
last_name = data["last_name"]
email = data["email"] || "noemail@email.com"
password = data["password"]
account_role = data["account_role"]
user_name = data["username"].try(:downcase)
user_name ||= data["email"]
account_role_key = account_role.blank? ? "individual" : account_role
relay_state = USER_ROLE_MAPPING.fetch(account_role_key, INDIVIDUAL_ROLE_URI)
email_verified = true
locale = "en"

KeycloakAdmin.configure do |config|
config.use_service_account = false
config.server_url = ExchangeInformation.keycloak_url
config.server_domain = ExchangeInformation.keycloak_domain
config.client_id = ExchangeInformation.keycloak_client_id
config.client_realm_name = ExchangeInformation.keycloak_realm
config.username = ExchangeInformation.keycloak_username
config.password = ExchangeInformation.keycloak_password
# config.rest_client_options = { verify_ssl: OpenSSL::SSL::VERIFY_NONE }
def fix_encoding(val)
return val if val.nil? || val.blank?
return val unless val.respond_to?(:encoding)
if [Encoding::ASCII_8BIT].include?(val.encoding)
val.force_encoding(Encoding::UTF_8)
else
val
end

KeycloakAdmin.realm(ExchangeInformation.keycloak_realm).users.create!(user_name, email, password, email_verified, locale)

end
=end

def post_user(r_data)
data = r_data.stringify_keys
first_name = data["first_name"]
last_name = data["last_name"]
email = data["email"]
password = data["password"]
system_flag = data["system_flag"]
account_role = data["account_role"]
user_name = data["username"].try(:downcase)
user_name ||= data["email"]
first_name = fix_encoding(data["first_name"])
last_name = fix_encoding(data["last_name"])
email = fix_encoding(data["email"])
password = fix_encoding(data["password"])
system_flag = fix_encoding(data["system_flag"])
account_role = fix_encoding(data["account_role"])
user_name = fix_encoding(data["username"]).try(:downcase)
user_name ||= fix_encoding(data["email"])
account_role_key = account_role.blank? ? "individual" : account_role
relay_state = USER_ROLE_MAPPING.fetch(account_role_key, INDIVIDUAL_ROLE_URI)
email_verified = true
locale = "en"
locale = "en"

request_data = {
email: email.present? ? email.downcase : "",
Expand Down