Fixes 3
This commit is contained in:
@@ -301,6 +301,71 @@ class HestiaBunkerWebApi
|
||||
return response[:body] || {}
|
||||
end
|
||||
|
||||
|
||||
def set_alias(service_name, list_aliases)
|
||||
@extra_info = ""
|
||||
|
||||
# First get current service configuration to preserve existing settings
|
||||
get_service_response = api_call("GET", "/services/#{service_name}", {})
|
||||
|
||||
if get_service_response[:status] != 200
|
||||
raise BunkerWebApiError.new("Service '#{service_name}' not found")
|
||||
end
|
||||
|
||||
# Extract current variables from the service configuration
|
||||
current_vars = get_service_response[:body]["variables"] || {}
|
||||
|
||||
# Clean the list_aliases string according to the rules
|
||||
cleaned_aliases = list_aliases.to_s
|
||||
|
||||
# Replace commas (with or without space) with a single space
|
||||
cleaned_aliases.gsub!(/,\s?/, ' ')
|
||||
|
||||
# Replace multiple spaces with a single space
|
||||
cleaned_aliases.gsub!(/\s{2,}/, ' ')
|
||||
|
||||
# Strip leading/trailing whitespace
|
||||
cleaned_aliases.strip!
|
||||
|
||||
# Ensure the main service name appears first in the alias list
|
||||
aliases_array = cleaned_aliases.split(' ')
|
||||
unless aliases_array.include?(service_name)
|
||||
# If service_name not present, add it at the front
|
||||
aliases_array.unshift(service_name)
|
||||
else
|
||||
# If present but not first, reorder to make it first
|
||||
aliases_array.delete(service_name)
|
||||
aliases_array.unshift(service_name)
|
||||
end
|
||||
# Rebuild cleaned string
|
||||
cleaned_aliases = aliases_array.join(' ')
|
||||
|
||||
# Update alias settings
|
||||
updated_vars = {
|
||||
"SERVER_NAME" => cleaned_aliases
|
||||
}
|
||||
|
||||
# Merge with existing variables (keep non-SSL settings)
|
||||
final_vars = current_vars.merge(updated_vars)
|
||||
|
||||
service_body = {
|
||||
server_name: nil, # Not changing name
|
||||
is_draft: false, # Keep as online
|
||||
variables: final_vars
|
||||
}
|
||||
|
||||
response = api_call("PATCH", "/services/#{service_name}", {}, JSON.generate(service_body))
|
||||
|
||||
if response[:status] == 200
|
||||
puts "[INFO] SSL configuration updated for service '#{service_name}'"
|
||||
else
|
||||
raise BunkerWebApiError.new("Failed to update SSL configuration: status=#{response[:status]}, body=#{response[:raw_body]}")
|
||||
end
|
||||
|
||||
return response[:body] || {}
|
||||
end
|
||||
|
||||
|
||||
def delete_service_ssl(service_name)
|
||||
|
||||
@extra_info = ""
|
||||
|
||||
Reference in New Issue
Block a user