Fixes 5
This commit is contained in:
@@ -269,8 +269,18 @@ class HestiaBunkerWebApi
|
||||
raise BunkerWebApiError.new("Service '#{service_name}' not found")
|
||||
end
|
||||
|
||||
# Extract current variables from the service configuration
|
||||
current_vars = get_service_response[:body]["variables"] || {}
|
||||
# Extract variables from config - API stores them in 'config' not 'variables'
|
||||
# Each variable is a hash with 'value' as the actual setting value
|
||||
current_vars = {}
|
||||
if get_service_response[:body]["config"]
|
||||
get_service_response[:body]["config"].each do |key, value_hash|
|
||||
if value_hash.is_a?(Hash) && value_hash.key?("value")
|
||||
current_vars[key] = value_hash["value"]
|
||||
else
|
||||
current_vars[key] = value_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Update SSL settings
|
||||
updated_vars = {
|
||||
@@ -312,8 +322,23 @@ class HestiaBunkerWebApi
|
||||
raise BunkerWebApiError.new("Service '#{service_name}' not found")
|
||||
end
|
||||
|
||||
# Extract current variables from the service configuration
|
||||
current_vars = get_service_response[:body]["variables"] || {}
|
||||
# Save the entire current configuration (except server_name which will be replaced)
|
||||
current_config = get_service_response[:body]
|
||||
|
||||
# Extract variables from config - API stores them in 'config' not 'variables'
|
||||
# Each variable is a hash with 'value' as the actual setting value
|
||||
current_vars = {}
|
||||
if current_config["config"]
|
||||
current_config["config"].each do |key, value_hash|
|
||||
if key != "SERVER_NAME"
|
||||
if value_hash.is_a?(Hash) && value_hash.key?("value")
|
||||
current_vars[key] = value_hash["value"]
|
||||
else
|
||||
current_vars[key] = value_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Clean the list_aliases string according to the rules
|
||||
cleaned_aliases = list_aliases.to_s
|
||||
@@ -329,40 +354,39 @@ class HestiaBunkerWebApi
|
||||
|
||||
# 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
|
||||
if aliases_array.include?(service_name)
|
||||
aliases_array.delete(service_name)
|
||||
aliases_array.unshift(service_name)
|
||||
end
|
||||
# Rebuild cleaned string
|
||||
cleaned_aliases = aliases_array.join(' ')
|
||||
current_vars["SERVER_NAME"]=cleaned_aliases
|
||||
|
||||
# Update alias settings
|
||||
updated_vars = {
|
||||
"SERVER_NAME" => cleaned_aliases
|
||||
}
|
||||
|
||||
# Merge with existing variables (keep non-SSL settings)
|
||||
final_vars = current_vars.merge(updated_vars)
|
||||
# Step 1: Delete the old service
|
||||
delete_response = api_call("DELETE", "/services/#{service_name}")
|
||||
if delete_response[:status] != 200 && delete_response[:status] != 204
|
||||
raise BunkerWebApiError.new("Failed to delete service '#{service_name}': status=#{delete_response[:status]}")
|
||||
end
|
||||
puts "[INFO] Service '#{service_name}' deleted"
|
||||
|
||||
# Step 2: Create a new service with the cleaned alias list as server_name
|
||||
# and preserve all existing configuration variables
|
||||
service_body = {
|
||||
server_name: nil, # Not changing name
|
||||
is_draft: false, # Keep as online
|
||||
variables: final_vars
|
||||
server_name: service_name, # Use the full alias list including service_name first
|
||||
is_draft: current_config["is_draft"] || false,
|
||||
variables: current_vars # Preserve all existing variables from the original service
|
||||
}
|
||||
|
||||
response = api_call("PATCH", "/services/#{service_name}", {}, JSON.generate(service_body))
|
||||
post_response = api_call("POST", "/services", {}, JSON.generate(service_body))
|
||||
|
||||
if response[:status] == 200
|
||||
puts "[INFO] SSL configuration updated for service '#{service_name}'"
|
||||
if post_response[:status] == 200 || post_response[:status] == 201
|
||||
puts "[INFO] Service recreated successfully with aliases: #{cleaned_aliases}"
|
||||
elsif post_response[:status] == 409
|
||||
raise BunkerWebApiError.new("Service '#{service_name}' already exists")
|
||||
else
|
||||
raise BunkerWebApiError.new("Failed to update SSL configuration: status=#{response[:status]}, body=#{response[:raw_body]}")
|
||||
raise BunkerWebApiError.new("Failed to create service: status=#{post_response[:status]}, body=#{post_response[:raw_body]}")
|
||||
end
|
||||
|
||||
return response[:body] || {}
|
||||
return post_response || {}
|
||||
end
|
||||
|
||||
|
||||
@@ -377,8 +401,18 @@ class HestiaBunkerWebApi
|
||||
raise BunkerWebApiError.new("Service '#{service_name}' not found")
|
||||
end
|
||||
|
||||
# Extract current variables from the service configuration
|
||||
current_vars = get_service_response[:body]["variables"] || {}
|
||||
# Extract variables from config - API stores them in 'config' not 'variables'
|
||||
# Each variable is a hash with 'value' as the actual setting value
|
||||
current_vars = {}
|
||||
if get_service_response[:body]["config"]
|
||||
get_service_response[:body]["config"].each do |key, value_hash|
|
||||
if value_hash.is_a?(Hash) && value_hash.key?("value")
|
||||
current_vars[key] = value_hash["value"]
|
||||
else
|
||||
current_vars[key] = value_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Update SSL settings
|
||||
updated_vars = {
|
||||
|
||||
Reference in New Issue
Block a user