workato-connector-sdk 0.4.1 → 0.5.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/lib/workato/cli/generate_command.rb +32 -5
- data/lib/workato/cli/main.rb +3 -2
- data/lib/workato/cli/oauth2_command.rb +2 -0
- data/lib/workato/cli/push_command.rb +2 -5
- data/lib/workato/cli/schema_command.rb +81 -0
- data/lib/workato/connector/sdk/version.rb +1 -1
- data/lib/workato/connector/sdk.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8d30836873d60dede61747b573f51864653aeabc2831f173663db68f42479c5
|
4
|
+
data.tar.gz: 19c2031601b7f63b317c42f081cf08044e3b75f3feefabc4f557f86b95f5e3c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e378b75932e66e5e9399870981d62473cdfe14f98facaebefc7de3faaf27e1382b17b6f019c45530f7130d9c81498ae3410bf2278ba67e29efd73fb6790e8c1e
|
7
|
+
data.tar.gz: 8d6a10d7e30515c7e6c86a9eb1cc2f88794d05bf42b0ccc2d3a24ac094134a8fd8a4cb3a7a8c321c2b786cc22a8825b26945a30b0d6eaa4de8d9451beefe3b42
|
@@ -39,12 +39,39 @@ module Workato
|
|
39
39
|
create_spec_files
|
40
40
|
end
|
41
41
|
|
42
|
-
desc 'schema', 'Generate schema
|
42
|
+
desc 'schema', 'Generate schema from example'
|
43
|
+
|
44
|
+
method_option :json, type: :string, desc: 'Path to JSON sample file'
|
45
|
+
method_option :csv, type: :string, desc: 'Path to CSV sample file'
|
46
|
+
method_option :col_sep,
|
47
|
+
type: :string,
|
48
|
+
desc: 'Use separator for CSV convertor',
|
49
|
+
enum: SchemaCommand::CSV_SEPARATORS,
|
50
|
+
default: 'comma'
|
51
|
+
method_option :api_email,
|
52
|
+
type: :string,
|
53
|
+
desc: 'Email for accessing Workato API or '\
|
54
|
+
"set #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} env"
|
55
|
+
method_option :api_token,
|
56
|
+
type: :string,
|
57
|
+
desc: 'Token for accessing Workato API or ' \
|
58
|
+
"set #{Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV} env"
|
59
|
+
|
60
|
+
long_desc <<~HELP
|
61
|
+
The 'workato generate schema' command generates Workato Schema from a sample file.
|
62
|
+
Supported inputs #{SchemaCommand::SAMPLE_TO_SCHEMA_SUPPORT_TYPES.join(', ')}
|
63
|
+
|
64
|
+
Example:
|
65
|
+
|
66
|
+
workato generate schema --csv=input.csv --col-sep=semicolon # This generates a schema from CSV file.
|
67
|
+
|
68
|
+
workato generate schema --json=input.json
|
69
|
+
HELP
|
70
|
+
|
43
71
|
def schema
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
HELP
|
72
|
+
SchemaCommand.new(
|
73
|
+
options: options
|
74
|
+
).call
|
48
75
|
end
|
49
76
|
|
50
77
|
private
|
data/lib/workato/cli/main.rb
CHANGED
@@ -4,6 +4,7 @@ require 'thor'
|
|
4
4
|
require 'workato/connector/sdk'
|
5
5
|
require_relative './exec_command'
|
6
6
|
require_relative './edit_command'
|
7
|
+
require_relative './schema_command'
|
7
8
|
require_relative './generate_command'
|
8
9
|
require_relative './push_command'
|
9
10
|
require_relative './oauth2_command'
|
@@ -125,11 +126,11 @@ module Workato
|
|
125
126
|
method_option :api_email,
|
126
127
|
type: :string,
|
127
128
|
desc: 'Email for accessing Workato API or '\
|
128
|
-
"set #{Workato::
|
129
|
+
"set #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} env"
|
129
130
|
method_option :api_token,
|
130
131
|
type: :string,
|
131
132
|
desc: 'Token for accessing Workato API or ' \
|
132
|
-
"set #{Workato::
|
133
|
+
"set #{Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV} env"
|
133
134
|
method_option :environment,
|
134
135
|
type: :string,
|
135
136
|
enum: Workato::CLI::PushCommand::ENVIRONMENTS.keys,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'securerandom'
|
3
4
|
require 'workato/web/app'
|
4
5
|
|
5
6
|
module Workato
|
@@ -112,6 +113,7 @@ module Workato
|
|
112
113
|
@authorize_url =
|
113
114
|
if (authorization_url = connector.connection.authorization.authorization_url(settings))
|
114
115
|
params = {
|
116
|
+
state: SecureRandom.hex(8),
|
115
117
|
client_id: connector.connection.authorization.client_id(settings),
|
116
118
|
redirect_uri: redirect_url
|
117
119
|
}
|
@@ -10,9 +10,6 @@ module Workato
|
|
10
10
|
class PushCommand
|
11
11
|
include Thor::Shell
|
12
12
|
|
13
|
-
WORKATO_API_TOKEN_ENV = 'WORKATO_API_TOKEN'
|
14
|
-
WORKATO_API_EMAIL_ENV = 'WORKATO_API_EMAIL'
|
15
|
-
|
16
13
|
ENVIRONMENTS = {
|
17
14
|
'preview' => 'https://app.preview.workato.com',
|
18
15
|
'preview-eu' => 'https://app.preview.eu.workato.com',
|
@@ -35,8 +32,8 @@ module Workato
|
|
35
32
|
def initialize(options:)
|
36
33
|
@options = options
|
37
34
|
@api_base_url = ENVIRONMENTS.fetch(options[:environment])
|
38
|
-
@api_email = options[:api_email] || ENV[WORKATO_API_EMAIL_ENV]
|
39
|
-
@api_token = options[:api_token] || ENV[WORKATO_API_TOKEN_ENV]
|
35
|
+
@api_email = options[:api_email] || ENV[Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV]
|
36
|
+
@api_token = options[:api_token] || ENV[Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV]
|
40
37
|
@folder_id = options[:folder]
|
41
38
|
end
|
42
39
|
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Workato
|
4
|
+
module CLI
|
5
|
+
class SchemaCommand
|
6
|
+
include Thor::Shell
|
7
|
+
|
8
|
+
SAMPLE_TO_SCHEMA_SUPPORT_TYPES = %w[csv json].freeze
|
9
|
+
CSV_SEPARATORS = %w[comma space tab colon semicolon pipe].freeze
|
10
|
+
|
11
|
+
WORKATO_BASE_URL = ENV['WORKATO_BASE_URL'] || 'https://app.workato.com'
|
12
|
+
API_GENERATE_SCHEMA_PATH = '/api/sdk/generate_schema'
|
13
|
+
|
14
|
+
def initialize(options:)
|
15
|
+
@api_email = options[:api_email] || ENV[Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV]
|
16
|
+
@api_token = options[:api_token] || ENV[Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV]
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
if verbose?
|
22
|
+
say('INPUT')
|
23
|
+
say sample[:sample]
|
24
|
+
end
|
25
|
+
|
26
|
+
schema = sample_to_schema(sample)
|
27
|
+
|
28
|
+
say('SCHEMA') if verbose?
|
29
|
+
jj schema
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :options,
|
35
|
+
:api_token,
|
36
|
+
:api_email
|
37
|
+
|
38
|
+
def verbose?
|
39
|
+
@options[:verbose]
|
40
|
+
end
|
41
|
+
|
42
|
+
def sample
|
43
|
+
return @sample if @sample
|
44
|
+
|
45
|
+
@sample = if options[:json]
|
46
|
+
{ sample: File.read(options[:json]), type: :json }
|
47
|
+
elsif options[:csv]
|
48
|
+
{ sample: File.read(options[:csv]), type: :csv, col_sep: options[:col_sep] }
|
49
|
+
else
|
50
|
+
{ sample: {}, type: :json }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sample_to_schema(sample)
|
55
|
+
url = "#{WORKATO_BASE_URL}#{API_GENERATE_SCHEMA_PATH}/#{sample.delete(:type)}"
|
56
|
+
response = RestClient.post(
|
57
|
+
url,
|
58
|
+
sample.to_json,
|
59
|
+
{
|
60
|
+
content_type: :json,
|
61
|
+
accept: :json
|
62
|
+
}.merge(auth_headers)
|
63
|
+
)
|
64
|
+
JSON.parse(response.body)
|
65
|
+
rescue RestClient::ExceptionWithResponse => e
|
66
|
+
message = JSON.parse(e.response.body).fetch('message') rescue e.message
|
67
|
+
raise "Failed to generate schema: #{message}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def auth_headers
|
71
|
+
{
|
72
|
+
'x-user-email' => api_email,
|
73
|
+
'x-user-token' => api_token
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
private_constant :API_GENERATE_SCHEMA_PATH,
|
78
|
+
:WORKATO_BASE_URL
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workato-connector-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Abolmasov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -380,6 +380,7 @@ files:
|
|
380
380
|
- lib/workato/cli/main.rb
|
381
381
|
- lib/workato/cli/oauth2_command.rb
|
382
382
|
- lib/workato/cli/push_command.rb
|
383
|
+
- lib/workato/cli/schema_command.rb
|
383
384
|
- lib/workato/connector/sdk.rb
|
384
385
|
- lib/workato/connector/sdk/account_properties.rb
|
385
386
|
- lib/workato/connector/sdk/action.rb
|
@@ -468,7 +469,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
468
469
|
- !ruby/object:Gem::Version
|
469
470
|
version: '0'
|
470
471
|
requirements: []
|
471
|
-
rubygems_version: 3.
|
472
|
+
rubygems_version: 3.2.3
|
472
473
|
signing_key:
|
473
474
|
specification_version: 4
|
474
475
|
summary: Gem for running adapter's code outside Workato infrastructure
|