aboutsummaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-19 21:24:26 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-19 21:47:20 +0100
commit4adfe630b29a85d02cc575533f20623edc935a24 (patch)
treebd91a510025170d1ec13f25c97028245ff540ee9 /app/controllers
parent9d24246300fc0390b0c9719251550d124388c1c3 (diff)
downloadgovuk-mini-environment-admin-4adfe630b29a85d02cc575533f20623edc935a24.tar
govuk-mini-environment-admin-4adfe630b29a85d02cc575533f20623edc935a24.tar.gz
Display Terraform states
Add an index route, and a route to access a historical Terraform state by index. This also makes the ordering explicit, and fixes an issue with wrapped parameters.
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/terraform_http_backend_controller.rb33
1 files changed, 28 insertions, 5 deletions
diff --git a/app/controllers/terraform_http_backend_controller.rb b/app/controllers/terraform_http_backend_controller.rb
index e4d8c54..4d11961 100644
--- a/app/controllers/terraform_http_backend_controller.rb
+++ b/app/controllers/terraform_http_backend_controller.rb
@@ -21,24 +21,47 @@
class TerraformHttpBackendController < ApplicationController
skip_before_action :verify_authenticity_token
+ def index
+ @all_states = TerraformState.all.group_by(&:state_id)
+ end
+
def create
TerraformState.create(
state_id: state_id,
- data: params
+ data: params[:terraform_http_backend]
)
render json: '{ "success": true }', status: 200
end
def show
- state = TerraformState.where(
+ @state = TerraformState.where(
state_id: state_id
- ).last
+ ).order(:id).last
- if state.nil?
+ if @state.nil?
render json: '{}', status: 404
else
- render json: state.data, status: 200
+ render json: @state.data, status: 200
+ end
+ end
+
+ def show_by_index
+ @state = TerraformState.where(
+ state_id: state_id
+ ).order(:id).to_a[params[:index].to_i]
+
+ respond_to do |format|
+ format.html do
+ render :show
+ end
+ format.json do
+ if @state.nil?
+ render json: '{}', status: 404
+ else
+ render json: @state.data, status: 200
+ end
+ end
end
end