tq 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc0bd8304fbc66b4f921997f047c637f579250b9
4
- data.tar.gz: d694a8a9b632e17715d78d32a7a2311176d4fed8
3
+ metadata.gz: e61541481bfdeea720c65bb55a70a7a7016ee078
4
+ data.tar.gz: e57448c12dad85090950ed38864d9b854bf8bddb
5
5
  SHA512:
6
- metadata.gz: f0062de8772a7555928676469d0fa9191c9d36429f0b451d8cdf28ff0225e07d8eac29d69b826f74636110639936209dda94908e9df2d18ddaf9dafcc68076c7
7
- data.tar.gz: 370c3621670e588217dd84fea9087d94fda54c040bc8776c55ea1f592383835f32c6d0baf366c3ce5052e0f655d729b59e88b0fe3af1069cdb5de706b4ac0983
6
+ metadata.gz: 6a6114945d7ca4e92db2bad2ebfc4f6afb4b5e70cc33a007999ad3572a833e72cca784b3508bf0c6909da7ac08920afd7baf69aab546916f720740fad925969a
7
+ data.tar.gz: 57dad8072196d556eacf93fadc1cb5cf88135f9554a3338c2988feb353b96717cca15567d1260efae2a4f9e58a5226094a17a17595357b568ac16e2e618c3a26
@@ -63,12 +63,17 @@ module TQ
63
63
  options({'stderr' => _})
64
64
  end
65
65
 
66
+ def service_run!(issuer, p12_file)
67
+ setup_logger!
68
+ _run *(_queues( TQ::Queue.new( *(service_auth!(issuer, p12_file)) ).project(@options['project']) ) )
69
+ end
70
+
66
71
  def run!(secrets_file=nil, store_file=nil)
67
72
  setup_logger!
68
73
  _run *(_queues( TQ::Queue.new( *(auth!(secrets_file, store_file)) ).project(@options['project']) ) )
69
74
  end
70
75
 
71
-
76
+ # Note issuer is not a file name but the service account email address
72
77
  def service_auth!(issuer, p12_file)
73
78
  key = Google::APIClient::KeyUtils.load_from_pkcs12(p12_file, 'notasecret')
