Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #790 from grtjn/622-escaping-pwd
Browse files Browse the repository at this point in the history
Fixed #622: applied escaping of props only for xquery use
  • Loading branch information
RobertSzkutak authored Aug 1, 2017
2 parents 6250dc0 + 273577c commit b6ec20c
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 118 deletions.
2 changes: 1 addition & 1 deletion deploy/lib/MLClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def MLClient.no_prompt=(no_prompt)

def initialize(options)
@ml_username = options[:user_name]
@ml_password = options[:password].xquery_unsafe
@ml_password = options[:password]
@logger = options[:logger] || logger
@request = {}

Expand Down
237 changes: 120 additions & 117 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1812,10 +1812,10 @@ def deploy_triggers
raise ExitException.new("Deploy triggers requires a triggers database")
end

target_config = ServerConfig.expand_path(ServerConfig.properties["ml.triggers.file"])
target_config = ServerConfig.expand_path(@properties["ml.triggers.file"])

if !File.exist?(target_config)
logger.error "ml.triggers.file=#{ServerConfig.properties['ml.triggers.file']}"
logger.error "ml.triggers.file=#{@properties['ml.triggers.file']}"
logger.error <<-ERR.strip_heredoc
Before you can deploy triggers, you must define a configuration. Steps:
1. Copy deploy/sample/triggers-config.sample.xml to #{target_config}
Expand Down Expand Up @@ -2731,10 +2731,6 @@ def ServerConfig.substitute_properties(sub_me, with_me, prefix = "")
end
end while (needs_rescan == true)

sub_me.each do |k,v|
sub_me[k] = v.xquery_safe
end

raise DanglingVarsException.new(dangling_vars) if dangling_vars.length > 0

sub_me
Expand Down Expand Up @@ -2975,159 +2971,159 @@ def build_config(config_files)
config_files.split(",").each do |config_file|
config = File.read(config_file)

# Build the triggers db if it is provided
if @properties['ml.triggers-db'].present?
# Build the triggers db if it is provided
if @properties['ml.triggers-db'].present?

if @properties['ml.triggers-db'] != @properties['ml.modules-db']
config.gsub!("@ml.triggers-db-xml", triggers_db_xml)
config.gsub!("@ml.triggers-assignment", triggers_assignment)
else
config.gsub!("@ml.triggers-db-xml", "")
config.gsub!("@ml.triggers-assignment", "")
end

config.gsub!("@ml.triggers-mapping",
%Q{
<triggers-database name="@ml.triggers-db"/>
})

if @properties['ml.triggers-db'] != @properties['ml.modules-db']
config.gsub!("@ml.triggers-db-xml", triggers_db_xml)
config.gsub!("@ml.triggers-assignment", triggers_assignment)
else
config.gsub!("@ml.triggers-db-xml", "")
config.gsub!("@ml.triggers-assignment", "")
config.gsub!("@ml.triggers-mapping", "")
end

config.gsub!("@ml.triggers-mapping",
%Q{
<triggers-database name="@ml.triggers-db"/>
})
if @properties['ml.xcc-port'].present? and @properties['ml.install-xcc'] != 'false'
config.gsub!("@ml.xdbc-server", xdbc_server)
else
config.gsub!("@ml.xdbc-server", "")
end

else
config.gsub!("@ml.triggers-db-xml", "")
config.gsub!("@ml.triggers-assignment", "")
config.gsub!("@ml.triggers-mapping", "")
end
if @properties['ml.odbc-port'].present?
config.gsub!("@ml.odbc-server", odbc_server)
else
config.gsub!("@ml.odbc-server", "")
end

if @properties['ml.xcc-port'].present? and @properties['ml.install-xcc'] != 'false'
config.gsub!("@ml.xdbc-server", xdbc_server)
else
config.gsub!("@ml.xdbc-server", "")
end
# Build the schemas db if it is provided
if @properties['ml.schemas-db'].present?

if @properties['ml.odbc-port'].present?
config.gsub!("@ml.odbc-server", odbc_server)
else
config.gsub!("@ml.odbc-server", "")
end
if @properties['ml.schemas-db'] != @properties['ml.modules-db']
config.gsub!("@ml.schemas-db-xml", schemas_db_xml)
config.gsub!("@ml.schemas-assignment", schemas_assignment)
else
config.gsub!("@ml.schemas-db-xml", "")
config.gsub!("@ml.schemas-assignment", "")
end

