Revision 912:5e80956cc792 extra/soundsoftware

View differences:

extra/soundsoftware/reposman-soundsoftware.rb
19 19
#                             -r redmine.example.net
20 20
#                             -r http://redmine.example.net
21 21
#                             -r https://example.net/redmine
22
#   -k, --key=KEY             use KEY as the Redmine API key
22
#   -k, --key=KEY             use KEY as the Redmine API key (you can use the
23
#                             --key-file option as an alternative)
23 24
#
24 25
# == Options
25 26
#
......
50 51
#                             and subversion.
51 52
#   --http-user=USER          User for HTTP Basic authentication with Redmine WS
52 53
#   --http-pass=PASSWORD      Password for Basic authentication with Redmine WS
54
#       --key-file=PATH       path to a file that contains the Redmine API key
55
#                             (use this option instead of --key if you don't 
56
#                             the key to appear in the command line)
53 57
#   -t, --test                only show what should be done
54 58
#   -h, --help                show help and exit
55 59
#   -v, --verbose             verbose
......
73 77
                      ['--scm-dir',      '-s', GetoptLong::REQUIRED_ARGUMENT],
74 78
                      ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
75 79
                      ['--key',          '-k', GetoptLong::REQUIRED_ARGUMENT],
80
                      ['--key-file',           GetoptLong::REQUIRED_ARGUMENT],
76 81
                      ['--owner',        '-o', GetoptLong::REQUIRED_ARGUMENT],
77 82
                      ['--group',        '-g', GetoptLong::REQUIRED_ARGUMENT],
78 83
                      ['--url',          '-u', GetoptLong::REQUIRED_ARGUMENT],
......
136 141
    when '--scm-dir';        $repos_base   = arg.dup
137 142
    when '--redmine-host';   $redmine_host = arg.dup
138 143
    when '--key';            $api_key      = arg.dup
144
    when '--key-file'
145
      begin
146
        $api_key = File.read(arg).strip
147
      rescue Exception => e
148
        $stderr.puts "Unable to read the key from #{arg}: #{e.message}"
149
        exit 1
150
      end
139 151
    when '--owner';          $svn_owner    = arg.dup; $use_groupid = false;
140 152
    when '--group';          $svn_group    = arg.dup; $use_groupid = false;
141 153
    when '--url';            $svn_url      = arg.dup
......
185 197

  
186 198
class Project < ActiveResource::Base
187 199
  self.headers["User-agent"] = "SoundSoftware repository manager/#{Version}"
200
  self.format = :xml
188 201
end
189 202

  
190 203
log("querying Redmine for projects...", :level => 1);
......
199 212
begin
200 213
  # Get all active projects that have the Repository module enabled
201 214
  projects = Project.find(:all, :params => {:key => $api_key})
215
rescue ActiveResource::ForbiddenAccess
216
  log("Request was denied by your Redmine server. Make sure that 'WS for repository management' is enabled in application settings and that you provided the correct API key.")
202 217
rescue => e
203 218
  log("Unable to connect to #{Project.site}: #{e}", :exit => true)
204 219
end
205 220

  
206 221
if projects.nil?
207
  log('no project found, perhaps you forgot to "Enable WS for repository management"', :exit => true)
222
  log('No project found, perhaps you forgot to "Enable WS for repository management"', :exit => true)
208 223
end
209 224

  
210 225
log("retrieved #{projects.size} projects", :level => 1)

Also available in: Unified diff