87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/shared_tools/tools/devops_toolkit.rb', line 87
def execute(operation:, environment: "staging", **options)
operation_id = SecureRandom.uuid
@logger.info("DevOpsToolkit#execute operation=#{operation} environment=#{environment} operation_id=#{operation_id}")
unless valid_environment?(environment)
return {
success: false,
error: "Invalid environment: #{environment}",
valid_environments: ["development", "staging", "production"]
}
end
if environment == "production" && !options[:production_confirmed]
@logger.warn("Production operation attempted without confirmation")
return {
success: false,
error: "Production operations require explicit confirmation",
required_option: "production_confirmed: true",
environment: environment
}
end
log_operation(operation_id, operation, environment, options)
result = case operation
when "deploy"
perform_deployment(environment, options, operation_id)
when "rollback"
perform_rollback(environment, options, operation_id)
when "health_check"
perform_health_check(environment, options, operation_id)
when "log_analysis"
analyze_logs(environment, options, operation_id)
when "metric_collection"
collect_metrics(environment, options, operation_id)
else
{
success: false,
error: "Unknown operation: #{operation}",
valid_operations: ["deploy", "rollback", "health_check", "log_analysis", "metric_collection"]
}
end
result[:operation_id] = operation_id
result
rescue => e
@logger.error("DevOps operation failed: #{e.message}")
{
success: false,
error: "DevOps operation failed: #{e.message}",
error_type: e.class.name,
operation_id: operation_id
}
end
|