etna 0.1.12 → 0.1.18

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/bin/etna +63 -0
  3. data/etna.completion +926 -0
  4. data/etna_app.completion +133 -0
  5. data/ext/completions/extconf.rb +20 -0
  6. data/lib/commands.rb +368 -0
  7. data/lib/etna.rb +6 -0
  8. data/lib/etna/application.rb +46 -22
  9. data/lib/etna/client.rb +82 -48
  10. data/lib/etna/clients.rb +4 -0
  11. data/lib/etna/clients/enum.rb +9 -0
  12. data/lib/etna/clients/janus.rb +2 -0
  13. data/lib/etna/clients/janus/client.rb +73 -0
  14. data/lib/etna/clients/janus/models.rb +78 -0
  15. data/lib/etna/clients/magma.rb +4 -0
  16. data/lib/etna/clients/magma/client.rb +80 -0
  17. data/lib/etna/clients/magma/formatting.rb +1 -0
  18. data/lib/etna/clients/magma/formatting/models_csv.rb +345 -0
  19. data/lib/etna/clients/magma/models.rb +579 -0
  20. data/lib/etna/clients/magma/workflows.rb +10 -0
  21. data/lib/etna/clients/magma/workflows/add_project_models_workflow.rb +78 -0
  22. data/lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb +62 -0
  23. data/lib/etna/clients/magma/workflows/create_project_workflow.rb +117 -0
  24. data/lib/etna/clients/magma/workflows/crud_workflow.rb +85 -0
  25. data/lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb +44 -0
  26. data/lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb +68 -0
  27. data/lib/etna/clients/magma/workflows/file_linking_workflow.rb +115 -0
  28. data/lib/etna/clients/magma/workflows/json_converters.rb +81 -0
  29. data/lib/etna/clients/magma/workflows/json_validators.rb +447 -0
  30. data/lib/etna/clients/magma/workflows/model_synchronization_workflow.rb +306 -0
  31. data/lib/etna/clients/magma/workflows/record_synchronization_workflow.rb +63 -0
  32. data/lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb +178 -0
  33. data/lib/etna/clients/metis.rb +3 -0
  34. data/lib/etna/clients/metis/client.rb +239 -0
  35. data/lib/etna/clients/metis/models.rb +313 -0
  36. data/lib/etna/clients/metis/workflows.rb +2 -0
  37. data/lib/etna/clients/metis/workflows/metis_download_workflow.rb +37 -0
  38. data/lib/etna/clients/metis/workflows/metis_upload_workflow.rb +137 -0
  39. data/lib/etna/clients/polyphemus.rb +3 -0
  40. data/lib/etna/clients/polyphemus/client.rb +33 -0
  41. data/lib/etna/clients/polyphemus/models.rb +68 -0
  42. data/lib/etna/clients/polyphemus/workflows.rb +1 -0
  43. data/lib/etna/clients/polyphemus/workflows/set_configuration_workflow.rb +47 -0
  44. data/lib/etna/command.rb +243 -5
  45. data/lib/etna/controller.rb +4 -0
  46. data/lib/etna/directed_graph.rb +56 -0
  47. data/lib/etna/environment_scoped.rb +19 -0
  48. data/lib/etna/generate_autocompletion_script.rb +130 -0
  49. data/lib/etna/hmac.rb +1 -0
  50. data/lib/etna/json_serializable_struct.rb +37 -0
  51. data/lib/etna/logger.rb +15 -1
  52. data/lib/etna/multipart_serializable_nested_hash.rb +50 -0
  53. data/lib/etna/parse_body.rb +1 -1
  54. data/lib/etna/route.rb +1 -1
  55. data/lib/etna/server.rb +3 -0
  56. data/lib/etna/spec/vcr.rb +98 -0
  57. data/lib/etna/templates/attribute_actions_template.json +43 -0
  58. data/lib/etna/test_auth.rb +4 -2
  59. data/lib/etna/user.rb +11 -1
  60. data/lib/helpers.rb +81 -0
  61. metadata +70 -7
@@ -0,0 +1,43 @@
1
+ // Make sure to remove all comments before using -- JSON doesn't allow comments!
2
+ [
3
+ // Attribute actions can be "add_attribute", "update_attribute", "rename_attribute", or "add_link".
4
+ // These are all executed at the same time -- so you can't "update" an attribute that you "add"
5
+ // in the same file -- everything must already exist on the server."
6
+ {
7
+ "action_name": "add_attribute",
8
+ "model_name": "assay_name", // Each action must include a model_name that it applies to.
9
+ "attribute_type": "string", // When adding, you must include attribute_type, attribute_name, desc, and display_name.
10
+ "attribute_name": "notes",
11
+ "display_name": "Notes",
12
+ "desc": "for notes that you have."
13
+ },
14
+ {
15
+ "action_name": "update_attribute",
16
+ "model_name": "document",
17
+ "attribute_name": "version", // When updating, you must include model_name and attribute_name, but any additional values are optional.
18
+ "read_only": true
19
+ },
20
+ {
21
+ "action_name": "rename_attribute",
22
+ "model_name": "assay_name",
23
+ "attribute_name": "vendor",
24
+ "new_attribute_name": "e_vendor" // When renaming an attribute, you need to include a "new_attribute_name" value.
25
+ },
26
+ {
27
+ // Links require two hashes inside of a "links" attribute.
28
+ "action_name": "add_link",
29
+ "links": [
30
+ {
31
+ "model_name": "assay_name",
32
+ "attribute_name": "document",
33
+ "attribute_type": "link" // One link must be of type "link". This has a one-to-one relationship with the other model.
34
+ // In this case, each assay_name has one document record, but document records can point to zero-or-more assay_name records.
35
+ },
36
+ {
37
+ "model_name": "document",
38
+ "attribute_name": "assay_name",
39
+ "attribute_type": "collection" // The other link must be of type "collection". This is a one-to-many relationship with the other model.
40
+ }
41
+ ]
42
+ }
43
+ ]
@@ -43,7 +43,9 @@ module Etna
43
43
  end
