#!/usr/bin/env ruby-2.5

require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_net'

#
# GitLab shell check task
#

print "Check GitLab API access: "
begin
  resp = GitlabNet.new.check

  if resp.code != "200"
    abort "FAILED. code: #{resp.code}"
  end

  puts 'OK'

  check_values = JSON.parse(resp.body)

  print 'Redis available via internal API: '
  if check_values['redis']
    puts 'OK'
  else
    abort 'FAILED'
  end
rescue GitlabNet::ApiUnreachableError
  abort "FAILED: Failed to connect to internal API"
end

puts "\n"
