Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-25 18:07:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-25 18:07:58 +0300
commit0d8e625e4cd499162e6113dca4988b28f9faa9b6 (patch)
tree8744ab9fdba76e924f15272bba473521e39b8760 /lib/gitlab/web_ide
parentb5249f2d99206a72459bc5e2bf2aeb2f06ee36f3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/web_ide')
-rw-r--r--lib/gitlab/web_ide/config.rb44
-rw-r--r--lib/gitlab/web_ide/config/entry/global.rb29
-rw-r--r--lib/gitlab/web_ide/config/entry/terminal.rb75
3 files changed, 148 insertions, 0 deletions
diff --git a/lib/gitlab/web_ide/config.rb b/lib/gitlab/web_ide/config.rb
new file mode 100644
index 00000000000..3b1fa162b53
--- /dev/null
+++ b/lib/gitlab/web_ide/config.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module WebIde
+ #
+ # Base GitLab WebIde Configuration facade
+ #
+ class Config
+ ConfigError = Class.new(StandardError)
+
+ def initialize(config, opts = {})
+ @config = build_config(config, opts)
+
+ @global = Entry::Global.new(@config,
+ with_image_ports: true)
+ @global.compose!
+ rescue Gitlab::Config::Loader::FormatError => e
+ raise Config::ConfigError, e.message
+ end
+
+ def valid?
+ @global.valid?
+ end
+
+ def errors
+ @global.errors
+ end
+
+ def to_hash
+ @config
+ end
+
+ def terminal_value
+ @global.terminal_value
+ end
+
+ private
+
+ def build_config(config, opts = {})
+ Gitlab::Config::Loader::Yaml.new(config).load!
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/web_ide/config/entry/global.rb b/lib/gitlab/web_ide/config/entry/global.rb
new file mode 100644
index 00000000000..50c3f2d294f
--- /dev/null
+++ b/lib/gitlab/web_ide/config/entry/global.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module WebIde
+ class Config
+ module Entry
+ ##
+ # This class represents a global entry - root Entry for entire
+ # GitLab WebIde Configuration file.
+ #
+ class Global < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Configurable
+ include ::Gitlab::Config::Entry::Attributable
+
+ ALLOWED_KEYS = %i[terminal].freeze
+
+ validations do
+ validates :config, allowed_keys: ALLOWED_KEYS
+ end
+
+ entry :terminal, Entry::Terminal,
+ description: 'Configuration of the webide terminal.'
+
+ attributes :terminal
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/web_ide/config/entry/terminal.rb b/lib/gitlab/web_ide/config/entry/terminal.rb
new file mode 100644
index 00000000000..403e308d45b
--- /dev/null
+++ b/lib/gitlab/web_ide/config/entry/terminal.rb
@@ -0,0 +1,75 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module WebIde
+ class Config
+ module Entry
+ ##
+ # Entry that represents a concrete CI/CD job.
+ #
+ class Terminal < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Configurable
+ include ::Gitlab::Config::Entry::Attributable
+
+ # By default the build will finish in a few seconds, not giving the webide
+ # enough time to connect to the terminal. This default script provides
+ # those seconds blocking the build from finishing inmediately.
+ DEFAULT_SCRIPT = ['sleep 60'].freeze
+
+ ALLOWED_KEYS = %i[image services tags before_script script variables].freeze
+
+ validations do
+ validates :config, allowed_keys: ALLOWED_KEYS
+ validates :config, job_port_unique: { data: ->(record) { record.ports } }
+
+ with_options allow_nil: true do
+ validates :tags, array_of_strings: true
+ end
+ end
+
+ entry :before_script, ::Gitlab::Ci::Config::Entry::Script,
+ description: 'Global before script overridden in this job.'
+
+ entry :script, ::Gitlab::Ci::Config::Entry::Commands,
+ description: 'Commands that will be executed in this job.'
+
+ entry :image, ::Gitlab::Ci::Config::Entry::Image,
+ description: 'Image that will be used to execute this job.'
+
+ entry :services, ::Gitlab::Ci::Config::Entry::Services,
+ description: 'Services that will be used to execute this job.'
+
+ entry :variables, ::Gitlab::Ci::Config::Entry::Variables,
+ description: 'Environment variables available for this job.'
+
+ attributes :tags
+
+ def value
+ to_hash.compact
+ end
+
+ private
+
+ def to_hash
+ { tag_list: tags || [],
+ yaml_variables: yaml_variables,
+ options: {
+ image: image_value,
+ services: services_value,
+ before_script: before_script_value,
+ script: script_value || DEFAULT_SCRIPT
+ }.compact }
+ end
+
+ def yaml_variables
+ return unless variables_value
+
+ variables_value.map do |key, value|
+ { key: key.to_s, value: value, public: true }
+ end
+ end
+ end
+ end
+ end
+ end
+end