# Build the schemas db if it is provided
if @properties['ml.schemas-db'].present?
config.gsub!("@ml.schemas-mapping",
%Q{
<schema-database name="@ml.schemas-db"/>
})

if @properties['ml.schemas-db'] != @properties['ml.modules-db']
config.gsub!("@ml.schemas-db-xml", schemas_db_xml)
config.gsub!("@ml.schemas-assignment", schemas_assignment)
else
config.gsub!("@ml.schemas-db-xml", "")
config.gsub!("@ml.schemas-assignment", "")
config.gsub!("@ml.schemas-mapping", "")
end

config.gsub!("@ml.schemas-mapping",
%Q{
<schema-database name="@ml.schemas-db"/>
})
# Build the test appserver and db if it is provided
if @properties['ml.test-content-db'].present? &&
@properties['ml.test-port'].present? &&
@environment != "prod"

else
config.gsub!("@ml.schemas-db-xml", "")
config.gsub!("@ml.schemas-assignment", "")
config.gsub!("@ml.schemas-mapping", "")
end
config.gsub!("@ml.test-content-db-xml", test_content_db_xml)
config.gsub!("@ml.test-content-db-assignment", test_content_db_assignment)
config.gsub!("@ml.test-appserver", test_appserver)

# Build the test appserver and db if it is provided
if @properties['ml.test-content-db'].present? &&
@properties['ml.test-port'].present? &&
@environment != "prod"
else
config.gsub!("@ml.test-content-db-xml", "")
config.gsub!("@ml.test-content-db-assignment", "")
config.gsub!("@ml.test-appserver", "")
end

config.gsub!("@ml.test-content-db-xml", test_content_db_xml)
config.gsub!("@ml.test-content-db-assignment", test_content_db_assignment)
config.gsub!("@ml.test-appserver", test_appserver)
# Build the test modules db if it is different from the app modules db
if @properties['ml.test-modules-db'].present? &&
@properties['ml.test-modules-db'] != @properties['ml.modules-db']

else
config.gsub!("@ml.test-content-db-xml", "")
config.gsub!("@ml.test-content-db-assignment", "")
config.gsub!("@ml.test-appserver", "")
end
config.gsub!("@ml.test-modules-db-xml", test_modules_db_xml)
config.gsub!("@ml.test-modules-db-assignment", test_modules_db_assignment)

# Build the test modules db if it is different from the app modules db
if @properties['ml.test-modules-db'].present? &&
@properties['ml.test-modules-db'] != @properties['ml.modules-db']
else
config.gsub!("@ml.test-modules-db-xml", "")
config.gsub!("@ml.test-modules-db-assignment", "")
end

config.gsub!("@ml.test-modules-db-xml", test_modules_db_xml)
config.gsub!("@ml.test-modules-db-assignment", test_modules_db_assignment)
if @properties['ml.test-user'].present?

else
config.gsub!("@ml.test-modules-db-xml", "")
config.gsub!("@ml.test-modules-db-assignment", "")
end

if @properties['ml.test-user'].present?
config.gsub!("@ml.test-user-xml", test_user_xml)

config.gsub!("@ml.test-user-xml", test_user_xml)
else
config.gsub!("@ml.test-user-xml", "")
end

else
config.gsub!("@ml.test-user-xml", "")
end
if @properties['ml.rest-port'].present?

if @properties['ml.rest-port'].present?
# Set up a REST API app server, distinct from the main application.
config.gsub!("@ml.rest-appserver", rest_appserver)

# Set up a REST API app server, distinct from the main application.
config.gsub!("@ml.rest-appserver", rest_appserver)
if @properties['ml.rest-modules-db'].present? &&
@properties['ml.rest-modules-db'] != @properties['ml.modules-db']
config.gsub!("@ml.rest-modules-db-xml", rest_modules_db_xml)
config.gsub!("@ml.rest-modules-db-assignment", rest_modules_db_assignment)
else
config.gsub!("@ml.rest-modules-db-xml", "")
config.gsub!("@ml.rest-modules-db-assignment", "")
end

