Skip to content

Commit

Permalink
let users comment on why usage limits were added
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Dec 15, 2017
1 parent e910918 commit d9b5ad7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/views/secrets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<%= form.input :key, input_html: {disabled: !!id}, required: true %>

<%= form.input :comment, as: :text_area, input_html: {rows: secret[:comment].to_s.count("\n") + 1} %>
<%= form.input :comment, as: :text_area %>

<%= form.input :visible, as: :check_box, help: 'Visible to other users in samsons UI' %>

Expand Down
16 changes: 8 additions & 8 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"check_name": "PermitAttributes",
"message": "Potentially dangerous key allowed for mass assignment",
"file": "plugins/kubernetes/app/controllers/kubernetes/deploy_group_roles_controller.rb",
"line": 137,
"line": 142,
"link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/",
"code": "params.require(:kubernetes_deploy_group_role).permit(:kubernetes_role_id, :requests_memory, :requests_cpu, :limits_memory, :limits_cpu, :replicas, :project_id, :deploy_group_id)",
"render_path": null,
Expand All @@ -27,7 +27,7 @@
"check_name": "PermitAttributes",
"message": "Potentially dangerous key allowed for mass assignment",
"file": "plugins/kubernetes/app/controllers/kubernetes/deploy_group_roles_controller.rb",
"line": 136,
"line": 141,
"link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/",
"code": "params.require(:kubernetes_deploy_group_role).permit(:kubernetes_role_id, :requests_memory, :requests_cpu, :limits_memory, :limits_cpu, :replicas, :project_id, :deploy_group_id)",
"render_path": null,
Expand All @@ -47,7 +47,7 @@
"check_name": "PermitAttributes",
"message": "Potentially dangerous key allowed for mass assignment",
"file": "plugins/kubernetes/app/controllers/kubernetes/deploy_group_roles_controller.rb",
"line": 138,
"line": 143,
"link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/",
"code": "params.require(:kubernetes_deploy_group_role).permit(:kubernetes_role_id, :requests_memory, :requests_cpu, :limits_memory, :limits_cpu, :replicas, :project_id, :deploy_group_id)",
"render_path": null,
Expand Down Expand Up @@ -219,13 +219,13 @@
{
"warning_type": "Mass Assignment",
"warning_code": 105,
"fingerprint": "a854b562bbd3eeede5a798c682df9e8e306ea38db0324dcda8663e64b1e1fe10",
"fingerprint": "c580d6ead04ca4dd19b71eea8c7d3832197a8b161da950b711064ced1b395ddb",
"check_name": "PermitAttributes",
"message": "Potentially dangerous key allowed for mass assignment",
"file": "plugins/kubernetes/app/controllers/kubernetes/usage_limits_controller.rb",
"line": 67,
"link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/",
"code": "params.require(:kubernetes_usage_limit).permit(:project_id, :scope_type_and_id, :cpu, :memory)",
"code": "params.require(:kubernetes_usage_limit).permit(:project_id, :scope_type_and_id, :cpu, :memory, :comment)",
"render_path": null,
"location": {
"type": "method",
Expand All @@ -239,13 +239,13 @@
{
"warning_type": "Mass Assignment",
"warning_code": 105,
"fingerprint": "a854b562bbd3eeede5a798c682df9e8e306ea38db0324dcda8663e64b1e1fe10",
"fingerprint": "c580d6ead04ca4dd19b71eea8c7d3832197a8b161da950b711064ced1b395ddb",
"check_name": "PermitAttributes",
"message": "Potentially dangerous key allowed for mass assignment",
"file": "plugins/kubernetes/app/controllers/kubernetes/usage_limits_controller.rb",
"line": 67,
"link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/",
"code": "params.require(:kubernetes_usage_limit).permit(:project_id, :scope_type_and_id, :cpu, :memory)",
"code": "params.require(:kubernetes_usage_limit).permit(:project_id, :scope_type_and_id, :cpu, :memory, :comment)",
"render_path": null,
"location": {
"type": "method",
Expand Down Expand Up @@ -377,6 +377,6 @@
"note": ""
}
],
"updated": "2017-12-14 10:59:13 -0800",
"updated": "2017-12-15 15:02:56 -0800",
"brakeman_version": "4.1.0"
}
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171110221726) do
ActiveRecord::Schema.define(version: 20171215200538) do

create_table "audits", force: :cascade do |t|
t.integer "auditable_id", null: false
Expand Down Expand Up @@ -271,6 +271,7 @@
t.decimal "cpu", precision: 4, scale: 2, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "comment", limit: 512
t.index ["project_id"], name: "index_kubernetes_usage_limits_on_project_id"
t.index ["scope_type", "scope_id", "project_id"], name: "index_kubernetes_usage_limits_on_scope", unique: true, length: { scope_type: 20 }
end
Expand Down
1 change: 1 addition & 0 deletions lib/samson/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def input(
input_html ||= {}
input_html[:pattern] ||= translate_regex_to_js(pattern) if pattern
input_html[:required] ||= required
input_html[:rows] ||= object.send(attribute).to_s.count("\n") + 2 if as == :text_area

label ||= attribute.to_s.humanize
label = "* " + label if required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def find_usage_limit

def usage_limit_params
params.require(:kubernetes_usage_limit).permit(
:project_id, :scope_type_and_id, :cpu, :memory
:project_id, :scope_type_and_id, :cpu, :memory, :comment
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
<% projects = Project.with_kubernetes_roles.pluck(:name, :id).unshift ["All", nil] %>
<%= form.select :project_id, projects, {}, Samson::FormBuilder::LIVE_SELECT_OPTIONS %>
<% end %>

<%= form.input :cpu, required: true %>
<%= form.input :memory, required: true %>

<%= form.input :comment, as: :text_area %>
</fieldset>

<%= form.actions delete: @usage_limit do %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
class AddCommentsToLimits < ActiveRecord::Migration[5.1]
def change
add_column :kubernetes_usage_limits, :comment, :string, limit: 512
end
end
9 changes: 8 additions & 1 deletion test/lib/samson/form_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ def fake_erb_rendering
end

it "can change field type" do
builder.input(:name, as: :text_area).must_include '<textarea class='
builder.input(:name, as: :text_area).must_include '<textarea '
end

it "auto-expands text areas to show full content" do
builder.input(:name).wont_include 'rows="'
builder.input(:name, as: :text_area).must_include 'rows="2"'
builder.object.name = "a\nb\nc\nd\n"
builder.input(:name, as: :text_area).must_include 'rows="6"'
end

it "can show help" do
Expand Down

0 comments on commit d9b5ad7

Please sign in to comment.