Class: Backup2qiniu::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/backup2qiniu/cli.rb

Instance Method Summary collapse

Instance Method Details

#gen_tokenObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/backup2qiniu/cli.rb', line 7

def gen_token
  puts 'input your keys (you can find them on https://dev.qiniutek.com/account/keys)'
  token = get_param("Access Key")
  secret = get_param("Secret Key")
  Qiniu::RS.establish_connection! :access_key => token, :secret_key => secret
  buckets = Qiniu::RS.buckets
  unless buckets
    puts 'Can not verify your key, wrong key?'
    exit 1
  end
  bucket = get_bucket_name(buckets)
  days = get_param("Token Valid Days (365)")
  if days == ''
    days = 365
  else
    days = days.to_i
  end

  print_params access_key: token, secret_key: secret, bucket: bucket, valid_days: days

  print_token Qiniu::RS.generate_upload_token(:expires_in => 3600*24*days, :scope => bucket), bucket
end