xapixctl 1.2.2 → 1.2.3

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
  SHA256:
3
- metadata.gz: 4ba3cb0a95f481dfd6568282c75d0bc4a2db36a03c4b8a177401deac61b04eaa
4
- data.tar.gz: f5cd613fdcb2c9a204b224b6504348c4840fe45fd3506bea904bb26d5367793a
3
+ metadata.gz: afb1bf2d6f83193e0b5d1341fbfc1177c7c76802a2aa0cdef748f3d9eb0e7d11
4
+ data.tar.gz: 742c9ce8f28477d6bf922196c1d0d192ec1648db7fbe1cc73a1aba673c307f2d
5
5
  SHA512:
6
- metadata.gz: c0635abac3da2424e0109306eec1795dac8ae2cf9cb81aa4f8769ef397f5e70f4b5db7095b2820f0a49f7902d2d3e75df86b2128622fdaa10bb3082dea38ddab
7
- data.tar.gz: f14855a202d934303acf771987686dcf395c0842a870a309283bbd080c1ebd32c0c1178e1a0df2256352c575920e4116010953a4e6d2a8833e178f27838f5e85
6
+ metadata.gz: 87ecb583e67e5210f5cc9c2333d519e6bc160b7e0d8eb5236c407825acca54fc0dd1bfac178d2f0abef4becd29e5cc4b46bdc1d6e0c4ffcda79ab969a2d5846f
7
+ data.tar.gz: 5ee3f1ef369eb548117d7e277884348ea9cc4885f650bae9c3bb4191a72e7f4d3261ceb05b97f53ca2ee04c2a917fbd2937e96d024b4e4a690d3a0fe37926d80
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xapixctl (1.2.2)
4
+ xapixctl (1.2.3)
5
5
  activesupport (>= 5.2.3, < 6.0.0)
6
+ hashdiff (>= 1.0.1, < 1.2.0)
6
7
  rest-client (>= 2.1.0, < 3.0.0)
7
8
  thor (>= 1.0.0, < 1.2.0)
8
9
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'xapixctl/base_cli'
4
4
  require 'pathname'
5
+ require 'hashdiff'
5
6
 
6
7
  module Xapixctl
7
8
  class SyncCli < BaseCli
@@ -10,7 +11,7 @@ module Xapixctl
10
11
 
11
12
  desc "to-dir DIRECTORY", "Syncs resources in project to directory"
12
13
  long_desc <<-LONGDESC
13
- `xapixctl sync to-dir DIRECTORY` will export all resources of a given project and remove any additional resources from the directory.
14
+ `xapixctl sync to-dir DIRECTORY -p org/prj` will export all resources of a given project and remove any additional resources from the directory.
14
15
 
15
16
  With --no-credentials you can exclude all credentials from getting exported.
16
17
 
@@ -24,7 +25,7 @@ module Xapixctl
24
25
  \x5> $ xapixctl sync to-dir ./project_dir -p xapix/some-project --exclude-types=ApiPublishing ApiPublishingRole Credential
25
26
  LONGDESC
26
27
  def to_dir(dir)
27
- sync_path = SyncPath.new(dir, prj_connection.resource_types_for_export, excluded_types)
28
+ sync_path = SyncPath.new(shell, dir, prj_connection.resource_types_for_export, excluded_types)
28
29
 
29
30
  res_details = prj_connection.project_resource
30
31
  sync_path.write_file(generate_readme(res_details), 'README.md')
@@ -43,7 +44,7 @@ module Xapixctl
43
44
 
44
45
  desc "from-dir DIRECTORY", "Syncs resources in project from directory"
45
46
  long_desc <<-LONGDESC
46
- `xapixctl sync from-dir project dir` will import all resources into the given project from the directory and remove any additional resources which are not present in the directory.
47
+ `xapixctl sync from-dir DIRECTORY -p org/prj` will import all resources into the given project from the directory and remove any additional resources which are not present in the directory.
47
48
 
48
49
  With --no-credentials you can exclude all credentials from getting exported.
49
50
 
@@ -55,10 +56,10 @@ module Xapixctl
55
56
  \x5> $ xapixctl sync from-dir ./project_dir -p xapix/some-project --exclude-types=ApiPublishing ApiPublishingRole Credential
56
57
  LONGDESC
57
58
  def from_dir(dir)
58
- sync_path = SyncPath.new(dir, prj_connection.resource_types_for_export, excluded_types)
59
+ sync_path = SyncPath.new(shell, dir, prj_connection.resource_types_for_export, excluded_types)
59
60
 
60
61
  sync_path.load_resource('project') do |desc|
61
- puts "applying #{desc['kind']} #{desc.dig('metadata', 'id')} to #{prj_connection.project}"
62
+ say "applying #{desc['kind']} #{desc.dig('metadata', 'id')} to #{prj_connection.project}"
62
63
  desc['metadata']['id'] = prj_connection.project
63
64
  prj_connection.organization.apply(desc)
