gooddata 0.6.0.pre6 → 0.6.0.pre7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gooddata +102 -56
- data/gooddata.gemspec +3 -0
- data/lib/gooddata/bricks/base_downloader.rb +62 -0
- data/lib/gooddata/bricks/brick.rb +24 -25
- data/lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb +38 -0
- data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +4 -2
- data/lib/gooddata/bricks/middleware/restforce_middleware.rb +9 -10
- data/lib/gooddata/client.rb +21 -1
- data/lib/gooddata/commands/auth.rb +68 -60
- data/lib/gooddata/commands/process.rb +75 -62
- data/lib/gooddata/commands/runners.rb +9 -6
- data/lib/gooddata/connection.rb +45 -20
- data/lib/gooddata/helpers.rb +31 -4
- data/lib/gooddata/model.rb +199 -72
- data/lib/gooddata/models/data_result.rb +94 -101
- data/lib/gooddata/models/metadata.rb +31 -9
- data/lib/gooddata/models/metric.rb +1 -1
- data/lib/gooddata/models/process.rb +2 -59
- data/lib/gooddata/models/project.rb +1 -1
- data/lib/gooddata/models/project_metadata.rb +10 -1
- data/lib/gooddata/models/report.rb +0 -3
- data/lib/gooddata/models/report_definition.rb +43 -8
- data/lib/gooddata/version.rb +1 -1
- data/spec/full_project_spec.rb +54 -0
- data/spec/goodzilla_spec.rb +2 -2
- data/spec/model_dsl_spec.rb +2 -1
- data/spec/test_project_model_spec.json +86 -0
- metadata +53 -2
- data/TODO.md +0 -77
data/bin/gooddata
CHANGED
@@ -3,6 +3,12 @@ require 'gli'
|
|
3
3
|
require 'gooddata'
|
4
4
|
require 'highline/import'
|
5
5
|
require 'gooddata/commands/projects'
|
6
|
+
require 'gooddata/commands/auth'
|
7
|
+
require 'gooddata/commands/scaffold'
|
8
|
+
require 'gooddata/commands/process'
|
9
|
+
require 'gooddata/commands/api'
|
10
|
+
require 'gooddata/commands/profile'
|
11
|
+
require 'pp'
|
6
12
|
|
7
13
|
include GLI::App
|
8
14
|
|
@@ -61,66 +67,77 @@ command :process do |c|
|
|
61
67
|
c.default_value nil
|
62
68
|
c.flag :dir
|
63
69
|
|
64
|
-
c.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
GoodData::Command::Process.
|
70
|
+
c.desc 'Specify type of deployment'
|
71
|
+
c.default_value nil
|
72
|
+
c.flag :type
|
73
|
+
|
74
|
+
c.desc 'Specify name of deployed process'
|
75
|
+
c.default_value nil
|
76
|
+
c.flag :name
|
77
|
+
|
78
|
+
c.command :list do |list|
|
79
|
+
list.action do |global_options,options,args|
|
80
|
+
pp GoodData::Command::Process.list(options.merge(global_options))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
c.command :get do |get|
|
85
|
+
get.action do |global_options,options,args|
|
86
|
+
pp GoodData::Command::Process.get(options.merge(global_options))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
c.command :deploy do |deploy|
|
91
|
+
deploy.action do |global_options,options,args|
|
92
|
+
pp GoodData::Command::Process.deploy(options[:dir], options.merge(global_options))
|
75
93
|
end
|
76
94
|
end
|
95
|
+
|
77
96
|
end
|
78
97
|
|
79
98
|
desc 'Some basic API stuff directly from CLI'
|
80
99
|
arg_name 'info|test|get|delete'
|
81
100
|
command :api do |c|
|
82
101
|
|
83
|
-
c.
|
84
|
-
|
85
|
-
options = options.merge(global_options)
|
86
|
-
|
87
|
-
case args.first
|
88
|
-
when "list", "index", "info"
|
102
|
+
c.command :info do |info|
|
103
|
+
info.action do |global_options,options,args|
|
89
104
|
pp GoodData::Command::Api.info
|
90
|
-
when "get"
|
91
|
-
pp GoodData::Command::Api.get(args[1])
|
92
|
-
when "deploy"
|
93
|
-
GoodData::Command::Api.deploy_graph(options[:dir], options)
|
94
105
|
end
|
95
106
|
end
|
107
|
+
|
108
|
+
c.command :get do |get|
|
109
|
+
get.action do |global_options,options,args|
|
110
|
+
pp GoodData::Command::Api.get(args[0])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
96
114
|
end
|
97
115
|
|
98
116
|
|
99
117
|
desc 'Describe add here'
|
100
118
|
arg_name 'show'
|
101
119
|
command :profile do |c|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
case args.first
|
106
|
-
when "show"
|
120
|
+
|
121
|
+
c.command :show do |show|
|
122
|
+
show.action do |global_options,options,args|
|
107
123
|
pp GoodData::Command::Profile.show()
|
108
|
-
else
|
109
|
-
raise "command provided not right"
|
110
124
|
end
|
111
125
|
end
|
126
|
+
|
112
127
|
end
|
113
128
|
|
114
129
|
desc 'Scaffold things'
|
115
130
|
arg_name 'show'
|
116
131
|
command :scaffold do |c|
|
117
132
|
c.action do |global_options, options, args|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
133
|
+
|
134
|
+
c.command :brick do |brick|
|
135
|
+
brick.arg_name 'name'
|
136
|
+
|
137
|
+
name = args[1]
|
138
|
+
fail "Name of the brick has to be provided" if name.nil? || name.empty?
|
139
|
+
|
140
|
+
GoodData::Command::Scaffold.brick(name)
|
124
141
|
end
|
125
142
|
end
|
126
143
|
end
|
@@ -136,6 +153,26 @@ command :project do |c|
|
|
136
153
|
end
|
137
154
|
end
|
138
155
|
|
156
|
+
c.command :jack_in do |jack|
|
157
|
+
jack.action do |global_options,options,args|
|
158
|
+
|
159
|
+
goodfile = JSON.parse(File.read(GoodData::Helpers.find_goodfile(Pathname('.'))), :symbolize_names => true)
|
160
|
+
model_key = goodfile[:model]
|
161
|
+
blueprint = GoodData::Model::ProjectBlueprint.new(eval(File.read(model_key)).to_hash) if File.exist?(model_key) && !File.directory?(model_key)
|
162
|
+
|
163
|
+
project_id = global_options[:project_id] || goodfile[:project_id]
|
164
|
+
fail "You have to provide 'project_id'" if project_id.nil?
|
165
|
+
|
166
|
+
GoodData.with_project(project_id) do |project|
|
167
|
+
puts "Use 'exit' to quit the interactive session. Use 'q' to jump out of displaying a large output."
|
168
|
+
binding.pry(:quiet => true,
|
169
|
+
:prompt => [proc { |target_self, nest_level, pry|
|
170
|
+
"project_live_sesion: "
|
171
|
+
}])
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
139
176
|
c.command :create do |create|
|
140
177
|
create.action do |global_options,options,args|
|
141
178
|
title = ask "Project name"
|
@@ -189,9 +226,12 @@ command :project do |c|
|
|
189
226
|
|
190
227
|
c.command :build do |show|
|
191
228
|
show.action do |global_options,options,args|
|
192
|
-
|
229
|
+
goodfile = JSON.parse(File.read(GoodData::Helpers.find_goodfile(Pathname('.'))), :symbolize_names => true)
|
230
|
+
spec_path = goodfile[:model] || fail("You need to specify the path of the build spec")
|
231
|
+
fail "Model path provided in Goodfile \"#{spec_path}\" does not exist" unless File.exist?(spec_path) && !File.directory?(spec_path)
|
232
|
+
|
193
233
|
opts = options.merge(global_options)
|
194
|
-
spec_path = Pathname
|
234
|
+
spec_path = Pathname(spec_path)
|
195
235
|
|
196
236
|
content = File.read(spec_path)
|
197
237
|
spec = if (spec_path.extname == ".rb")
|
@@ -206,6 +246,17 @@ command :project do |c|
|
|
206
246
|
|
207
247
|
end
|
208
248
|
|
249
|
+
desc 'Work with your credentials'
|
250
|
+
command :auth do |c|
|
251
|
+
|
252
|
+
c.command :store do |store|
|
253
|
+
store.action do |global_options,options,args|
|
254
|
+
GoodData::Command::Auth.store
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
209
260
|
desc 'Run bricks locally'
|
210
261
|
# arg_name 'show'
|
211
262
|
command :run_ruby do |c|
|
@@ -214,10 +265,6 @@ command :run_ruby do |c|
|
|
214
265
|
c.default_value nil
|
215
266
|
c.flag [:d, :dir]
|
216
267
|
|
217
|
-
c.desc 'Project id for which you would like to run the script'
|
218
|
-
c.default_value nil
|
219
|
-
c.flag [:p, :project, :project_id, :project_pid]
|
220
|
-
|
221
268
|
c.desc 'Log file. If empty STDOUT will be used instead'
|
222
269
|
c.default_value nil
|
223
270
|
c.flag [:l, :logger]
|
@@ -235,13 +282,13 @@ command :run_ruby do |c|
|
|
235
282
|
|
236
283
|
|
237
284
|
c.action do |global_options, options, args|
|
238
|
-
options[:
|
285
|
+
options[:expanded_params] = if (options[:params])
|
239
286
|
JSON.parse(File.read(options[:params]), :symbolize_names => true)
|
240
287
|
else
|
241
288
|
{}
|
242
289
|
end
|
243
290
|
|
244
|
-
opts = options.merge(global_options).merge({:
|
291
|
+
opts = options.merge(global_options).merge({:type => "RUBY"})
|
245
292
|
if options[:remote]
|
246
293
|
fail "You have to specify name of the deploy when deploying remotely" if options[:name].nil? || options[:name].empty?
|
247
294
|
require 'gooddata/commands/process'
|
@@ -255,29 +302,28 @@ command :run_ruby do |c|
|
|
255
302
|
end
|
256
303
|
end
|
257
304
|
|
258
|
-
desc 'Manage your projects'
|
259
|
-
arg_name 'project_command'
|
260
|
-
command :project do |c|
|
261
|
-
|
262
|
-
c.command :list do |list|
|
263
|
-
list.action do |global_options,options,args|
|
264
|
-
list = GoodData::Command::Projects.list()
|
265
|
-
puts list.map {|p| [p.uri, p.title].join(",")}
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
end
|
270
|
-
|
271
305
|
pre do |global,command,options,args|
|
272
306
|
require 'logger'
|
273
307
|
GoodData.logger = Logger.new(STDOUT) if global[:l]
|
274
308
|
username = global[:username]
|
275
309
|
password = global[:password]
|
310
|
+
token = global[:token]
|
276
311
|
|
312
|
+
creds = GoodData::Command::Auth.read_credentials
|
313
|
+
|
314
|
+
username = creds[:username] if username.nil?
|
315
|
+
password = creds[:password] if password.nil?
|
316
|
+
token = creds[:auth_token] if token.nil?
|
317
|
+
|
318
|
+
global[:token] = token if global[:token].nil?
|
319
|
+
global[:username] = username if global[:username].nil?
|
320
|
+
global[:password] = password if global[:password].nil?
|
321
|
+
|
277
322
|
GoodData.connect(global.merge(options).merge({
|
278
323
|
:login => username,
|
279
324
|
:password => password,
|
280
|
-
:server => global[:server]
|
325
|
+
:server => global[:server],
|
326
|
+
:token => token
|
281
327
|
}))
|
282
328
|
|
283
329
|
# Pre logic here
|
data/gooddata.gemspec
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
module GoodData::Bricks
|
2
|
+
class BaseDownloader
|
3
|
+
|
4
|
+
def initialize(params)
|
5
|
+
@params = params
|
6
|
+
end
|
7
|
+
|
8
|
+
def pre_process(meta)
|
9
|
+
meta
|
10
|
+
end
|
11
|
+
|
12
|
+
def download
|
13
|
+
puts "would download data"
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
|
17
|
+
def backup(meta)
|
18
|
+
puts "would send a backup list of files to backup"
|
19
|
+
files = meta.reduce([]) do |memo, item|
|
20
|
+
memo << item[:filename]
|
21
|
+
end
|
22
|
+
|
23
|
+
bucket_name = @params[:s3_backup_bucket_name]
|
24
|
+
|
25
|
+
s3 = AWS::S3.new(
|
26
|
+
:access_key_id => @params[:aws_access_key_id],
|
27
|
+
:secret_access_key => @params[:aws_secret_access_key])
|
28
|
+
|
29
|
+
bucket = s3.buckets[bucket_name]
|
30
|
+
bucket = s3.buckets.create(bucket_name) unless bucket.exists?
|
31
|
+
|
32
|
+
files.each do |file|
|
33
|
+
obj = bucket.objects[file]
|
34
|
+
obj.write(Pathname.new(file))
|
35
|
+
end
|
36
|
+
meta
|
37
|
+
end
|
38
|
+
|
39
|
+
def post_process(meta)
|
40
|
+
puts "Maybe some postprocessing"
|
41
|
+
meta
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
downloaded_data = download
|
46
|
+
downloaded_data = pre_process(downloaded_data)
|
47
|
+
backup(downloaded_data)
|
48
|
+
downloaded_data = post_process(downloaded_data)
|
49
|
+
|
50
|
+
downloaded_data.reduce([]) do |memo, item|
|
51
|
+
item.has_key?(:state) ? memo.concat(item[:state]) : memo
|
52
|
+
end.each do |item|
|
53
|
+
key = item[:key]
|
54
|
+
val = item[:value]
|
55
|
+
|
56
|
+
puts "Saving metadata #{}"
|
57
|
+
GoodData::ProjectMetadata[key] = val
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -1,42 +1,41 @@
|
|
1
1
|
require 'gooddata/bricks/utils'
|
2
|
+
require 'gooddata/bricks/base_downloader'
|
2
3
|
require 'gooddata/bricks/middleware/middleware'
|
3
4
|
require 'gooddata/bricks/middleware/bench_middleware'
|
4
5
|
require 'gooddata/bricks/middleware/gooddata_middleware'
|
5
6
|
require 'gooddata/bricks/middleware/logger_middleware'
|
6
7
|
require 'gooddata/bricks/middleware/stdout_middleware'
|
7
8
|
require 'gooddata/bricks/middleware/restforce_middleware'
|
9
|
+
require 'gooddata/bricks/middleware/bulk_salesforce_middleware.rb'
|
8
10
|
require 'gooddata/bricks/middleware/twitter_middleware'
|
9
11
|
|
10
|
-
module GoodData
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def self.prepare(pipeline)
|
15
|
-
pipeline.reverse.reduce(nil) {|memo, app| memo.nil? ? app.new : app.new(memo)}
|
16
|
-
end
|
12
|
+
module GoodData::Bricks
|
13
|
+
class Pipeline
|
14
|
+
def self.prepare(pipeline)
|
15
|
+
pipeline.reverse.reduce(nil) {|memo, app| memo.nil? ? app.new : app.new(memo)}
|
17
16
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def log(message)
|
22
|
-
logger = @params[:gdc_logger]
|
23
|
-
logger.info(message) unless logger.nil?
|
24
|
-
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Brick
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
def log(message)
|
22
|
+
logger = @params[:gdc_logger]
|
23
|
+
logger.info(message) unless logger.nil?
|
24
|
+
end
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
def name
|
27
|
+
self.class
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
30
|
+
def version
|
31
|
+
fail "Method version should be reimplemented"
|
32
|
+
end
|
38
33
|
|
34
|
+
def call(params={})
|
35
|
+
@params = params
|
36
|
+
""
|
39
37
|
end
|
40
|
-
|
38
|
+
|
41
39
|
end
|
40
|
+
|
42
41
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'gooddata'
|
2
|
+
require 'salesforce_bulk'
|
3
|
+
|
4
|
+
module GoodData::Bricks
|
5
|
+
class BulkSalesforceMiddleware < GoodData::Bricks::Middleware
|
6
|
+
|
7
|
+
def call(params)
|
8
|
+
|
9
|
+
username = params[:salesforce_username]
|
10
|
+
password = params[:salesforce_password]
|
11
|
+
token = params[:salesforce_token]
|
12
|
+
client_id = params[:salesforce_client_id]
|
13
|
+
client_secret = params[:salesforce_client_secret]
|
14
|
+
host = params[:salesforce_host]
|
15
|
+
|
16
|
+
credentials = {}
|
17
|
+
|
18
|
+
credentials = if (username && password && token)
|
19
|
+
{
|
20
|
+
:username => username,
|
21
|
+
:password => password,
|
22
|
+
:security_token => token
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
client = if credentials
|
27
|
+
credentials.merge!({
|
28
|
+
:client_id => client_id,
|
29
|
+
:client_secret => client_secret,
|
30
|
+
})
|
31
|
+
credentials[:host] = host unless host.nil?
|
32
|
+
SalesforceBulk::Api.new(credentials[:username], credentials[:password] + credentials[:security_token])
|
33
|
+
end
|
34
|
+
@app.call(params.merge(:salesforce_bulk_client => client))
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -11,12 +11,14 @@ module GoodData::Bricks
|
|
11
11
|
project_id = params[:GDC_PROJECT_ID]
|
12
12
|
|
13
13
|
fail "SST (SuperSecureToken) not present in params" if params[token_name].nil?
|
14
|
-
logger.info "Connecting to GD with SST"
|
15
14
|
server = if !params[protocol_name].empty? && !params[server_name].empty?
|
16
15
|
params[protocol_name] + "://" + params[server_name]
|
17
16
|
end
|
18
17
|
|
19
|
-
GoodData.
|
18
|
+
fail "GoodData username is missing. Expected param :GDC_USERANME" if params[:GDC_USERNAME].nil?
|
19
|
+
fail "GoodData password is missing. Expected param :GDC_PASSWORD" if params[:GDC_PASSWORD].nil?
|
20
|
+
|
21
|
+
GoodData.connect(params[:GDC_USERNAME], params[:GDC_PASSWORD], {:server => server})
|
20
22
|
GoodData.logger = logger
|
21
23
|
GoodData.with_project(project_id) do |p|
|
22
24
|
@app.call(params)
|