foobara-remote-imports 0.0.11 → 0.0.12

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: 6618b6975d35dbe7af376615f41d0d751643beaa41affc79233790a312f5ec96
4
- data.tar.gz: 6591a7dc132e364238b76757236e95fc57cee6b8014653ed023df3f012e69303
3
+ metadata.gz: 2b9b83098b7e947b7591062fdf5068efdb7386672a84600eb35f1ad4f8752a51
4
+ data.tar.gz: db98220fe18dd9d65e4ac4ccc1757c96a897431dff6f6d6cafecab37d853997a
5
5
  SHA512:
6
- metadata.gz: df41f1c9e935122256b3da5411705de12a1e63e881959047534e2ec9a385256e365e01be11a1fe137b5cab1385eb2abdc9bf12bf7ba2d94641a390ef99d1e177
7
- data.tar.gz: 31d8ea034d85432104cbafd7f04f9ac8e94f12854dd157864d8142c1cc3340afadcffb8c0e5c83eef18c5d32708adbf3afcce883227160836a8730e3ba9e71f7
6
+ metadata.gz: 3a359c8a0c630e1e04fe4c2bd6a317c98b1f6f135001494153a1883e13189d1c9e064eb7d6172c6e21029c69c571eb918f4a47cc77eda32bd2d2193f90a3add3
7
+ data.tar.gz: c557900b44619844163796640115a0d58ce4849a6c471b0351d44eb31c8503abe9b0a03e6b2480cfe51d3971107bea88299171d9b3b0c93779aaaa341ff84743
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.12] - 2025-05-05
2
+
3
+ - Add AuthenticatedRemoteCommand
4
+
1
5
  ## [0.0.11] - 2025-04-19
2
6
 
3
7
  - Facilitate overriding methods in RemoteCommand
@@ -0,0 +1,30 @@
1
+ require_relative "remote_command"
2
+
3
+ module Foobara
4
+ class AuthenticatedRemoteCommand < RemoteCommand
5
+ class << self
6
+ attr_accessor :authenticate_with_header_name, :authenticate_with_header_value
7
+
8
+ def subclass(authenticate_with_header:, **opts)
9
+ super(base: AuthenticatedRemoteCommand, **opts).tap do |klass|
10
+ klass.authenticate_with_header_name = authenticate_with_header[:name]
11
+ klass.authenticate_with_header_value = authenticate_with_header[:value]
12
+ end
13
+ end
14
+ end
15
+
16
+ def build_request_headers
17
+ value = self.class.authenticate_with_header_value
18
+
19
+ if value.is_a?(Proc)
20
+ value = if value.lambda? && value.arity == 0
21
+ value.call
22
+ else
23
+ value.call(self)
24
+ end
25
+ end
26
+
27
+ self.request_headers = super.merge(self.class.authenticate_with_header_name => value)
28
+ end
29
+ end
30
+ end
@@ -7,7 +7,6 @@ module Foobara
7
7
  class RemoteCommand < Command
8
8
  class UnexpectedError < StandardError; end
9
9
 
10
- # TODO: fill this out
11
10
  class << self
12
11
  attr_accessor :url_base
13
12
 
@@ -18,10 +17,9 @@ module Foobara
18
17
  result:,
19
18
  possible_errors:,
20
19
  name:,
21
- base: self
20
+ base: RemoteCommand
22
21
  )
23
22
  klass = Util.make_class_p(name, base)
24
-
25
23
  klass.url_base = url_base
26
24
  klass.description description
27
25
  klass.inputs inputs
@@ -72,12 +70,12 @@ module Foobara
72
70
 
73
71
  # Handling transactions across systems is too much to attempt for now and maybe ever.
74
72
  # So let's noop several of these
75
- %i[
76
- auto_detect_current_transactions
77
- relevant_entity_classes
78
- open_transaction
79
- rollback_transaction
80
- commit_transaction
73
+ [
74
+ :auto_detect_current_transactions,
75
+ :relevant_entity_classes,
76
+ :open_transaction,
77
+ :rollback_transaction,
78
+ :commit_transaction
81
79
  ].each do |method_name|
82
80
  define_method(method_name) { nil }
83
81
  end
@@ -9,7 +9,11 @@ module Foobara
9
9
  include ImportBase
10
10
 
11
11
  add_inputs do
12
- base_command_class Class, default: RemoteCommand
12
+ base_command_class :duck, :allow_nil
13
+ authenticate_with_header :allow_nil do
14
+ name :string, :required, "The header name to set"
15
+ value :duck, :required, "A string value or proc that returns a string value"
16
+ end
13
17
  end
14
18
 
15
19
  depends_on ImportDomain, ImportType, ImportError
@@ -35,7 +39,7 @@ module Foobara
35
39
  already_imported:
36
40
  )
37
41
 
38
- Util.make_class_p(manifest_to_import.reference, base_command_class)
42
+ Util.make_class_p(manifest_to_import.reference, determine_base_command_class)
39
43
 
40
44
  manifest_to_import.types_depended_on.each do |type|
41
45
  run_subcommand!(
@@ -73,15 +77,32 @@ module Foobara
73
77
  def build_command
74
78
  url_base = root_manifest.metadata["url"].gsub(/\/manifest$/, "")
75
79
 
76
- RemoteCommand.subclass(
80
+ subclass_args = {
77
81
  url_base:,
78
82
  description: manifest_to_import.description,
79
83
  inputs: manifest_to_import.inputs_type.relevant_manifest,
80
84
  result: manifest_to_import.result_type.relevant_manifest,
81
85
  possible_errors: manifest_to_import.possible_errors,
82
86
  name: manifest_to_import.reference,
83
- base: base_command_class
84
- )
87
+ base: determine_base_command_class
88
+ }
89
+
90
+ if determine_base_command_class == AuthenticatedRemoteCommand
91
+ subclass_args.merge!(authenticate_with_header:)
92
+ end
93
+
94
+ determine_base_command_class.subclass(**subclass_args)
95
+ end
96
+
97
+ def determine_base_command_class
98
+ @determine_base_command_class ||= if base_command_class
99
+ base_command_class
100
+ elsif manifest_to_import.requires_authentication? &&
101
+ authenticate_with_header
102
+ AuthenticatedRemoteCommand
103
+ else
104
+ RemoteCommand
105
+ end
85
106
  end
86
107
  end
87
108
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-remote-imports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2025-05-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -34,6 +34,7 @@ files:
34
34
  - LICENSE.txt
35
35
  - README.md
36
36
  - lib/foobara/remote_imports.rb
37
+ - src/foobara/authenticated_remote_command.rb
37
38
  - src/foobara/remote_command.rb
38
39
  - src/foobara/remote_imports/already_imported.rb
39
40
  - src/foobara/remote_imports/import_base.rb
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  - !ruby/object:Gem::Version
65
66
  version: '0'
66
67
  requirements: []
67
- rubygems_version: 3.6.7
68
+ rubygems_version: 3.6.2
68
69
  specification_version: 4
69
70
  summary: Used to import commands/entities/whatever from another system into this one.
70
71
  test_files: []