64
65
  end
@@ -68,7 +69,7 @@ module Xapixctl
68
69
  res_path = sync_path.resource_path(type)
69
70
  updated_resource_ids = []
70
71
  res_path.load_resources do |desc|
71
- puts "applying #{desc['kind']} #{desc.dig('metadata', 'id')}"
72
+ say "applying #{desc['kind']} #{desc.dig('metadata', 'id')}"
72
73
  updated_resource_ids += prj_connection.apply(desc)
73
74
  end
74
75
  outdated_resources[type] = prj_connection.resource_ids(type) - updated_resource_ids
@@ -76,16 +77,90 @@ module Xapixctl
76
77
 
77
78
  outdated_resources.each do |type, resource_ids|
78
79
  resource_ids.each do |resource_id|
79
- puts "removing #{type} #{resource_id}"
80
+ say "removing #{type} #{resource_id}"
80
81
  prj_connection.delete(type, resource_id)
81
82
  end
82
83
  end
83
84
  end
84
85
 
86
+ desc "diff DIRECTORY", "List resource which differ between project and directory"
87
+ long_desc <<-LONGDESC
88
+ `xapixctl sync diff DIRECTORY -p org/prj` will list the resources which are different between the given project and the given directory.
89
+
90
+ With --no-credentials you can exclude all credentials from getting exported.
91
+
92
+ With --exclude-types you can specify any resource types besides Project you'd like to exclude.
93
+
94
+ When only listing changed resources, the first character in a line indicates the status of the resource:
95
+ \x5 = - no changes
96
+ \x5 ~ - changed
97
+ \x5 ^ - in remote project
98
+ \x5 v - in directory
99
+
100
+ Examples:
101
+ \x5> $ xapixctl sync diff ./project_dir -p xapix/some-project
102
+ \x5> $ xapixctl sync diff ./project_dir -p xapix/some-project --no-credentials
103
+ \x5> $ xapixctl sync diff ./project_dir -p xapix/some-project --exclude-types=ApiPublishing ApiPublishingRole Credential
104
+ LONGDESC
105
+ option :details, desc: "Include detailed differences", type: :boolean, default: false
106
+ def diff(dir)
107
+ sync_path = SyncPath.new(shell, dir, prj_connection.resource_types_for_export, excluded_types)
108
+
109
+ sync_path.load_resource('project') do |desc|
110
+ desc['metadata']['id'] = prj_connection.project
111
+ res_details = prj_connection.project_resource
112
+ show_diff(desc, res_details)
113
+ end
114
+
115
+ sync_path.types_to_sync.each do |type|
116
+ res_path = sync_path.resource_path(type)
117
+ local_resource_ids = []
118
+ remote_resource_ids = prj_connection.resource_ids(type)
119
+ res_path.load_resources do |desc|
120
+ resource_id = desc['metadata']['id']
121
+ local_resource_ids << resource_id
122
+ if remote_resource_ids.include?(resource_id)
123
+ res_details = prj_connection.resource(type, desc['metadata']['id'])
124
+ show_diff(desc, res_details)
125
+ else
126
+ say "v #{type} #{resource_id}"
127
+ end
128
+ end
129
+ (remote_resource_ids - local_resource_ids).each do |resource_id|
130
+ say "^ #{type} #{resource_id}"
131
+ end
132
+ end
133
+ end
134
+
85
135
  private
86
136
 
137
+ def show_diff(local, remote)
138
+ kind, id = local['kind'], local['metadata']['id']
139
+ local, remote = local.slice('definition'), remote.slice('definition')
140
+ changed = local != remote
141
+ status = changed ? "~" : "="
142
+ say "#{status} #{kind} #{id}"
143
+ return unless changed && options[:details]
144
+ shell.indent do
145
+ Hashdiff.diff(local, remote).each do |change|
146
+ status = change[0].tr('+-', '^v')
147
+ key = change[1]
148
+ say "#{status} #{key}"
149
+ shell.indent do
150
+ case status
151
+ when "~" then say "^ #{change[3]}"; say "v #{change[2]}"
152
+ else say "#{status} #{change[2]}" if change[2]
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+
87
159
  class ResourcePath
88
- def initialize(path)
160
+ delegate :say, to: :@shell
161
+
162
+ def initialize(shell, path)
163
+ @shell = shell
89
164
  @path = path
90
165
  @resource_files = []
91
166
  end
@@ -98,7 +173,7 @@ module Xapixctl
98
173
  end
99
174
  file = @path.join(filename)
100
175
  file.write(content)
101
- puts "updated #{file}..."
176
+ say "updated #{file}..."
102
177
  file
103
178
  end
104
179
 
@@ -119,7 +194,7 @@ module Xapixctl
119
194
  def remove_outdated_resources
120
195
  (@path.glob('*.yaml') - @resource_files).each do |outdated_file|
121
196
  outdated_file.delete
