Birst_Command 0.2.2 → 0.3.0
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 +4 -4
- data/README.md +50 -6
- data/bin/birstcl +26 -1
- data/config.json_template +2 -2
- data/lib/birst_command/session.rb +6 -4
- data/lib/birst_command/version.rb +1 -1
- data/test/standard/test_cookie.rb +61 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcdd92e145719837d3ed3e8852f5988dd67ce45f
|
4
|
+
data.tar.gz: d2da607de6a3b7b6464f2d75a3b184233f3bc06b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4b62531154a7185851a7063ca352c4f02b5699b7c971c776d66923564dfcf1df4cd207b1e057c499cf6623519cbf7a214d6f5a7134841d198acf084a3b7c330
|
7
|
+
data.tar.gz: 4450044f4856ed4ecfe05b59ba189926f8edf93cad684a3d38f9b5ab0ebbfb024579448a39bede084cb75843e98c3811163c2d1f676155ade18c5861253e8043
|
data/README.md
CHANGED
@@ -9,6 +9,8 @@ Birst user that needed to set up a very basic Ruby interface.
|
|
9
9
|
|
10
10
|
# Installation & Setup
|
11
11
|
|
12
|
+
Prerequisites: Ruby > 2.0 and rubygems.
|
13
|
+
|
12
14
|
Install the gem using `gem install Birst_Command` or using rvm or
|
13
15
|
rbenv/bundler as you prefer.
|
14
16
|
|
@@ -17,13 +19,15 @@ that contains the credentials you'll use to connect to Birst. This
|
|
17
19
|
config file should look like,
|
18
20
|
|
19
21
|
{
|
20
|
-
"wsdl": "https://
|
21
|
-
"endpoint": "https://
|
22
|
+
"wsdl": "https://app2102.bws.birst.com/CommandWebService.asmx?WSDL",
|
23
|
+
"endpoint": "https://app2102.bws.birst.com/CommandWebService.asmx",
|
22
24
|
"username": "name@myplace.com",
|
23
25
|
"password": "obfuscated pwd"
|
24
26
|
}
|
25
27
|
|
26
|
-
Most users should only need to modify the username and
|
28
|
+
Most users should only need to modify the username and
|
29
|
+
password. (**Note**: do not use `login.bws.birst.com` since it does
|
30
|
+
not use an updated WSDL; a specific app server must be specified).
|
27
31
|
Since I have a strong aversion to storing passwords in plaintext, the
|
28
32
|
password in the config file needs to be an obfuscated password. Birst
|
29
33
|
Command comes with a password obfuscator that can be executed via
|
@@ -61,6 +65,24 @@ Copy space with options
|
|
61
65
|
|
62
66
|
birstcl -c copy_space -a '{ spFromID: "9ab9865c-37a8-0586-e856-ddd3856a0371", spToID: "3957a9b7-38c1-175v-3985-1957f1836a93", mode: "replicate", options: "data;repository;settings-basic" }'
|
63
67
|
|
68
|
+
## Cookies
|
69
|
+
|
70
|
+
Many Birst web API commands return a job token that can be used to check up
|
71
|
+
on the status of a job as it progresses. The job tokens are tied to a specific
|
72
|
+
server, and the only way to direct your login to a specific server is to use
|
73
|
+
cookies. So, if you wanted to copy a space with one command and then
|
74
|
+
check whether the job is complete with another, you need to do something
|
75
|
+
like the following.
|
76
|
+
|
77
|
+
Copy a space and write a cookie file
|
78
|
+
|
79
|
+
birstcl -c copy_space -a '{ spFromID: "f9cb64fe-58a1-1db6-a7a8-9f091b4ea96f", spToID: "12913e53-3eac-4f98-91ab-2fqf345e22e5", mode: "replicate", options: "data;datastore;repository;useunloadfeature" }' -w ./cookie
|
80
|
+
|
81
|
+
Note the job token returned as result and then run another command to
|
82
|
+
check whether the job is complete by reading the cookie file
|
83
|
+
|
84
|
+
birstcl -c is_job_complete -a '{ jobToken: "9f636262f4c73d7503bf240ea08de040" }' -r ./cookie
|
85
|
+
|
64
86
|
# Usage - As Ruby library
|
65
87
|
|
66
88
|
In your Ruby program, include the Birst Command gem and load the config file via
|
@@ -108,6 +130,29 @@ The `spaces` variable is a Ruby hash parsed from the SOAP response.
|
|
108
130
|
The structure of the returned hash follows the structure that Birst
|
109
131
|
returns.
|
110
132
|
|
133
|
+
## Cookies
|
134
|
+
|
135
|
+
The start session block can also accept an argument named `use_cookie` to
|
136
|
+
pass a cookie to be used during startup. For example, suppose we start
|
137
|
+
a copy job and save the `session_cookie` and `job_token` in variables.
|
138
|
+
|
139
|
+
````ruby
|
140
|
+
session_cookie = nil
|
141
|
+
job_token = nil
|
142
|
+
Session.start do |bc|
|
143
|
+
job_token = bc.copy_space :spFromID => @from_id, :spToID => @to_id, :mode => "replicate", :options => "data;datastore;useunloadfeature"
|
144
|
+
session_cookie = bc.auth_cookies
|
145
|
+
end
|
146
|
+
````
|
147
|
+
In a subsequent session we can use the `session_cookie` on login via
|
148
|
+
|
149
|
+
````ruby
|
150
|
+
is_job_complete = false
|
151
|
+
Session.start use_cookie: session_cookie do |bc|
|
152
|
+
is_job_complete = bc.is_job_complete :jobToken => job_token
|
153
|
+
end
|
154
|
+
puts "COMPLETE? #{is_job_complete}"
|
155
|
+
````
|
111
156
|
|
112
157
|
## Helper methods
|
113
158
|
|
@@ -135,6 +180,7 @@ I have not included any of these helper methods in the Birst Command
|
|
135
180
|
gem because what I find helpful, you may not. Birst Command just
|
136
181
|
provides the basic interface.
|
137
182
|
|
183
|
+
|
138
184
|
## Command arguments
|
139
185
|
|
140
186
|
Some Birst API commands require arguments. All arguments are supplied
|
@@ -142,9 +188,7 @@ as an argument hash. For example, to create a new space,
|
|
142
188
|
|
143
189
|
````ruby
|
144
190
|
Birst_Command::Session.start do |bc|
|
145
|
-
new_space_id = bc.create_new_space :spaceName => "myNewSpace",
|
146
|
-
:comments => "Just testing",
|
147
|
-
:automatic => "false"
|
191
|
+
new_space_id = bc.create_new_space :spaceName => "myNewSpace", :comments => "Just testing",:automatic => "false"
|
148
192
|
end
|
149
193
|
````
|
150
194
|
|
data/bin/birstcl
CHANGED
@@ -47,6 +47,17 @@ module BirstCL
|
|
47
47
|
opts.on("-s","--config_file <CONFIG FILE>", "Path to config file containing credentials (default: $HOME/.birstcl)") do |opt|
|
48
48
|
@options[:config_full_path] = opt
|
49
49
|
end
|
50
|
+
|
51
|
+
@options[:write_cookie_full_path] = nil
|
52
|
+
opts.on("-w","--write_cookie_file <COOKIE FILE>", "Path to cookie file to write") do |opt|
|
53
|
+
@options[:write_cookie_full_path] = opt
|
54
|
+
end
|
55
|
+
|
56
|
+
@options[:read_cookie_full_path] = nil
|
57
|
+
opts.on("-r","--read_cookie_file <COOKIE FILE>", "Path to cookie file to read") do |opt|
|
58
|
+
@options[:read_cookie_full_path] = opt
|
59
|
+
end
|
60
|
+
|
50
61
|
end.parse!
|
51
62
|
|
52
63
|
if @options[:version]
|
@@ -61,17 +72,31 @@ module BirstCL
|
|
61
72
|
end
|
62
73
|
|
63
74
|
|
75
|
+
def write_cookie_file(file_full_path)
|
76
|
+
return nil if file_full_path.nil?
|
77
|
+
File.open(file_full_path, 'w') {|f| f.write(Marshal.dump(@session_cookie)) }
|
78
|
+
end
|
79
|
+
|
80
|
+
def read_cookie_file(file_full_path)
|
81
|
+
return nil if file_full_path.nil?
|
82
|
+
Marshal.load(File.read(file_full_path))
|
83
|
+
end
|
84
|
+
|
85
|
+
|
64
86
|
def execute_command
|
87
|
+
@session_cookie = read_cookie_file(@options[:read_cookie_full_path])
|
65
88
|
output = {}
|
66
89
|
|
67
90
|
output[:command] = @options[:command]
|
68
91
|
output[:arguments] = @options[:arguments]
|
69
|
-
Birst_Command::Session.start do |bc|
|
92
|
+
Birst_Command::Session.start use_cookie: @session_cookie do |bc|
|
70
93
|
output[:token] = bc.token
|
71
94
|
output[:auth_cookies] = bc.auth_cookies.inspect
|
72
95
|
output[:result] = bc.send(@options[:command], @options[:arguments])
|
96
|
+
@session_cookie = bc.auth_cookies
|
73
97
|
end
|
74
98
|
puts "#{JSON.pretty_generate output}"
|
99
|
+
write_cookie_file(@options[:write_cookie_full_path])
|
75
100
|
end
|
76
101
|
end
|
77
102
|
|
data/config.json_template
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
|
-
"wsdl": "https://
|
3
|
-
"endpoint": "https://
|
2
|
+
"wsdl": "https://app2102.bws.birst.com/CommandWebService.asmx?WSDL",
|
3
|
+
"endpoint": "https://app2102.bws.birst.com/CommandWebService.asmx",
|
4
4
|
"username": "name@myplace.com",
|
5
5
|
"password": "obfuscated pwd"
|
6
6
|
}
|
@@ -24,23 +24,25 @@ module Birst_Command
|
|
24
24
|
attr_reader :response
|
25
25
|
|
26
26
|
|
27
|
-
def self.start(&b)
|
27
|
+
def self.start(use_cookie: nil, &b)
|
28
28
|
session = self.new
|
29
|
-
session.login
|
29
|
+
session.login(use_cookie: use_cookie)
|
30
30
|
session.execute_block(&b)
|
31
31
|
ensure
|
32
32
|
session.logout
|
33
33
|
end
|
34
34
|
|
35
35
|
|
36
|
-
def login
|
36
|
+
def login(use_cookie: nil)
|
37
|
+
@auth_cookies = use_cookie
|
37
38
|
@response = @client.call(:login,
|
39
|
+
cookies: @auth_cookies,
|
38
40
|
message: {
|
39
41
|
username: @options[:username],
|
40
42
|
password: Obfuscate.deobfuscate(@options[:password])
|
41
43
|
})
|
42
44
|
|
43
|
-
@auth_cookies = @response.http.cookies
|
45
|
+
@auth_cookies = @response.http.cookies if @auth_cookies.nil?
|
44
46
|
@token = @response.hash[:envelope][:body][:login_response][:login_result]
|
45
47
|
end
|
46
48
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "test_birst_command"
|
2
|
+
|
3
|
+
class Test_cookie < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Birst_Command::Config.read_config
|
7
|
+
Birst_Command::Config.read_config(File.join(File.dirname(__FILE__),"../config_test.json"))
|
8
|
+
@new_space_id = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
Session.start do |bc|
|
13
|
+
bc.delete_space :spaceId => @new_space_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_cookie_using_a_copy_command
|
18
|
+
test_options = Birst_Command::Config.options[:test][:test_copy_space]
|
19
|
+
|
20
|
+
session_cookie = nil
|
21
|
+
job_token = nil
|
22
|
+
Session.start do |bc|
|
23
|
+
@new_space_id = bc.create_new_space :spaceName => "test_copy_space",
|
24
|
+
:comments => "",
|
25
|
+
:automatic => "false"
|
26
|
+
|
27
|
+
puts "#{JSON.pretty_generate bc.list_spaces}"
|
28
|
+
job_token = bc.copy_space :spFromID => test_options[:from_space_id],
|
29
|
+
:spToID => @new_space_id,
|
30
|
+
:mode => "copy",
|
31
|
+
:options => "data;settings-permissions;settings-membership;repository;birst-connect;custom-subject-areas;dashboardstyles;salesforce;catalog;CustomGeoMaps.xml;spacesettings.xml;SavedExpressions.xml;DrillMaps.xml;connectors;datastore-aggregates;settings-basic"
|
32
|
+
|
33
|
+
session_cookie = bc.auth_cookies
|
34
|
+
end
|
35
|
+
|
36
|
+
puts "COOKIE COOKIE: #{session_cookie}"
|
37
|
+
|
38
|
+
i = 0
|
39
|
+
loop do
|
40
|
+
i += 1
|
41
|
+
if i < 60
|
42
|
+
is_job_complete = false
|
43
|
+
Session.start use_cookie: session_cookie do |bc|
|
44
|
+
is_job_complete = bc.is_job_complete :jobToken => job_token
|
45
|
+
end
|
46
|
+
puts "COMPLETE? #{is_job_complete}"
|
47
|
+
|
48
|
+
sleep 1
|
49
|
+
break if is_job_complete
|
50
|
+
else
|
51
|
+
raise "Copy job timed out"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# This test sucks, but it will fail if the cookies don't work
|
58
|
+
assert_equal 36, @new_space_id.length, "Got an invalid space id #{@new_space_id}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Birst_Command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sterling Paramore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- test/standard/resources/config_test.json
|
70
70
|
- test/standard/test_add_user_to_space.rb
|
71
71
|
- test/standard/test_command_helper.rb
|
72
|
+
- test/standard/test_cookie.rb
|
72
73
|
- test/standard/test_copy_space.rb
|
73
74
|
- test/standard/test_deobfuscate.rb
|
74
75
|
- test/standard/test_list_spaces.rb
|
@@ -104,6 +105,7 @@ test_files:
|
|
104
105
|
- test/standard/resources/config_test.json
|
105
106
|
- test/standard/test_add_user_to_space.rb
|
106
107
|
- test/standard/test_command_helper.rb
|
108
|
+
- test/standard/test_cookie.rb
|
107
109
|
- test/standard/test_copy_space.rb
|
108
110
|
- test/standard/test_deobfuscate.rb
|
109
111
|
- test/standard/test_list_spaces.rb
|