74
79
  client.authorization = Signet::OAuth2::Client.new(
@@ -8,8 +8,6 @@ module TQ
8
8
 
9
9
  DEFAULT_OPTIONS = {
10
10
  app: {},
11
- auth_secrets_file: './tq-client.json',
12
- auth_store_file: './tq-client-store.json',
13
11
  config_file: './tq-app.json'
14
12
  }
15
13
 
@@ -33,12 +31,24 @@ module TQ
33
31
 
34
32
  @logger.info(progname) { "Configuring #{@app.id}" } if @logger
35
33
  opts = parse_args(argv)
36
- @logger.debug(progname) { "Configuration: #{opts[:app].inspect}" } if @logger
34
+ @logger.debug(progname) { "Configuration: #{opts.inspect}" } if @logger
37
35
 
38
- @app = @app.options( opts[:app] ).logger(@logger)
36
+ @app = @app.options( opts[:app] )
37
+ @app = @app.logger(@logger) if @logger
39
38
 
40
39
  @logger.info(progname) { "Running #{@app.id} using worker #{@app.worker}" } if @logger
41
- @app.run!( opts[:auth_secrets_file], opts[:auth_store_file] )
40
+
41
+ secrets, store = opts[:auth_secrets_file], opts[:auth_store_file]
42
+ issuer, p12 = opts[:service_auth_issuer_file], opts[:service_auth_p12_file]
43
+
44
+ if secrets
45
+ @app.run!(secrets, store)
46
+ elsif issuer && p12
47
+ @app.service_run!(File.read(issuer).chomp, p12)
48
+ else
49
+ raise ArgumentError, "You must provide either OAuth2 secrets and credentials store, " +
50
+ "or service-account issuer and p12 files."
51
+ end
42
52
 
43
53
  end
44
54
 
@@ -58,10 +68,18 @@ module TQ
58
68
  opts[:auth_secrets_file] = given
59
69
  end
60
70
 
61
- shell.on('-s', '--auth-store [FILE]', "Google OAuth2 storage file") do |given|
71
+ shell.on('-s', '--auth-store [FILE]', "Google OAuth2 credentials storage file") do |given|
62
72
  opts[:auth_store_file] = given
63
73
  end
64
74
 
75
+ shell.on('-i', '--service-auth-issuer [FILE]', "Google service account issuer file") do |given|
76
+ opts[:service_auth_issuer_file] = given
77
+ end
78
+
79
+ shell.on('-p', '--service-auth-p12 [FILE]', "Google service account p12 file") do |given|
80
+ opts[:service_auth_p12_file] = given
81
+ end
82
+
65
83
  shell.on('-c', '--config [FILE]', "Application config file (json)") do |given|
66
84
  opts[:config_file] = given
67
85
  opts[:app] = JSON.load( File.open(given, 'r') )
@@ -1,4 +1,4 @@
1
1
 
2
2
  module TQ
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
@@ -14,7 +14,7 @@ end
14
14
  CLIENT_SECRETS_FILE = File.expand_path('../config/secrets/test/client_secrets.json', File.dirname(__FILE__))
15
15
  CREDENTIALS_FILE = File.expand_path("../config/secrets/test/#{File.basename(__FILE__,'.rb')}-oauth2.json", File.dirname(__FILE__))
16
16
 
17
- # for service account auth -- not quite working
17
+ # for service account auth
18
18
  SERVICE_ISSUER_FILE = File.expand_path('../config/secrets/test/issuer', File.dirname(__FILE__))
19
19
  SERVICE_P12_FILE = File.expand_path('../config/secrets/test/client.p12', File.dirname(__FILE__))
20
20
 
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  class ShellTests < Minitest::Spec
10
10
 
11
- include
12
11
  # for installed app auth
13
12
  CLIENT_SECRETS_FILE = File.expand_path(
14
13
  '../config/secrets/test/client_secrets.json', File.dirname(__FILE__)
@@ -18,6 +17,9 @@ class ShellTests < Minitest::Spec
18
17
  File.dirname(__FILE__)
19
18
  )
20
19
 
20
+ SERVICE_ISSUER_FILE = File.expand_path('../config/secrets/test/issuer', File.dirname(__FILE__))
21
+ SERVICE_P12_FILE = File.expand_path('../config/secrets/test/client.p12', File.dirname(__FILE__))
22
+
21
23
  # task queue constants
22
24
  TASKQUEUE_APP_CONFIG =
23
25
  File.expand_path("../config/secrets/test/#{File.basename(__FILE__,'.rb')}" +
@@ -91,6 +93,13 @@ class ShellTests < Minitest::Spec
91
93
  ]
92
94
  end
93
95
 
96
+ def shell_args_service
97
+ [ "--service-auth-issuer", SERVICE_ISSUER_FILE,
98
+ "--service-auth-p12", SERVICE_P12_FILE,
99
+ "--config", TASKQUEUE_APP_CONFIG
100
+ ]
101
+ end
102
+
94
103
  def setup
95
104
  sleep TASKQUEUE_LEASE_SECS+1
96
105
  clear_queue!
@@ -120,6 +129,30 @@ class ShellTests < Minitest::Spec
120
129
  assert_tasks_on_queue(exps.length - app_stdin_num_tasks)
121
130
 
122
131
  end
132
+
133
+ it 'should execute using service auth' do
134
+ exps = [
135
+ { 'What is your name?' => 'Sir Lancelot',
136
+ 'What is your quest?' => 'To seek the holy grail',
137
+ 'What is your favorite color?' => 'blue' },
138
+ { 'What is your name?' => 'Sir Robin',
139
+ 'What is your quest?' => 'To seek the holy grail',
140
+ 'What is the capital of Assyria?' => nil },
141
+ { 'What is your name?' => 'Galahad',
142
+ 'What is your quest?' => 'To seek the grail',
143
+ 'What is your favorite color?' => ['blue','yellow'] },
144
+ { 'What is your name?' => 'Arthur',
145
+ 'What is your quest?' => 'To seek the holy grail',
146
+ 'What is the air-speed velocity of an unladen swallow?' => 'African or European swallow?' }
147
+ ]
148
+
149
+ populate_queue! exps
150
+
151
+ TQ::Shell.new(@app, logger).call( shell_args_service )
152
+
153
+ assert_tasks_on_queue(exps.length - app_stdin_num_tasks)
154
+
155
+ end
123
156
 
124
157
  end
125
158
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Gjertsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client