graphql-armory 0.1.0.pre12 → 0.1.0.pre13

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/README.md +3 -3
  4. data/docs/versioning.md +540 -0
  5. data/lib/graphql/armory/authorization/audit/findings.rb +6 -1
  6. data/lib/graphql/armory/authorization/audit/overrides.rb +8 -2
  7. data/lib/graphql/armory/authorization/audit/payload_reuse.rb +9 -8
  8. data/lib/graphql/armory/authorization/definitions.rb +8 -92
  9. data/lib/graphql/armory/authorization.rb +3 -1
  10. data/lib/graphql/armory/definitions.rb +111 -0
  11. data/lib/graphql/armory/location.rb +101 -0
  12. data/lib/graphql/armory/version.rb +1 -1
  13. data/lib/graphql/armory/versioning/audit/command.rb +43 -0
  14. data/lib/graphql/armory/versioning/audit/own_checks.rb +139 -0
  15. data/lib/graphql/armory/versioning/audit/profiles.rb +123 -0
  16. data/lib/graphql/armory/versioning/audit/subscription_triggers.rb +98 -0
  17. data/lib/graphql/armory/versioning/audit.rb +559 -0
  18. data/lib/graphql/armory/versioning/controls.rb +403 -0
  19. data/lib/graphql/armory/versioning/decision.rb +89 -0
  20. data/lib/graphql/armory/versioning/deprecation.rb +95 -0
  21. data/lib/graphql/armory/versioning/diff/command.rb +49 -0
  22. data/lib/graphql/armory/versioning/diff.rb +349 -0
  23. data/lib/graphql/armory/versioning/dump/command.rb +46 -0
  24. data/lib/graphql/armory/versioning/dump.rb +107 -0
  25. data/lib/graphql/armory/versioning/gate.rb +140 -0
  26. data/lib/graphql/armory/versioning/integration.rb +903 -0
  27. data/lib/graphql/armory/versioning/lifecycle.rb +61 -0
  28. data/lib/graphql/armory/versioning/profiles.rb +122 -0
  29. data/lib/graphql/armory/versioning/rspec.rb +38 -0
  30. data/lib/graphql/armory/versioning/versions.rb +111 -0
  31. data/lib/graphql/armory/versioning/view.rb +61 -0
  32. data/lib/graphql/armory/versioning.rb +132 -0
  33. data/lib/graphql/armory.rb +1 -0
  34. data/lib/tasks/graphql_armory.rake +20 -0
  35. metadata +24 -2
  36. data/lib/graphql/armory/authorization/location.rb +0 -103
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GraphQL
4
- module Armory
5
- module Authorization
6
- # Where something of the app's schema was written, as "path:line", for the audit's report. graphql-ruby keeps no
7
- # location for a field or an argument, so the plugin's field and argument classes record the line that declared them,
8
- # and a type records the line of its `authorize`. Anything else falls back to the line of its class, and a type
9
- # graphql-ruby generated (a mutation's payload, a connection, an edge) to the class it was generated from.
10
- #
11
- # Limits: a schema built from SDL has no Ruby lines; a field declared by a helper method points to the helper; a class
12
- # reopened in several files gives the first one.
13
- module Location
14
- GRAPHQL_RUBY_PATH = "#{File.dirname(GraphQL::Schema.method(:from_definition).source_location.first)}/"
15
- ARMORY_PATH = "#{File.expand_path('..', __dir__)}/"
16
- # The directory the app started in, read once: a later `Dir.chdir` must not change the report's text. None when the
17
- # directory is gone, and then paths stay absolute.
18
- ROOT = begin
19
- "#{Dir.pwd}/"
20
- rescue SystemCallError
21
- nil
22
- end
23
-
24
- # The first line of the caller's stack outside graphql-ruby and this gem: where the app declared it. An `initialize`
25
- # is skipped too: an app's field or argument class, or another gem's module, may define one that calls super into
26
- # the plugin's, and its line is the same for every field.
27
- def self.declared
28
- found = caller_locations(2, 40)&.find do |location|
29
- path = location.absolute_path || location.path
30
- !path.start_with?("<", GRAPHQL_RUBY_PATH, ARMORY_PATH) && location.base_label != "initialize"
31
- end
32
- found && "#{found.absolute_path || found.path}:#{found.lineno}"
33
- end
34
-
35
- # "path:line" for a method, a field, an argument, a type or a class, relative to the directory the app started in
36
- # when it is inside it, or nil when there is no line to give.
37
- def self.of(thing)
38
- relative(absolute(thing))
39
- end
40
-
41
- def self.absolute(thing)
42
- case thing
43
- when nil then nil
44
- when String then thing
45
- when Method, UnboundMethod then join(thing.source_location)
46
- when GraphQL::Schema::Field, GraphQL::Schema::Argument
47
- (thing.armory_location if thing.respond_to?(:armory_location)) || absolute(thing.owner)
48
- when Module
49
- (thing.armory_rule_location if thing.respond_to?(:armory_rule_location)) || constant(thing) || generated_from(thing)
50
- end
51
- end
52
- private_class_method :absolute
53
-
54
- # graphql-ruby generates some types as classes with no constant: a mutation's payload, and a type's connection and
55
- # edge. They point to the class they were generated from, which was written somewhere.
56
- # Only an object type is followed: a schema also answers `mutation`, with its root type. A connection of connections
57
- # can lead back to itself, so each class is visited once, and the walk stops after a few steps.
58
- def self.generated_from(type)
59
- seen = {}.compare_by_identity
60
- while type.is_a?(Class) && type < GraphQL::Schema::Object && !seen.key?(type) && seen.size < 16
61
- seen[type] = true
62
- source = type.mutation if type.respond_to?(:mutation)
63
- source = nil unless source.is_a?(Class) && source < GraphQL::Schema::Resolver
64
- source ||= type.node_type if type.respond_to?(:node_type)
65
- return unless source.is_a?(Module)
66
-
67
- found = (source.armory_rule_location if source.respond_to?(:armory_rule_location)) || constant(source)
68
- return found if found
69
-
70
- type = source
71
- end
72
- rescue StandardError, NotImplementedError
73
- nil
74
- end
75
- private_class_method :generated_from
76
-
77
- # Only when the name leads back to this class: a class may answer another constant's name. A location is never worth
78
- # failing the audit, so a `name` that raises gives none.
79
- def self.constant(mod)
80
- name = mod.name
81
- return if !name.is_a?(String) || name.empty? || !Object.const_get(name).equal?(mod)
82
-
83
- join(Object.const_source_location(name))
84
- rescue StandardError, NotImplementedError
85
- nil
86
- end
87
- private_class_method :constant
88
-
89
- def self.join(pair)
90
- pair && !pair.empty? && pair.first ? "#{pair.first}:#{pair.last}" : nil
91
- end
92
- private_class_method :join
93
-
94
- def self.relative(location)
95
- return location if location.nil? || ROOT.nil?
96
-
97
- location.start_with?(ROOT) ? location.delete_prefix(ROOT) : location
98
- end
99
- private_class_method :relative
100
- end
101
- end
102
- end
103
- end