Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1061098
  • Loading branch information
Dan McPherson committed Feb 6, 2014
1 parent 0993b14 commit c0fa2da
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion controller/app/controllers/authorizations_controller.rb
Expand Up @@ -15,7 +15,7 @@ def create
scopes = if s = params[:scope] || params[:scopes]
Scope.list!(s) rescue (
return render_error(:unprocessable_entity, "One or more of the scopes you provided are not allowed. Valid scopes are #{Scope.describe_all.map(&:first).to_sentence}.",
194, "scopes"))
1, "scopes"))
end
scopes = Scope.default if scopes.blank?

Expand Down
12 changes: 7 additions & 5 deletions controller/app/controllers/environment_variables_controller.rb
Expand Up @@ -19,7 +19,7 @@ def show
name = params[:id].presence

env_hash = @application.list_user_env_variables([name])
return render_error(:not_found, "User environment variable named '#{name}' not found in application", 189) unless env_hash[name]
return render_error(:not_found, "User environment variable named '#{name}' not found in application", 188) unless env_hash[name]
env_var = {'name' => name, 'value' => env_hash[name]}
render_success(:ok, "environment-variable", get_rest_environment_variable(env_var),
"Showing environment variable '#{name}' for application #{@application.name}")
Expand All @@ -32,15 +32,17 @@ def create
user_env_vars = params[:environment_variables].presence

if (user_env_vars.present? && name) or (!user_env_vars.present? && !name)
return render_error(:unprocessable_entity, "Specify parameters 'name'/'value' or 'environment_variables'", 191)
return render_error(:unprocessable_entity, "Specify parameters 'name'/'value' or 'environment_variables'", 186)
end
if name
match = /\A([a-zA-Z_][\w]*)\z/.match(name)
return render_error(:unprocessable_entity, "Name can only contain letters, digits and underscore and can't begin with a digit.", 194, "name") if match.nil?
return render_error(:unprocessable_entity, "Name can only contain letters, digits and underscore and can't begin with a digit.", 188, "name") if match.nil?
return render_error(:unprocessable_entity, "Name must be 128 characters or less.", 188, "name") if name.length > 128
return render_error(:unprocessable_entity, "Value not specified for environment variable '#{name}'", 190, "value") unless params.has_key?(:value)
value = params[:value]
return render_error(:unprocessable_entity, "Value must be 512 characters or less.", 190, "value") if value.length > 512
env_hash = @application.list_user_env_variables([name])
return render_error(:unprocessable_entity, "Environment variable named '#{name}' already exists in application", 192) if env_hash[name]
return render_error(:unprocessable_entity, "Environment variable named '#{name}' already exists in application", 188) if env_hash[name]

env_var = {'name' => name, 'value' => value}
result = @application.patch_user_env_variables([env_var])
Expand All @@ -63,7 +65,7 @@ def update
return render_error(:unprocessable_entity, "Value not specified for environment variable '#{name}'", 190, "value") unless params.has_key?(:value)
value = params[:value]
env_hash = @application.list_user_env_variables([name])
return render_error(:not_found, "User environment variable named '#{name}' not found in application", 189) unless env_hash[name]
return render_error(:not_found, "User environment variable named '#{name}' not found in application", 188) unless env_hash[name]

env_var = {'name' => name, 'value' => value}
result = @application.patch_user_env_variables([env_var])
Expand Down
9 changes: 6 additions & 3 deletions controller/app/models/application.rb
Expand Up @@ -2684,17 +2684,20 @@ def self.validate_user_env_variables(user_env_vars, no_delete=false)
keys = {}
user_env_vars.each do |ev|
name = ev['name']
value = ev['value']
unless name and (ev.keys - ['name', 'value']).empty?
raise OpenShift::UserException.new("Invalid environment variable #{ev}. Valid keys 'name'(required), 'value'", 187, "environment_variables")
raise OpenShift::UserException.new("Invalid environment variable #{ev}. Valid keys 'name'(required), 'value'", 186, "environment_variables")
end
raise OpenShift::UserException.new("Invalid environment variable name #{name}: specified multiple times", 188, "environment_variables") if keys[name]
keys[name] = true
raise OpenShift::UserException.new("Name must be 128 characters or less.", 188, "environment_variables") if name.length > 128
match = /\A([a-zA-Z_][\w]*)\z/.match(name)
raise OpenShift::UserException.new("Name can only contain letters, digits and underscore and can't begin with a digit.", 194, "name") if match.nil?
raise OpenShift::UserException.new("Name can only contain letters, digits and underscore and can't begin with a digit.", 188, "environment_variables") if match.nil?
raise OpenShift::UserException.new("Value must be 512 characters or less.", 190, "environment_variables") if value.length > 512
end
if no_delete
set_vars, unset_vars = sanitize_user_env_variables(user_env_vars)
raise OpenShift::UserException.new("Environment variable deletion not allowed for this operation", 193, "environment_variables") unless unset_vars.empty?
raise OpenShift::UserException.new("Environment variable deletion not allowed for this operation", 186, "environment_variables") unless unset_vars.empty?
end
end
end
Expand Down
Expand Up @@ -294,7 +294,7 @@ def user_var_add(variables, gears = [])
end

if name.to_s.length > USER_VARIABLE_NAME_MAX_SIZE
return 127, "CLIENT_ERROR: name '#{name}' exceeds maximum size of #{USER_VARIABLE_NAME_MAX_SIZE}b"
return 127, "CLIENT_ERROR: Name '#{name}' exceeds maximum size of #{USER_VARIABLE_NAME_MAX_SIZE}b"
end
if value.to_s.length > USER_VARIABLE_VALUE_MAX_SIZE
return 127, "CLIENT_ERROR: '#{name}' value exceeds maximum size of #{USER_VARIABLE_VALUE_MAX_SIZE}b"
Expand Down

0 comments on commit c0fa2da

Please sign in to comment.