if @properties['ml.rest-modules-db'].present? &&
@properties['ml.rest-modules-db'] != @properties['ml.modules-db']
config.gsub!("@ml.rest-modules-db-xml", rest_modules_db_xml)
config.gsub!("@ml.rest-modules-db-assignment", rest_modules_db_assignment)
else
config.gsub!("@ml.rest-appserver", "")
config.gsub!("@ml.rest-modules-db-xml", "")
config.gsub!("@ml.rest-modules-db-assignment", "")
end

else
config.gsub!("@ml.rest-appserver", "")
config.gsub!("@ml.rest-modules-db-xml", "")
config.gsub!("@ml.rest-modules-db-assignment", "")
end

if @properties['ml.forest-data-dir'].present?
config.gsub!("@ml.forest-data-dir-xml",
%Q{
<data-directory>@ml.forest-data-dir</data-directory>
})
else
config.gsub!("@ml.forest-data-dir-xml", "")
end

if !@properties['ml.rewrite-resolves-globally'].nil?
config.gsub!("@ml.rewrite-resolves-globally",
%Q{
<rewrite-resolves-globally>#{@properties['ml.rewrite-resolves-globally']}</rewrite-resolves-globally>
})
elsif ['rest', 'hybrid'].include?(@properties["ml.app-type"])
config.gsub!("@ml.rewrite-resolves-globally",
%Q{
<rewrite-resolves-globally>true</rewrite-resolves-globally>
})
else
config.gsub!("@ml.rewrite-resolves-globally", "")
end
if @properties['ml.forest-data-dir'].present?
config.gsub!("@ml.forest-data-dir-xml",
%Q{
<data-directory>@ml.forest-data-dir</data-directory>
})
else
config.gsub!("@ml.forest-data-dir-xml", "")
end

if !@properties['ml.rewrite-resolves-globally'].nil?
config.gsub!("@ml.rewrite-resolves-globally",
%Q{
<rewrite-resolves-globally>#{@properties['ml.rewrite-resolves-globally']}</rewrite-resolves-globally>
})
elsif ['rest', 'hybrid'].include?(@properties["ml.app-type"])
config.gsub!("@ml.rewrite-resolves-globally",
%Q{
<rewrite-resolves-globally>true</rewrite-resolves-globally>
})
else
config.gsub!("@ml.rewrite-resolves-globally", "")
end

if @properties['ml.ssl-certificate-template'].present?
config.gsub!("@ml.ssl-certificate-xml", ssl_certificate_xml)
else
config.gsub!("@ml.ssl-certificate-xml", "")
end
if @properties['ml.ssl-certificate-template'].present?
config.gsub!("@ml.ssl-certificate-xml", ssl_certificate_xml)
else
config.gsub!("@ml.ssl-certificate-xml", "")
end

replace_properties(config, File.basename(config_file))
replace_properties(config, File.basename(config_file), true)

# escape unresolved braces, they have special meaning in XQuery
config.gsub!("{", "{{")
config.gsub!("}", "}}")
# escape unresolved braces, they have special meaning in XQuery
config.gsub!("{", "{{")
config.gsub!("}", "}}")

configs << config
end

%Q{(#{configs.join(", ")})}
end

def replace_properties(contents, name)
def replace_properties(contents, name, xquery = false)
# warn for deprecated properties
deprecated={
"app-modules-db" => "modules-db"
Expand All @@ -3139,6 +3135,11 @@ def replace_properties(contents, name)

# make sure to apply descending order to replace @ml.foo-bar before @ml.foo
@properties.sort {|x,y| y <=> x}.each do |k, v|
if xquery
# escape XML specials, they have special meaning in XQuery
v = v.xquery_safe
end

# new property syntax: @{app-name} or ${app-name}
n = k.sub("ml.", "")
contents.gsub!("@{#{n}}", v)
Expand Down Expand Up @@ -3172,7 +3173,9 @@ def ServerConfig.properties(prop_file_location = @@path)
environments = properties['ml.environments'].split(",") if properties['ml.environments']
environments = ["local", "dev", "prod"] unless environments

environment = find_arg(environments)
if environments.index(ARGV[0])
environment = ARGV.shift
end

properties["environment"] = environment if environment
properties["ml.environment"] = environment if environment
Expand Down

0 comments on commit b6ec20c

Please sign in to comment.