manageiq-api-common 0.1.0 → 1.0.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/manageiq/api/common/entitlement.rb +2 -0
- data/lib/manageiq/api/common/graphql.rb +29 -21
- data/lib/manageiq/api/common/graphql/generator.rb +13 -14
- data/lib/manageiq/api/common/graphql/templates/query_type.erb +1 -1
- data/lib/manageiq/api/common/open_api/generator.rb +1 -0
- data/lib/manageiq/api/common/request.rb +2 -1
- data/lib/manageiq/api/common/version.rb +1 -1
- data/spec/support/user_header_spec_helper.rb +6 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aa3a3a98c142ee7b4e8e62af8acd12e08a86d189bf74ad2eb902b454c9b20bb
|
4
|
+
data.tar.gz: eddfcfd2730f8a252a76482a72d213c2cdc18d887b3c6465d378bc8b9119a3f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f7a9bbfaf5e56fc3f625d35e8a1e0f466e65581980a88a72d052e5d5d2bd472b0f1de63380b84cf678e85b12b03713fbaf84adb2b6d23544947cecb79200f3b
|
7
|
+
data.tar.gz: 1e563fc8760b903a88f7dffcb7e3569400e84dc2b4f86a0e440c74b7bc191d4ced1b7162120401554d6bd1b7770ee9918b2f173636f6433975ab111c2a643876
|
@@ -13,6 +13,9 @@ module ManageIQ
|
|
13
13
|
module API
|
14
14
|
module Common
|
15
15
|
module GraphQL
|
16
|
+
module Api
|
17
|
+
end
|
18
|
+
|
16
19
|
def self.version(request)
|
17
20
|
/\/?\w+\/v(?<major>\d+)[x\.]?(?<minor>\d+)?\// =~ request.original_url
|
18
21
|
[major, minor].compact.join(".")
|
@@ -27,27 +30,6 @@ module ManageIQ
|
|
27
30
|
"content" => {
|
28
31
|
"application/json" => {
|
29
32
|
"schema" => {
|
30
|
-
"type" => "object",
|
31
|
-
"properties" => {
|
32
|
-
"query" => {
|
33
|
-
"type" => "string",
|
34
|
-
"description" => "The GraphQL query",
|
35
|
-
"default" => "{}"
|
36
|
-
},
|
37
|
-
"operationName" => {
|
38
|
-
"type" => "string",
|
39
|
-
"description" => "If the Query contains several named operations, the operationName controls which one should be executed",
|
40
|
-
"default" => ""
|
41
|
-
},
|
42
|
-
"variables" => {
|
43
|
-
"type" => "object",
|
44
|
-
"description" => "Optional Query variables",
|
45
|
-
"nullable" => true
|
46
|
-
}
|
47
|
-
},
|
48
|
-
"required" => [
|
49
|
-
"query"
|
50
|
-
]
|
51
33
|
}
|
52
34
|
}
|
53
35
|
},
|
@@ -69,6 +51,32 @@ module ManageIQ
|
|
69
51
|
}
|
70
52
|
end
|
71
53
|
|
54
|
+
def self.openapi_graphql_request
|
55
|
+
{
|
56
|
+
"type" => "object",
|
57
|
+
"properties" => {
|
58
|
+
"query" => {
|
59
|
+
"type" => "string",
|
60
|
+
"description" => "The GraphQL query",
|
61
|
+
"default" => "{}"
|
62
|
+
},
|
63
|
+
"operationName" => {
|
64
|
+
"type" => "string",
|
65
|
+
"description" => "If the Query contains several named operations, the operationName controls which one should be executed",
|
66
|
+
"default" => ""
|
67
|
+
},
|
68
|
+
"variables" => {
|
69
|
+
"type" => "object",
|
70
|
+
"description" => "Optional Query variables",
|
71
|
+
"nullable" => true
|
72
|
+
}
|
73
|
+
},
|
74
|
+
"required" => [
|
75
|
+
"query"
|
76
|
+
]
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
72
80
|
def self.openapi_graphql_response
|
73
81
|
{
|
74
82
|
"type" => "object",
|
@@ -41,16 +41,19 @@ module ManageIQ
|
|
41
41
|
|
42
42
|
def self.resource_associations(openapi_content, collection)
|
43
43
|
collection_is_associated = openapi_content["paths"].keys.any? do |path|
|
44
|
-
path.match("^/[^/]*/{id}/#{collection}$") &&
|
45
|
-
openapi_content.dig("paths", path, "get")
|
44
|
+
path.match?("^/[^/]*/{[[a-z]*_]*id}/#{collection}$") &&
|
45
|
+
openapi_content.dig("paths", path, "get").present?
|
46
46
|
end
|
47
47
|
collection_associations = []
|
48
48
|
openapi_content["paths"].keys.each do |path|
|
49
|
-
subcollection_match = path.match("^/#{collection}/{id}/([^/]*)$")
|
49
|
+
subcollection_match = path.match("^/#{collection}/{[[a-z]*_]*id}/([^/]*)$")
|
50
50
|
next unless subcollection_match
|
51
51
|
|
52
52
|
subcollection = subcollection_match[1]
|
53
|
-
next unless openapi_content
|
53
|
+
next unless openapi_content["paths"].keys.any? do |subcollection_path|
|
54
|
+
subcollection_path.match?("^/#{subcollection}/{[[a-z]*_]*id}$") &&
|
55
|
+
openapi_content.dig("paths", subcollection_path, "get").present?
|
56
|
+
end
|
54
57
|
|
55
58
|
collection_associations << subcollection
|
56
59
|
end
|
@@ -81,16 +84,10 @@ module ManageIQ
|
|
81
84
|
openapi_doc = ::ManageIQ::API::Common::OpenApi::Docs.instance[api_version]
|
82
85
|
openapi_content = openapi_doc.content
|
83
86
|
|
84
|
-
|
85
|
-
|
86
|
-
else
|
87
|
-
::Api.const_set(version_namespace, Module.new)
|
88
|
-
end
|
89
|
-
|
90
|
-
graphql_namespace = if api_namespace.const_defined?("GraphQL", false)
|
91
|
-
api_namespace.const_get("GraphQL")
|
87
|
+
graphql_namespace = if ::ManageIQ::API::Common::GraphQL::Api.const_defined?(version_namespace, false)
|
88
|
+
::ManageIQ::API::Common::GraphQL::Api.const_get(version_namespace)
|
92
89
|
else
|
93
|
-
|
90
|
+
::ManageIQ::API::Common::GraphQL::Api.const_set(version_namespace, Module.new)
|
94
91
|
end
|
95
92
|
|
96
93
|
return graphql_namespace.const_get("Schema") if graphql_namespace.const_defined?("Schema", false)
|
@@ -100,11 +97,13 @@ module ManageIQ
|
|
100
97
|
resources.each do |resource|
|
101
98
|
next unless openapi_content.dig("paths", resource, "get") # we only care for queries
|
102
99
|
|
103
|
-
rmatch = resource.match("^/(.*/)?([^/]*)/{id}$")
|
100
|
+
rmatch = resource.match("^/(.*/)?([^/]*)/{[[a-z]*_]*id}$")
|
104
101
|
next unless rmatch
|
105
102
|
|
106
103
|
collection = rmatch[2]
|
107
104
|
klass_name = collection.camelize.singularize
|
105
|
+
next if graphql_namespace.const_defined?("#{klass_name}Type", false)
|
106
|
+
|
108
107
|
_schema_name, this_schema = openapi_schema(openapi_doc, klass_name)
|
109
108
|
next if this_schema.nil? || this_schema["type"] != "object" || this_schema["properties"].nil?
|
110
109
|
|
@@ -9,7 +9,7 @@ QueryType = ::GraphQL::ObjectType.define do
|
|
9
9
|
klass_names = collection.to_s.camelize
|
10
10
|
klass_name = klass_names.singularize
|
11
11
|
model_class = klass_name.constantize
|
12
|
-
resource_type = "Api::#{version_namespace}
|
12
|
+
resource_type = "::ManageIQ::API::Common::GraphQL::Api::#{version_namespace}::#{klass_name}Type".constantize
|
13
13
|
|
14
14
|
collection_schema_overlay = ::ManageIQ::API::Common::GraphQL::Generator.collection_schema_overlay(schema_overlay, collection)
|
15
15
|
base_query = collection_schema_overlay["base_query"]
|
@@ -419,6 +419,7 @@ module ManageIQ
|
|
419
419
|
case verb
|
420
420
|
when "post"
|
421
421
|
if sub_path == "/graphql" && route.action == "query"
|
422
|
+
schemas["GraphQLRequest"] = ::ManageIQ::API::Common::GraphQL.openapi_graphql_request
|
422
423
|
schemas["GraphQLResponse"] = ::ManageIQ::API::Common::GraphQL.openapi_graphql_response
|
423
424
|
::ManageIQ::API::Common::GraphQL.openapi_graphql_description
|
424
425
|
else
|
@@ -10,7 +10,8 @@ module ManageIQ
|
|
10
10
|
class Request
|
11
11
|
REQUEST_ID_KEY = "x-rh-insights-request-id".freeze
|
12
12
|
IDENTITY_KEY = 'x-rh-identity'.freeze
|
13
|
-
|
13
|
+
PERSONA_KEY = 'x-rh-persona'.freeze
|
14
|
+
FORWARDABLE_HEADER_KEYS = [REQUEST_ID_KEY, IDENTITY_KEY, PERSONA_KEY].freeze
|
14
15
|
OPTIONAL_AUTH_PATHS = [
|
15
16
|
%r{\A/api/v[0-9]+(\.[0-9]+)?/openapi.json\z},
|
16
17
|
%r{\A/api/[^/]+/v[0-9]+(\.[0-9]+)?/openapi.json\z}
|
@@ -1,12 +1,18 @@
|
|
1
1
|
module UserHeaderSpecHelper
|
2
2
|
DEFAULT_USER = {
|
3
3
|
"entitlements" => {
|
4
|
+
"ansible" => {
|
5
|
+
"is_entitled" => true
|
6
|
+
},
|
4
7
|
"hybrid_cloud" => {
|
5
8
|
"is_entitled" => true
|
6
9
|
},
|
7
10
|
"insights" => {
|
8
11
|
"is_entitled" => true
|
9
12
|
},
|
13
|
+
"migrations" => {
|
14
|
+
"is_entitled" => true
|
15
|
+
},
|
10
16
|
"openshift" => {
|
11
17
|
"is_entitled" => true
|
12
18
|
},
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manageiq-api-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ManageIQ Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_tenant
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: 0.
|
137
|
+
version: 0.5.0
|
138
138
|
type: :runtime
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: 0.
|
144
|
+
version: 0.5.0
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: graphql
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|