44
44
 
45
45
  def approve_hmac(request)
46
- hmac_signature = etna_param(request, :signature) || 'invalid'
46
+ hmac_signature = etna_param(request, :signature)
47
+
48
+ return false unless hmac_signature
47
49
 
48
50
  headers = (etna_param(request, :headers)&.split(/,/) || []).map do |header|
49
51
  [ header.to_sym, etna_param(request, header) ]
@@ -74,7 +76,7 @@ module Etna
74
76
  end
75
77
  class TestHmac < Hmac
76
78
  def valid?
77
- @test_signature == 'valid'
79
+ @test_signature == 'valid' || super
78
80
  end
79
81
  end
80
82
  end
@@ -7,7 +7,9 @@ module Etna
7
7
  }
8
8
 
9
9
  def initialize params, token=nil
10
- @first, @last, @email, @encoded_permissions = params.values_at(:first, :last, :email, :perm)
10
+ @first, @last, @email, @encoded_permissions, encoded_flags = params.values_at(:first, :last, :email, :perm, :flags)
11
+
12
+ @flags = encoded_flags&.split(/;/) || []
11
13
  @token = token unless !token
12
14
  raise ArgumentError, "No email given!" unless @email
13
15
  end
@@ -30,6 +32,10 @@ module Etna
30
32
  end.inject([],:+).to_h
31
33
  end
32
34
 
35
+ def has_flag?(flag)
36
+ @flags.include?(flag)
37
+ end
38
+
33
39
  def name
34
40
  "#{first} #{last}"
35
41
  end
@@ -75,5 +81,9 @@ module Etna
75
81
  def is_admin? project
76
82
  is_superuser? || has_roles(project, :admin)
77
83
  end
84
+
85
+ def active? project=nil
86
+ permissions.keys.length > 0
87
+ end
78
88
  end
79
89
  end
@@ -0,0 +1,81 @@
1
+ require_relative './etna/clients'
2
+ require_relative './etna/environment_scoped'
3
+
4
+ module WithEtnaClients
5
+ def environment
6
+ EtnaApp.instance.environment
7
+ end
8
+
9
+ def token
10
+ env_token = ENV['TOKEN']
11
+ if !env_token
12
+ puts "No environment variable TOKEN is set. You should set your token with `export TOKEN=<your.janus.token>` before running."
13
+ redirect = EtnaApp.instance.config(:auth_redirect)
14
+
15
+ if redirect.nil? && EtnaApp.instance.environment == :production
16
+ redirect = 'https://janus.ucsf.edu/'
17
+ end
18
+
19
+ unless redirect.nil?
20
+ puts "Open your browser to #{redirect} to complete login and copy your token."
21
+ end
22
+
23
+ exit
24
+ end
25
+
26
+ env_token
27
+ end
28
+
29
+ def magma_client
30
+ @magma_client ||= Etna::Clients::Magma.new(
31
+ token: token,
32
+ ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
33
+ # Persistent connections cause problem with magma restarts, until we can fix that we should force them
34
+ # to close + reopen each request.
35
+ persistent: false,
36
+ **EtnaApp.instance.config(:magma, environment) || {})
37
+ end
38
+
39
+ def metis_client
40
+ @metis_client ||= Etna::Clients::Metis.new(
41
+ token: token,
42
+ ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
43
+ **EtnaApp.instance.config(:metis, environment) || {})
44
+ end
45
+
46
+ def janus_client
47
+ @janus_client ||= Etna::Clients::Janus.new(
48
+ token: token,
49
+ ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
50
+ **EtnaApp.instance.config(:janus, environment) || {})
51
+ end
52
+
53
+ def polyphemus_client
54
+ @polyphemus_client ||= Etna::Clients::Polyphemus.new(
55
+ token: token,
56
+ ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
57
+ **EtnaApp.instance.config(:polyphemus, environment) || {})
58
+ end
59
+ end
60
+
61
+ module WithLogger
62
+ def logger
63
+ EtnaApp.instance.logger
64
+ end
65
+ end
66
+
67
+ module StrongConfirmation
68
+ def confirm
69
+ puts "Confirm Y/n:"
70
+ input = STDIN.gets.chomp
71
+ if input != "Y"
72
+ return false
73
+ end
74
+
75
+ true
76
+ end
77
+ end
78
+
79
+ WithEtnaClientsByEnvironment = EnvironmentScoped.new do
80
+ include WithEtnaClients
81
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saurabh Asthana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-04 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -66,37 +66,101 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rollbar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: See summary
70
84
  email: Saurabh.Asthana@ucsf.edu
