From 6a9007f3286bf910b26a0a79e3dddca608920b04 Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Mon, 14 Nov 2022 17:09:25 +0000 Subject: [PATCH] Add enterprise information to Metadata API Include a new key `"enterprise": true` to Metadata API in order to indicate whether GitLab instance is Enterprise Edition or not. Changelog: added --- app/graphql/types/metadata_type.rb | 2 ++ app/models/instance_metadata.rb | 5 +-- doc/api/graphql/reference/index.md | 1 + doc/api/metadata.md | 4 ++- lib/api/entities/metadata.rb | 1 + lib/api/metadata.rb | 1 + .../api/schemas/public_api/v4/metadata.json | 34 +++++++++++++++---- spec/models/instance_metadata_spec.rb | 3 +- .../api/graphql/metadata_query_spec.rb | 3 +- 9 files changed, 42 insertions(+), 12 deletions(-) diff --git a/app/graphql/types/metadata_type.rb b/app/graphql/types/metadata_type.rb index b00fcfd38ad33d..492cca365f3f82 100644 --- a/app/graphql/types/metadata_type.rb +++ b/app/graphql/types/metadata_type.rb @@ -6,6 +6,8 @@ class MetadataType < ::Types::BaseObject authorize :read_instance_metadata + field :enterprise, GraphQL::Types::Boolean, null: false, + description: 'Enterprise edition.' field :kas, ::Types::Metadata::KasType, null: false, description: 'Metadata about KAS.' field :revision, GraphQL::Types::String, null: false, diff --git a/app/models/instance_metadata.rb b/app/models/instance_metadata.rb index 6cac78178e03ce..47460c856713df 100644 --- a/app/models/instance_metadata.rb +++ b/app/models/instance_metadata.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true class InstanceMetadata - attr_reader :version, :revision, :kas + attr_reader :version, :revision, :kas, :enterprise - def initialize(version: Gitlab::VERSION, revision: Gitlab.revision) + def initialize(version: Gitlab::VERSION, revision: Gitlab.revision, enterprise: Gitlab.ee?) @version = version @revision = revision @kas = ::InstanceMetadata::Kas.new + @enterprise = enterprise end end diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index a8e48a952c0d78..b1f9d6ceae172f 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -15783,6 +15783,7 @@ four standard [pagination arguments](#connection-pagination-arguments): | Name | Type | Description | | ---- | ---- | ----------- | +| `enterprise` | [`Boolean!`](#boolean) | Enterprise edition. | | `kas` | [`Kas!`](#kas) | Metadata about KAS. | | `revision` | [`String!`](#string) | Revision. | | `version` | [`String!`](#string) | Version. | diff --git a/doc/api/metadata.md b/doc/api/metadata.md index 3803173b0b8c24..c3cbae70a54bae 100644 --- a/doc/api/metadata.md +++ b/doc/api/metadata.md @@ -24,6 +24,7 @@ Response body attributes: | `kas.enabled` | boolean | Indicates whether KAS is enabled. | | `kas.externalUrl` | string or null | URL used by the agents to communicate with KAS. It's `null` if `kas.enabled` is `false`. | | `kas.version` | string or null | Version of KAS. It's `null` if `kas.enabled` is `false`. | +| `enterprise` | boolean | Indicates whether GitLab instance is Enterprise Edition. | Example request: @@ -41,6 +42,7 @@ Example response: "enabled": true, "externalUrl": "grpc://gitlab.example.com:8150", "version": "15.0.0" - } + }, + "enterprise": true } ``` diff --git a/lib/api/entities/metadata.rb b/lib/api/entities/metadata.rb index 1e04b5c59821f2..7dfcad2ccabd3c 100644 --- a/lib/api/entities/metadata.rb +++ b/lib/api/entities/metadata.rb @@ -10,6 +10,7 @@ class Metadata < Grape::Entity expose :externalUrl, documentation: { type: 'string', example: 'grpc://gitlab.example.com:8150' } expose :version, documentation: { type: 'string', example: '15.0.0' } end + expose :enterprise, documentation: { type: 'boolean' } end end end diff --git a/lib/api/metadata.rb b/lib/api/metadata.rb index 2fdb97f98efcb4..788d9843c6392e 100644 --- a/lib/api/metadata.rb +++ b/lib/api/metadata.rb @@ -23,6 +23,7 @@ class Metadata < ::API::Base externalUrl version } + enterprise } } EOF diff --git a/spec/fixtures/api/schemas/public_api/v4/metadata.json b/spec/fixtures/api/schemas/public_api/v4/metadata.json index fd219b95df8ac6..f5a6aa8689006b 100644 --- a/spec/fixtures/api/schemas/public_api/v4/metadata.json +++ b/spec/fixtures/api/schemas/public_api/v4/metadata.json @@ -3,11 +3,16 @@ "required": [ "version", "revision", - "kas" + "kas", + "enterprise" ], "properties": { - "version": { "type": "string" }, - "revision": { "type": "string" }, + "version": { + "type": "string" + }, + "revision": { + "type": "string" + }, "kas": { "type": "object", "required": [ @@ -16,11 +21,26 @@ "version" ], "properties": { - "enabled": { "type": "boolean" }, - "externalUrl": { "type": ["string", "null"] }, - "version": { "type": ["string", "null"] } + "enabled": { + "type": "boolean" + }, + "externalUrl": { + "type": [ + "string", + "null" + ] + }, + "version": { + "type": [ + "string", + "null" + ] + } } + }, + "enterprise": { + "type": "boolean" } }, "additionalProperties": false -} +} \ No newline at end of file diff --git a/spec/models/instance_metadata_spec.rb b/spec/models/instance_metadata_spec.rb index 5fc073c392dc85..46fd165e065378 100644 --- a/spec/models/instance_metadata_spec.rb +++ b/spec/models/instance_metadata_spec.rb @@ -9,7 +9,8 @@ expect(subject).to have_attributes( version: Gitlab::VERSION, revision: Gitlab.revision, - kas: kind_of(::InstanceMetadata::Kas) + kas: kind_of(::InstanceMetadata::Kas), + enterprise: Gitlab.ee? ) end end diff --git a/spec/requests/api/graphql/metadata_query_spec.rb b/spec/requests/api/graphql/metadata_query_spec.rb index 840bd7c018c16b..435e1b5b59658e 100644 --- a/spec/requests/api/graphql/metadata_query_spec.rb +++ b/spec/requests/api/graphql/metadata_query_spec.rb @@ -17,7 +17,8 @@ 'enabled' => Gitlab::Kas.enabled?, 'version' => expected_kas_version, 'externalUrl' => expected_kas_external_url - } + }, + 'enterprise' => Gitlab.ee? } } end -- GitLab