122
- puts "removed #{outdated_file}"
197
+ say "removed #{outdated_file}"
123
198
  end
124
199
  end
125
200
  end
@@ -127,8 +202,8 @@ module Xapixctl
127
202
  class SyncPath < ResourcePath
128
203
  attr_reader :types_to_sync
129
204
 
130
- def initialize(dir, all_types, excluded_types)
131
- super(Pathname.new(dir))
205
+ def initialize(shell, dir, all_types, excluded_types)
206
+ super(shell, Pathname.new(dir))
132
207
  @all_types = all_types
133
208
  @excluded_types_file = @path.join('.excluded_types')
134
209
  @excluded_types = excluded_types || []
@@ -136,11 +211,11 @@ module Xapixctl
136
211
  @excluded_types &= @all_types
137
212
  @excluded_types.sort!
138
213
  @types_to_sync = @all_types - @excluded_types
139
- puts "Resource types excluded from sync: #{@excluded_types.join(', ')}" if @excluded_types.any?
214
+ say "Resource types excluded from sync: #{@excluded_types.join(', ')}" if @excluded_types.any?
140
215
  end
141
216
 
142
217
  def resource_path(type)
143
- ResourcePath.new(@path.join(type.underscore))
218
+ ResourcePath.new(@shell, @path.join(type.underscore))
144
219
  end
145
220
 
146
221
  def update_excluded_types_file
@@ -149,7 +224,7 @@ module Xapixctl
149
224
  end
150
225
 
151
226
  def excluded_types
152
- excluded = options[:exclude_types]
227
+ excluded = options[:exclude_types] || []
153
228
  excluded += ['Credential'] unless options[:credentials]
154
229
  excluded
155
230
  end
@@ -31,6 +31,10 @@ module Xapixctl
31
31
  connector_refs = import_swagger(File.basename(url.path), schema)
32
32
  say "\n== Onboarding Connectors", :bold
33
33
  connectors = match_connectors_to_action(connector_refs)
34
+ if connectors.empty?
35
+ warn "\nNo valid connectors for ML service detected, not building service."
36
+ exit 1
37
+ end
34
38
  say "\n== Building Service", :bold
35
39
  service_doc = build_service(schema.dig('info', 'title'), connectors)
36
40
  res = prj_connection.apply(service_doc)
@@ -81,7 +85,8 @@ module Xapixctl
81
85
  say "\n#{connector['kind']} #{connector.dig('definition', 'name')} -> "
82
86
  if action
83
87
  say "#{action} action"
84
- [action, update_connector_with_preview(connector)]
88
+ updated_connector = update_connector_with_preview(connector)
89
+ [action, updated_connector] if updated_connector
85
90
  else
86
91
  say "no action type detected, ignoring"
87
92
  nil
@@ -100,7 +105,7 @@ module Xapixctl
100
105
  res = prj_connection.accept_data_source_preview(connector.dig('metadata', 'id'))
101
106
  return res.dig('data_source', 'resource_description')
102
107
  end
103
- connector
108
+ nil
104
109
  end
105
110
 
106
111
  def extract_schema(data_sample)
@@ -206,10 +211,10 @@ module Xapixctl
206
211
  name: 'Result',
207
212
  inputs: ['predict'],
208
213
  formulas: [{
209
- ref: "#prediction.raw",
214
+ ref: "#prediction.percent",
210
215
  formula: "IF(.predict.status = 200, ROUND(100*coerce.to-float(.predict.body), 2))"
211
216
  }, {
212
- ref: "#prediction.percent",
217
+ ref: "#prediction.raw",
213
218
  formula: "IF(.predict.status = 200, coerce.to-float(.predict.body))"
214
219
  }, {
215
220
  ref: "#success",
@@ -219,7 +224,7 @@ module Xapixctl
219
224
  formula: "IF(.predict.status <> 200, 'Model not trained!')"
220
225
  }],
221
226
  parameter_sample: {
222
- "prediction" => { "percent" => 51, "raw" => 0.5112131 },
227
+ "prediction" => { "percent" => 51.12, "raw" => 0.5112131 },
223
228
  "success" => true,
224
229
  "error" => nil
225
230
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xapixctl
4
- VERSION = "1.2.2"
4
+ VERSION = "1.2.3"
5
5
  end
data/xapixctl.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.required_ruby_version = '>= 2.6'
30
30
 
31
31
  spec.add_dependency "activesupport", ">= 5.2.3", "< 6.0.0"
32
+ spec.add_dependency "hashdiff", ">= 1.0.1", "< 1.2.0"
32
33
  spec.add_dependency "rest-client", ">= 2.1.0", "< 3.0.0"
33
34
  spec.add_dependency "thor", ">= 1.0.0", "< 1.2.0"
34
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapixctl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Reinsch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 6.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: hashdiff
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 1.0.1
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 1.2.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.0.1
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 1.2.0
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: rest-client
35
55
  requirement: !ruby/object:Gem::Requirement