Skip to content

Commit

Permalink
mergeing into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sepulworld committed Jul 19, 2016
2 parents 3a9b508 + c16d90e commit c7ffca2
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 158 deletions.
130 changes: 107 additions & 23 deletions bin/aptly-cli
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,54 @@ require 'aptly_cli'
program :version, AptlyCli::VERSION
program :description, 'Aptly repository API client'

$config_file = '/etc/aptly-cli.conf'
$server = nil
$username = nil
$password = nil
$debug = false

global_option('-c', '--config FILE', 'Path to YAML config file') do |config_file|
$config_file = config_file
end

global_option('-s', '--server SERVER', 'Host name or IP address') do |server|
$server = server
end
global_option('--username USERNAME', 'User name') do |username|
$username = username
end
global_option('--password PASSWORD', 'Password') do |password|
$password = password
end
global_option('--debug', 'Enable debug output') do
$debug = true
end

def handle_global_options(options)
if $server
options.server = $server
end
if $username
options.username = $username
end
if $password
options.password = $password
end
if $debug
options.debug = $debug
end
end

command :file_list do |c|
c.syntax = 'aptly-cli file_list [options]'
c.summary = 'List all directories'
c.description = 'List all directories that contain uploaded files'
c.example 'List all directories for file uploads', 'aptly-cli file_list'
c.option '--directory DIRECTORY', String, 'Directory to list packages on server'
c.action do |args, options|
aptly_command = AptlyCli::AptlyFile.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyFile.new(config, options)
if options.directory
puts aptly_command.file_get(options.directory)
else
Expand All @@ -32,7 +72,9 @@ command :file_upload do |c|
c.option '--directory DIRECTORY', String, 'Directory to load packages into'
c.option '--upload UPLOAD', String, 'Package(s) to upload'
c.action do |args, options|
aptly_command = AptlyCli::AptlyFile.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyFile.new(config, options)
puts aptly_command.file_post(:file_uri => options.directory, :package => options.upload, :local_file => options.upload)
end
end
Expand All @@ -46,7 +88,9 @@ command :file_delete do |c|
'aptly-cli file_delete --target /redis/redis-server_2.8.3_i386-cc1.deb')
c.option '--target TARGET', String, 'Path to directory or specific package to delete'
c.action do |args, options|
aptly_command = AptlyCli::AptlyFile.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyFile.new(config, options)
puts aptly_command.file_delete(options.target)
end
end
Expand All @@ -63,7 +107,9 @@ command :repo_create do |c|
c.option '--default_component COMPONENT', String, 'Default component when publishing from this local repo'
c.action do |args, options|
puts options.name
aptly_command = AptlyCli::AptlyRepo.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyRepo.new(config, options)
repo_options = { :name => options.name.to_s,
:comment => options.comment.to_s,
:DefaultDistribution => options.default_distribution.to_s,
Expand All @@ -80,7 +126,9 @@ command :repo_delete do |c|
c.option '--name NAME', String, 'Local repository name, required'
c.option '--force'
c.action do |args, options|
aptly_command = AptlyCli::AptlyRepo.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyRepo.new(config, options)
repo_options = { :name => options.name.to_s,
:force => options.force.to_s }
puts aptly_command.repo_delete(repo_options)
Expand All @@ -97,7 +145,9 @@ command :repo_edit do |c|
c.option '--default_distribution DISTRIBUTION', String, 'Edit DefaultDistribution for repo'
c.option '--default_component COMPONENT', String, 'Edit DefaultComponent for repo'
c.action do |args, options|
aptly_command = AptlyCli::AptlyRepo.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyRepo.new(config, options)
if options.default_distribution
repo_options = { :DefaultDistribution => options.default_distribution.to_s }
end
Expand All @@ -117,7 +167,9 @@ command :repo_list do |c|
c.description = 'Show list of currently available local repositories'
c.example 'description', 'aptly-cli repo_list'
c.action do |args, options|
aptly_command = AptlyCli::AptlyRepo.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyRepo.new(config, options)
puts aptly_command.repo_list()
end
end
Expand All @@ -132,7 +184,9 @@ command :repo_package_query do |c|
c.option '--with_deps', 'Return results with dependencies'
c.option '--format FORMAT', String, 'Format type to return, compact by default. "details" is an option'
c.action do |args, options|
aptly_command = AptlyCli::AptlyRepo.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyRepo.new(config, options)
if options.query
repo_options = { :name => options.name.to_s, :query => options.query.to_s }
elsif options.with_deps and options.query.nil?
Expand Down Expand Up @@ -163,7 +217,9 @@ command :repo_upload do |c|
c.option '--noremove', 'Flag to not remove any files that were uploaded via File API after repo upload'
c.option '--forcereplace', 'flag to replace file(s) already in the repo'
c.action do |args, options|
aptly_command = AptlyCli::AptlyRepo.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyRepo.new(config, options)
puts aptly_command.repo_upload({ :name => options.name, :dir => options.dir,
:file => options.file, :noremove => options.noremove,
:forcereplace => options.forcereplace })
Expand All @@ -177,7 +233,9 @@ command :repo_show do |c|
c.example 'description', 'aptly-cli repo_show --name megatronsoftware'
c.option '--name NAME', String, 'Local repository name, required'
c.action do |args, options|
aptly_command = AptlyCli::AptlyRepo.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyRepo.new(config, options)
puts aptly_command.repo_show(options.name)
end
end
Expand All @@ -191,7 +249,9 @@ command :publish_drop do |c|
c.option '--distribution DISTRIBUTION', String, 'distribution'
c.option '--force', 'force published repository removal even if component cleanup fails'
c.action do |args, options|
aptly_command = AptlyCli::AptlyPublish.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyPublish.new(config, options)
puts aptly_command.publish_drop({ :prefix => options.prefix, :distribution => options.distribution, :force => options.force })
end
end
Expand All @@ -202,7 +262,9 @@ command :publish_list do |c|
c.description = 'List published repositories.'
c.example 'List published repositories', 'aptly-cli publish_list'
c.action do |args, options|
aptly_command = AptlyCli::AptlyPublish.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyPublish.new(config, options)
puts aptly_command.publish_list()
end
end
Expand Down Expand Up @@ -232,7 +294,9 @@ command :publish_repo do |c|
c.option '--gpg_passphrase GPGPASS', String, 'gpg key passphrase (if using over http, would be transmitted in clear text!)'
c.option '--gpg_passphrase_file GPGPASSFILE', String, 'gpg passphrase file (local to aptly server/user)'
c.action do |args, options|
aptly_command = AptlyCli::AptlyPublish.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyPublish.new(config, options)
puts aptly_command.publish_repo(options.name, { :sourcekind => options.sourcekind, :prefix => options.prefix,
:label => options.label, :distribution => options.distribution,
:origin => options.origin, :forceoverwrite => options.forceoverwrite,
Expand All @@ -259,7 +323,9 @@ command :publish_update do |c|
c.option '--gpg_passphrase GPGPASS', String, 'gpg key passphrase (if using over http, would be transmitted in clear text!)'
c.option '--gpg_passphrase_file GPGPASSFILE', String, 'gpg passphrase file (local to aptly server/user)'
c.action do |args, options|
aptly_command = AptlyCli::AptlyPublish.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyPublish.new(config, options)
puts aptly_command.publish_update({ :prefix => options.prefix, :distribution => options.distribution, :forceoverwrite => options.forceoverwrite,
:skip => options.gpg_skip, :batch => options.gpg_batch, :gpgKey => options.gpg_key,
:keyring => options.gpg_keyring, :secretKeyring => options.gpg_secret_keyring,
Expand All @@ -277,7 +343,9 @@ command :snapshot_create do |c|
c.option '--repo REPO', String, 'Name of repo to snapshot'
c.option '--description DESCRIPTION', String, 'Set description for snapshot'
c.action do |args, options|
aptly_command = AptlyCli::AptlySnapshot.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlySnapshot.new(config, options)
puts aptly_command.snapshot_create(options.name, options.repo, options.description)
end
end
Expand All @@ -291,7 +359,9 @@ command :snapshot_delete do |c|
c.option '--name NAME', String, 'Local snapshot name, required'
c.option '--force', 'Force'
c.action do |args, options|
aptly_command = AptlyCli::AptlySnapshot.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlySnapshot.new(config, options)
puts aptly_command.snapshot_delete(options.name, options.force)
end
end
Expand All @@ -304,7 +374,9 @@ command :snapshot_diff do |c|
c.option '--name NAME', String, 'Local snapshot name (left)'
c.option '--withsnapshot WITHSNAPSHOT', String, 'Snapshot to diff against (right)'
c.action do |args, options|
aptly_command = AptlyCli::AptlySnapshot.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlySnapshot.new(config, options)
puts aptly_command.snapshot_diff(options.name, options.withsnapshot)
end
end
Expand All @@ -317,7 +389,9 @@ command :snapshot_list do |c|
c.example 'Return list sorted by time', 'aptly-cli snapshot_list --sort time'
c.option '--sort', String, 'Set sort by'
c.action do |args, options|
aptly_command = AptlyCli::AptlySnapshot.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlySnapshot.new(config, options)
puts aptly_command.snapshot_list(options.sort)
end
end
Expand All @@ -334,7 +408,9 @@ command :snapshot_search do |c|
c.option '--withdeps', 'Include package dependencies'
c.option '--format FORMAT', String, 'Format the respone of the snapshot search results, compact by default.'
c.action do |args, options|
aptly_command = AptlyCli::AptlySnapshot.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlySnapshot.new(config, options)
puts aptly_command.snapshot_search(options.name, { :query => options.query, :format => options.format, :withdeps => options.withdeps })
end
end
Expand All @@ -346,7 +422,9 @@ command :snapshot_show do |c|
c.example 'Show snapshot information for repo named megatronsoftware', 'aptly-cli snapshot_show --name megatronsoftware'
c.option '--name NAME', String, 'Local snapshot name, required'
c.action do |args, options|
aptly_command = AptlyCli::AptlySnapshot.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlySnapshot.new(config, options)
puts aptly_command.snapshot_show(options.name)
end
end
Expand All @@ -360,7 +438,9 @@ command :snapshot_update do |c|
c.option '--new_name NEWNAME', String, 'New name for the snapshot'
c.option '--description DESCRIPTION', String, 'Update description for snapshot'
c.action do |args, options|
aptly_command = AptlyCli::AptlySnapshot.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlySnapshot.new(config, options)
puts aptly_command.snapshot_update(options.name, options.new_name, options.description)
end
end
Expand All @@ -372,7 +452,9 @@ command :graph do |c|
c.example 'description', 'aptly-cli graph png > ~/repo_graph.png'
c.option '--type GRAPH_TYPE', String, 'Type of graph to download, present options are png or svg'
c.action do |args, options|
aptly_command = AptlyCli::AptlyMisc.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyMisc.new(config, options)
puts aptly_command.get_graph(options.type)
end
end
Expand All @@ -382,7 +464,9 @@ command :version do |c|
c.description = 'Display aptly server version'
c.example 'description', 'aptly-cli version'
c.action do |args, options|
aptly_command = AptlyCli::AptlyMisc.new
config = AptlyCli::AptlyLoad.new.configure_with($config_file)
handle_global_options options
aptly_command = AptlyCli::AptlyMisc.new(config, options)
puts aptly_command.get_version()
end
end
Expand Down
55 changes: 55 additions & 0 deletions lib/aptly_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class AptlyCommand
def initialize(config, options = nil)
@config = config
options ||= Options.new

if options.server
@config[:server] = options.server
end

if options.username
@config[:username] = options.username
end

if options.password
@config[:password] = options.password
end

if options.debug
@config[:debug] = options.debug
end

@config.each do |k, v|
if v == '${PROMPT}'
@config[k.to_sym] = ask("Enter a value for #{k}:")
elsif v == '${PROMPT_PASSWORD}'
@config[k.to_sym] = password("Enter a value for #{k}:")
elsif v == '${KEYRING}'
require 'keyring'

keyring = Keyring.new
value = keyring.get_password(@config[:server], @config[:username])

unless value
# Prompt for password...
value = password("Enter a value for #{k}:")

# ... and store in keyring
keyring.set_password(@config[:server], @config[:username], value)
end

@config[k.to_sym] = value
end
end

base_uri = "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
self.class.base_uri base_uri

if @config[:username]
if @config[:password]
self.class.basic_auth @config[:username].to_s, @config[:password].to_s
end
end
debug_output $stdout if @config[:debug] == true
end
end
18 changes: 2 additions & 16 deletions lib/aptly_file.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
require 'aptly_cli/version'
require 'aptly_command'
require 'aptly_load'
require 'httmultiparty'

module AptlyCli
# Uploading file into Aptly
class AptlyFile
class AptlyFile < AptlyCommand
include HTTMultiParty
attr_accessor :file_uri, :package, :local_file_path

# Load aptly-cli.conf and establish base_uri
@config = AptlyCli::AptlyLoad.new.configure_with('/etc/aptly-cli.conf')
base_uri "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"

if @config[:username]
if @config[:password]
basic_auth @config[:username].to_s, @config[:password].to_s
end
end

debug_output $stdout if @config[:debug] == true

def initialize(file_uri=nil, package=nil, local_file_path=nil)
end

def file_dir
uri = '/files'
self.class.get uri
Expand Down
Loading

0 comments on commit c7ffca2

Please sign in to comment.