71
- executables: []
72
- extensions: []
85
+ executables:
86
+ - etna
87
+ extensions:
88
+ - ext/completions/extconf.rb
73
89
  extra_rdoc_files: []
74
90
  files:
91
+ - bin/etna
92
+ - etna.completion
93
+ - etna_app.completion
94
+ - ext/completions/extconf.rb
95
+ - lib/commands.rb
75
96
  - lib/etna.rb
76
97
  - lib/etna/application.rb
77
98
  - lib/etna/auth.rb
78
99
  - lib/etna/client.rb
100
+ - lib/etna/clients.rb
101
+ - lib/etna/clients/enum.rb
102
+ - lib/etna/clients/janus.rb
103
+ - lib/etna/clients/janus/client.rb
104
+ - lib/etna/clients/janus/models.rb
105
+ - lib/etna/clients/magma.rb
106
+ - lib/etna/clients/magma/client.rb
107
+ - lib/etna/clients/magma/formatting.rb
108
+ - lib/etna/clients/magma/formatting/models_csv.rb
109
+ - lib/etna/clients/magma/models.rb
110
+ - lib/etna/clients/magma/workflows.rb
111
+ - lib/etna/clients/magma/workflows/add_project_models_workflow.rb
112
+ - lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb
113
+ - lib/etna/clients/magma/workflows/create_project_workflow.rb
114
+ - lib/etna/clients/magma/workflows/crud_workflow.rb
115
+ - lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb
116
+ - lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb
117
+ - lib/etna/clients/magma/workflows/file_linking_workflow.rb
118
+ - lib/etna/clients/magma/workflows/json_converters.rb
119
+ - lib/etna/clients/magma/workflows/json_validators.rb
120
+ - lib/etna/clients/magma/workflows/model_synchronization_workflow.rb
121
+ - lib/etna/clients/magma/workflows/record_synchronization_workflow.rb
122
+ - lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb
123
+ - lib/etna/clients/metis.rb
124
+ - lib/etna/clients/metis/client.rb
125
+ - lib/etna/clients/metis/models.rb
126
+ - lib/etna/clients/metis/workflows.rb
127
+ - lib/etna/clients/metis/workflows/metis_download_workflow.rb
128
+ - lib/etna/clients/metis/workflows/metis_upload_workflow.rb
129
+ - lib/etna/clients/polyphemus.rb
130
+ - lib/etna/clients/polyphemus/client.rb
131
+ - lib/etna/clients/polyphemus/models.rb
132
+ - lib/etna/clients/polyphemus/workflows.rb
133
+ - lib/etna/clients/polyphemus/workflows/set_configuration_workflow.rb
79
134
  - lib/etna/command.rb
80
135
  - lib/etna/controller.rb
81
136
  - lib/etna/cross_origin.rb
82
137
  - lib/etna/describe_routes.rb
138
+ - lib/etna/directed_graph.rb
139
+ - lib/etna/environment_scoped.rb
83
140
  - lib/etna/errors.rb
84
141
  - lib/etna/ext.rb
142
+ - lib/etna/generate_autocompletion_script.rb
85
143
  - lib/etna/hmac.rb
144
+ - lib/etna/json_serializable_struct.rb
86
145
  - lib/etna/logger.rb
146
+ - lib/etna/multipart_serializable_nested_hash.rb
87
147
  - lib/etna/parse_body.rb
88
148
  - lib/etna/route.rb
89
149
  - lib/etna/server.rb
90
150
  - lib/etna/sign_service.rb
91
151
  - lib/etna/spec.rb
92
152
  - lib/etna/spec/auth.rb
153
+ - lib/etna/spec/vcr.rb
93
154
  - lib/etna/symbolize_params.rb
155
+ - lib/etna/templates/attribute_actions_template.json
94
156
  - lib/etna/test_auth.rb
95
157
  - lib/etna/user.rb
158
+ - lib/helpers.rb
96
159
  homepage: http://github.com/mountetna/etna
97
160
  licenses: []
98
161
  metadata: {}
99
- post_install_message:
162
+ post_install_message: "\n\n\e[1;31mAdd 'source ~/etna.completion' to your .bashrc
163
+ to get etna command line completions!\e[0m\n\n"
100
164
  rdoc_options: []
101
165
  require_paths:
102
166
  - lib
@@ -111,8 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
175
  - !ruby/object:Gem::Version
112
176
  version: '0'
113
177
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.7.6.2
178
+ rubygems_version: 3.1.2
116
179
  signing_key:
117
180
  specification_version: 4
118
181
  summary: Base classes for Mount Etna applications