Merge branch 'develop' into feat/scenario-agents

This commit is contained in:
Shivam Mishra
2025-07-31 10:00:37 +05:30
committed by GitHub
50 changed files with 1166 additions and 295 deletions
@@ -0,0 +1,15 @@
module Enterprise::Api::V1::Accounts::PortalsController
def ssl_status
return render_could_not_create_error(I18n.t('portals.ssl_status.custom_domain_not_configured')) if @portal.custom_domain.blank?
result = Cloudflare::CheckCustomHostnameService.new(portal: @portal).perform
return render_could_not_create_error(result[:errors]) if result[:errors].present?
ssl_settings = @portal.ssl_settings || {}
render json: {
status: ssl_settings['cf_status'],
verification_errors: ssl_settings['cf_verification_errors']
}
end
end
@@ -17,4 +17,25 @@ class Cloudflare::BaseCloudflareZoneService
def zone_id
InstallationConfig.find_by(name: 'CLOUDFLARE_ZONE_ID')&.value
end
def update_portal_ssl_settings(portal, data)
verification_record = data['ownership_verification_http']
ssl_record = data['ssl']
verification_errors = data['verification_errors']&.first || ''
# Start with existing settings to preserve verification data if it exists
ssl_settings = portal.ssl_settings || {}
# Only update verification fields if they exist in the response (during initial setup)
if verification_record.present?
ssl_settings['cf_verification_id'] = verification_record['http_url'].split('/').last
ssl_settings['cf_verification_body'] = verification_record['http_body']
end
# Always update SSL status and errors from current response
ssl_settings['cf_status'] = ssl_record&.dig('status')
ssl_settings['cf_verification_errors'] = verification_errors
portal.update(ssl_settings: ssl_settings)
end
end
@@ -14,21 +14,10 @@ class Cloudflare::CheckCustomHostnameService < Cloudflare::BaseCloudflareZoneSer
data = response.parsed_response['result']
if data.present?
update_portal_ssl_settings(data.first)
update_portal_ssl_settings(@portal, data.first)
return { data: data }
end
{ errors: ['Hostname is missing in Cloudflare'] }
end
private
def update_portal_ssl_settings(data)
verification_record = data['ownership_verification_http']
ssl_settings = {
'cf_verification_id': verification_record['http_url'].split('/').last,
'cf_verification_body': verification_record['http_body']
}
@portal.update(ssl_settings: ssl_settings)
end
end
@@ -12,7 +12,7 @@ class Cloudflare::CreateCustomHostnameService < Cloudflare::BaseCloudflareZoneSe
data = response.parsed_response['result']
if data.present?
update_portal_ssl_settings(data)
update_portal_ssl_settings(@portal, data)
return { data: data }
end
@@ -25,16 +25,13 @@ class Cloudflare::CreateCustomHostnameService < Cloudflare::BaseCloudflareZoneSe
HTTParty.post(
"#{BASE_URI}/zones/#{zone_id}/custom_hostnames",
headers: headers,
body: { hostname: @portal.custom_domain }.to_json
body: {
hostname: @portal.custom_domain,
ssl: {
method: 'http',
type: 'dv'
}
}.to_json
)
end
def update_portal_ssl_settings(data)
verification_record = data['ownership_verification_http']
ssl_settings = {
'cf_verification_id': verification_record['http_url'].split('/').last,
'cf_verification_body': verification_record['http_body']
}
@portal.update(ssl_settings: ssl_settings)
end
end
@@ -15,7 +15,8 @@ class Llm::BaseOpenAiService
private
def uri_base
InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT')&.value || 'https://api.openai.com/'
endpoint = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT')&.value
endpoint.presence || 'https://api.openai.com/'
end
def setup_model