Add ability to set user and group owners of file and permissions for it

Change-Id: I313a169fd79e6e5cb415f4a329c82a956ecc83b0
This commit is contained in:
Vladimir 2013-10-08 10:28:27 +04:00
parent 29d4229408
commit 30559e7072
4 changed files with 61 additions and 3 deletions

View File

@ -114,7 +114,15 @@ module Astute
source_path = File.join(KEY_DIR, deployment_id.to_s, key_name, ssh_key)
destination_path = File.join(KEY_DIR, key_name, ssh_key)
content = File.read(source_path)
upload_mclient.upload(:path => destination_path, :content => content, :overwrite => true, :parents => true)
upload_mclient.upload(:path => destination_path,
:content => content,
:user_owner => 'root',
:group_owner => 'root',
:permissions => '0600',
:dir_permissions => '0700',
:overwrite => true,
:parents => true
)
end
end

View File

@ -24,6 +24,42 @@ action "upload", :description => "upload file" do
:validation => '^.+$',
:optional => false,
:maxlength => 0
input :user_owner,
:prompt => "User owner of file",
:description => "Who should be owner of the file?",
:type => :string,
:validation => :shellsafe,
:optional => false,
:default => 'root',
:maxlength => 0
input :group_owner,
:prompt => "Group owner of file",
:description => "What group should be owner of the file?",
:type => :string,
:validation => :shellsafe,
:optional => false,
:default => 'root',
:maxlength => 0
input :permissions,
:prompt => "File permissions",
:description => "What permissions should be set to the file?",
:type => :string,
:validation => '^[0-7]{3,4}$',
:default => '0644',
:optional => false,
:maxlength => 4
input :dir_permissions,
:prompt => "Directory permissions",
:description => "What permissions should be set for folder where file will be place?",
:type => :string,
:validation => '^[0-7]{3,4}$',
:optional => true,
:default => '0755',
:maxlength => 4
input :overwrite,
:prompt => "Force overwrite",
@ -31,13 +67,13 @@ action "upload", :description => "upload file" do
:type => :boolean,
:optional => false,
:default => false
input :parents,
:prompt => "Create intermediate directories as required",
:description => "no error if destination directory existing, make parent directories as needed",
:type => :boolean,
:optional => false,
:default => true
:default => true
output :msg,
:description => "Report message",

View File

@ -34,9 +34,15 @@ module MCollective
# first create target directory on managed server
FileUtils.mkdir_p(dir) unless File.directory?(dir)
FileUtils.chmod(request.data[:dir_permissions].to_i(8), dir) if request.data[:dir_permissions]
# then create file and save their content
File.open(path, 'w') { |file| file.write(request.data[:content]) }
# Set user owner, group owner and permissions
FileUtils.chown request.data[:user_owner], request.data[:group_owner], path
FileUtils.chmod request.data[:permissions].to_i(8), path
reply[:msg] = "File was uploaded!"
end

View File

@ -193,11 +193,19 @@ describe Astute::DeploymentEngine do
File.stubs(:read).returns("private key").then.returns("public key")
mclient.expects(:upload).with(:path => File.join(Engine::KEY_DIR, 'nova', 'nova'),
:content => "private key",
:user_owner => 'root',
:group_owner => 'root',
:permissions => '0600',
:dir_permissions => '0700',
:overwrite => true,
:parents => true
)
mclient.expects(:upload).with(:path => File.join(Engine::KEY_DIR, 'nova', 'nova.pub'),
:content => "public key",
:user_owner => 'root',
:group_owner => 'root',
:permissions => '0600',
:dir_permissions => '0700',
:overwrite => true,
:parents => true
)