As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 89bd72d1 authored by Ash McKenzie's avatar Ash McKenzie
Browse files

Merge branch '173-remove-unneeded-binaries' into 'master'

Remove dead Ruby code and unused binaries

See merge request gitlab-org/gitlab-shell!346
parents c88d80fe 8cf3f4c7
No related branches found
No related tags found
No related merge requests found
Showing
with 22 additions and 840 deletions
Loading
Loading
@@ -4,7 +4,6 @@ tmp/*
*.log
/*.log*
authorized_keys.lock
coverage/
.gitlab_shell_secret
.bundle
tags
Loading
Loading
@@ -15,7 +14,4 @@ hooks/*.d
/bin/gitlab-shell
/bin/gitlab-shell-authorized-keys-check
/bin/gitlab-shell-authorized-principals-check
/bin/gitaly-upload-pack
/bin/gitaly-receive-pack
/bin/gitaly-upload-archive
/bin/check
image: "ruby:2.3"
variables:
INSTALL_BUNDLER_VERSION: "~> 2.0.1"
before_script:
- export PATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
- gem install --force --bindir /usr/local/bin bundler -v "$INSTALL_BUNDLER_VERSION"
- cp config.yml.example config.yml
- bundle install
.rspec_definition: &rspec_definition
script:
# Skip the experimental Golang wrapper in the Ruby specs. These are now
# primarily regression tests for particular versions of Ruby.
#
# The full rspec suite is also run against each suppported golang version
- make test_ruby
rspec:
<<: *rspec_definition
except:
- tags
verify_ruby:
script:
- make verify_ruby
except:
- tags
#ruby 2.6
rspec:ruby2.6:
image: ruby:2.6
variables:
INSTALL_BUNDLER_VERSION: ~> 1.17.3
<<: *rspec_definition
except:
- tags
#ruby 2.2
rspec:ruby2.2:
image: ruby:2.2
variables:
INSTALL_BUNDLER_VERSION: ~> 1.17.3
<<: *rspec_definition
except:
- tags
#ruby 2.1
rspec:ruby2.1:
image: ruby:2.1
variables:
INSTALL_BUNDLER_VERSION: ~> 1.17.3
<<: *rspec_definition
except:
- tags
.go: &go_definition
.test: &test_definition
before_script:
# Set up the environment to run integration tests (still written in Ruby)
- apt-get update -qq && apt-get install -y ruby ruby-dev
- ruby -v
- export PATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
- gem update --system
- gem install --bindir /usr/local/bin bundler
- cp config.yml.example config.yml
- gem install --force --bindir /usr/local/bin bundler -v 1.17.2
- bundle install
script:
# Now set up to run the Golang tests
- make build
- cp config.yml.example config.yml
- go version
- which go
- make build verify_golang test_golang
# Run the full Ruby test suite in the "go" tests. As more functionality is
# migrated into these tests and out of Ruby, the amount of work here will
# reduce
- make test_ruby
script:
- make verify test
go:1.11:
<<: *go_definition
<<: *test_definition
image: golang:1.11
go:1.12:
<<: *go_definition
<<: *test_definition
image: golang:1.12
go:1.13:
<<: *go_definition
<<: *test_definition
image: golang:1.13
codequality:
Loading
Loading
source 'https://rubygems.org'
group :development, :test do
gem 'listen', '~> 0.5.0'
gem 'pry', '~> 0.12.2'
gem 'rspec', '~> 3.8.0'
gem 'rspec-parameterized', '~> 0.4.0'
gem 'rubocop', '0.49.1', require: false
gem 'simplecov', '~> 0.9.0', require: false
gem 'vcr', '~> 4.0.0'
gem 'webmock', '~> 3.4.0'
end
GEM
remote: https://rubygems.org/
specs:
abstract_type (0.0.7)
adamantium (0.2.0)
ice_nine (~> 0.11.0)
memoizable (~> 0.4.0)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
coderay (1.1.2)
concord (0.1.5)
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
crack (0.4.3)
safe_yaml (~> 1.0.0)
debug_inspector (0.0.3)
diff-lcs (1.3)
docile (1.1.5)
equalizer (0.0.11)
hashdiff (0.3.7)
ice_nine (0.11.2)
listen (0.5.3)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
method_source (0.9.2)
multi_json (1.13.1)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
proc_to_ast (0.1.0)
coderay
parser
unparser
procto (0.0.3)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.3)
rainbow (2.2.2)
rake
rake (12.3.3)
Loading
Loading
@@ -55,12 +22,6 @@ GEM
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-parameterized (0.4.0)
binding_of_caller
parser
proc_to_ast
rspec (>= 2.13, < 4)
unparser
rspec-support (3.8.0)
rubocop (0.49.1)
parallel (~> 1.10)
Loading
Loading
@@ -70,40 +31,14 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.9.0)
simplecov-html (0.9.0)
thread_safe (0.3.6)
unicode-display_width (1.4.0)
unparser (0.2.8)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
concord (~> 0.1.5)
diff-lcs (~> 1.3)
equalizer (~> 0.0.9)
parser (>= 2.3.1.2, < 2.6)
procto (~> 0.0.2)
vcr (4.0.0)
webmock (3.4.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
PLATFORMS
ruby
DEPENDENCIES
listen (~> 0.5.0)
pry (~> 0.12.2)
rspec (~> 3.8.0)
rspec-parameterized (~> 0.4.0)
rubocop (= 0.49.1)
simplecov (~> 0.9.0)
vcr (~> 4.0.0)
webmock (~> 3.4.0)
BUNDLED WITH
1.16.3
1.17.2
Loading
Loading
@@ -14,15 +14,9 @@ verify_golang:
test: test_ruby test_golang
# The Ruby tests are now all integration specs that test the Go implementation.
test_ruby:
# bin/gitlab-shell, bin/gitlab-shell-authorized-keys-check and
# bin/gitlab-shell-authorized-principals-check must exist and need to be
# the Ruby version for rspec to be able to test.
cp bin/gitlab-shell-ruby bin/gitlab-shell
cp bin/gitlab-shell-authorized-keys-check-ruby bin/gitlab-shell-authorized-keys-check
cp bin/gitlab-shell-authorized-principals-check-ruby bin/gitlab-shell-authorized-principals-check
bundle exec rspec --color --tag '~go' --format d spec
rm -f bin/gitlab-shell bin/gitlab-shell-authorized-keys-check bin/gitlab-shell-authorized-principals-check
bundle exec rspec --color --format d spec
test_golang:
support/go-test
Loading
Loading
Loading
Loading
@@ -45,26 +45,10 @@ plan](https://gitlab.com/gitlab-org/gitaly/issues/1226#note_126519133).
## Requirements
**GitLab shell will always use your system ruby (normally located at /usr/bin/ruby) and will not use the ruby your installed with a ruby version manager (such as RVM).**
It requires ruby 2.0 or higher.
Please uninstall any old ruby versions from your system:
GitLab Shell is written in Go, and needs a Go compiler to build. It still requires
Ruby to build and test, but not to run.
```
sudo apt-get remove ruby1.8
```
Download Ruby and compile it with:
```
mkdir /tmp/ruby && cd /tmp/ruby
curl -L --progress http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz | tar xz
cd ruby-2.1.5
./configure --disable-install-rdoc
make
sudo make install
```
To install gitlab-shell you also need a Go compiler version 1.8 or newer. https://golang.org/dl/
Download and install the current version of Go from https://golang.org/dl/
## Setup
Loading
Loading
@@ -78,59 +62,25 @@ Checks if GitLab API access and redis via internal API can be reached:
## Testing
Run Ruby and Golang tests:
Run tests:
bundle install
make test
Run Rubocop and gofmt:
Run gofmt and rubocop:
bundle install
make verify
Run both test and verify (the default Makefile target):
bundle install
make validate
## Git LFS remark
Starting with GitLab 8.12, GitLab supports Git LFS authentication through SSH.
## Migration to Go feature flags
We are starting to migrate some features from Ruby to Go. To be able to do this
incrementally, we hide the Go implementation behind a feature flag.
To enable a feature, modify `migration` option in `config.yml` and ensure `enabled`
is set to `true` and feature to be enabled is added to `features`.
It should look something like this:
```yaml
migration:
enabled: true
features: ['discover']
```
Here are the following features that can be enabled:
- `discover`
- `2fa_recovery_codes`
### Configuring using Omnibus
If you're using Omnibus, these features can be enabled by adding something like this to `gitlab.rb`:
```ruby
gitlab_shell['migration'] = { enabled: true, features: ['discover', '2fa_recovery_codes'] }
```
This is equivalent to having this in `config.yml`:
```yaml
migration:
enabled: true
features: ['discover', '2fa_recovery_codes']
```
## Releasing a new version
GitLab Shell is versioned by git tags, and the version used by the Rails
Loading
Loading
@@ -152,18 +102,6 @@ Rails application:
version**. (Note: this can be done as a separate MR to that, or in and MR
that will make use of the latest GitLab Shell changes.)
## Updating VCR fixtures
In order to generate new VCR fixtures you need to have a local GitLab instance
running and have next data:
1. gitlab-org/gitlab-test project.
2. SSH key with access to the project and ID 1 that belongs to Administrator.
3. SSH key without access to the project and ID 2.
You also need to modify `secret` variable at `spec/gitlab_net_spec.rb` so tests
can connect to your local instance.
## Contributing
See [CONTRIBUTING.md](./CONTRIBUTING.md).
Loading
Loading
#!/usr/bin/env ruby
#
# GitLab shell authorized_keys helper. Query GitLab API to get the authorized
# command for a given ssh key fingerprint
#
# Ex.
# bin/gitlab-shell-authorized-keys-check <username> <public-key>
#
# Returns
# command="/bin/gitlab-shell key-#",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAA...
#
# Expects to be called by the SSH daemon, via configuration like:
# AuthorizedKeysCommandUser git
# AuthorizedKeysCommand /bin/gitlab-shell-authorized-keys-check git %u %k
abort "# Wrong number of arguments. #{ARGV.size}. Usage:
# gitlab-shell-authorized-keys-check <expected-username> <actual-username> <key>" unless ARGV.size == 3
expected_username = ARGV[0]
abort '# No username provided' if expected_username.nil? || expected_username == ''
actual_username = ARGV[1]
abort '# No username provided' if actual_username.nil? || actual_username == ''
# Only check access if the requested username matches the configured username.
# Normally, these would both be 'git', but it can be configured by the user
exit 0 unless expected_username == actual_username
key = ARGV[2]
abort "# No key provided" if key.nil? || key == ''
require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_net'
require_relative '../lib/gitlab_keys'
authorized_key = GitlabNet.new.authorized_key(key)
if authorized_key.nil?
puts "# No key was found for #{key}"
else
puts GitlabKeys.key_line("key-#{authorized_key['id']}", authorized_key['key'])
end
#!/usr/bin/env ruby
#
# GitLab shell authorized principals helper. Emits the same sort of
# command="..." line as gitlab-shell-authorized-principals-check, with
# the right options.
#
# Ex.
# bin/gitlab-shell-authorized-keys-check <key-id> <principal1> [<principal2>...]
#
# Returns one line per principal passed in, e.g.:
# command="/bin/gitlab-shell username-{KEY_ID}",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty {PRINCIPAL}
# [command="/bin/gitlab-shell username-{KEY_ID}",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty {PRINCIPAL2}]
#
# Expects to be called by the SSH daemon, via configuration like:
# AuthorizedPrincipalsCommandUser root
# AuthorizedPrincipalsCommand /bin/gitlab-shell-authorized-principals-check git %i sshUsers
abort "# Wrong number of arguments. #{ARGV.size}. Usage:
# gitlab-shell-authorized-principals-check <key-id> <principal1> [<principal2>...]" unless ARGV.size >= 2
key_id = ARGV[0]
abort '# No key_id provided' if key_id.nil? || key_id == ''
principals = ARGV[1..-1]
principals.each { |principal|
abort '# An invalid principal was provided' if principal.nil? || principal == ''
}
require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_net'
require_relative '../lib/gitlab_keys'
principals.each { |principal|
puts GitlabKeys.principal_line("username-#{key_id}", principal.dup)
}
#!/usr/bin/env ruby
unless ENV['SSH_CONNECTION']
puts "Only ssh allowed"
exit
end
original_cmd = ENV.delete('SSH_ORIGINAL_COMMAND')
require_relative '../lib/gitlab_init'
#
#
# GitLab shell, invoked from ~/.ssh/authorized_keys or from an
# AuthorizedPrincipalsCommand in the key-less SSH CERT mode.
#
#
require File.join(ROOT_PATH, 'lib', 'gitlab_shell')
# We must match e.g. "key-12345" anywhere on the command-line. See
# https://gitlab.com/gitlab-org/gitlab-shell/issues/145
who = /\b(?:(?:key)-[0-9]+|username-\S+)\b/.match(ARGV.join(' ')).to_s
if GitlabShell.new(who).exec(original_cmd)
exit 0
else
exit 1
end
#!/usr/bin/env ruby
# The purpose of this executable is to test that gitlab-shell logging
# works correctly in combination with Kernel.exec.
require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_logger'
$logger.info(ARGV.first)
Kernel.exec('true')
package main
import (
"context"
"encoding/json"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/handler"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/logger"
"google.golang.org/grpc"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func init() {
logger.ProgName = "gitaly-receive-pack"
}
func main() {
handler.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn, requestJSON string) (int32, error) {
request, err := deserialize(requestJSON)
if err != nil {
return 1, err
}
return handler.ReceivePack(ctx, conn, request)
})
}
func deserialize(requestJSON string) (*pb.SSHReceivePackRequest, error) {
var request pb.SSHReceivePackRequest
if err := json.Unmarshal([]byte(requestJSON), &request); err != nil {
return nil, err
}
return &request, nil
}
package main
import (
"testing"
"github.com/stretchr/testify/require"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func Test_deserialize(t *testing.T) {
tests := []struct {
name string
requestJSON string
want *pb.SSHReceivePackRequest
wantErr bool
}{
{
name: "empty",
requestJSON: "",
want: nil,
wantErr: true,
},
{
name: "empty_hash",
requestJSON: "{}",
want: &pb.SSHReceivePackRequest{},
wantErr: false,
},
{
name: "nil",
requestJSON: "null",
want: &pb.SSHReceivePackRequest{},
wantErr: false,
},
{
name: "values",
requestJSON: `{"gl_id": "1234"}`,
want: &pb.SSHReceivePackRequest{GlId: "1234"},
wantErr: false,
},
{
name: "invalid_json",
requestJSON: `{"gl_id": "1234`,
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := deserialize(tt.requestJSON)
require.EqualValues(t, got, tt.want, "Got %+v, wanted %+v", got, tt.want)
if tt.wantErr {
require.Error(t, err, "Wanted an error, got %+v", err)
} else {
require.NoError(t, err, "Wanted no error, got %+v", err)
}
})
}
}
package main
import (
"context"
"encoding/json"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/handler"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/logger"
"google.golang.org/grpc"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func init() {
logger.ProgName = "gitaly-upload-archive"
}
func main() {
handler.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn, requestJSON string) (int32, error) {
request, err := deserialize(requestJSON)
if err != nil {
return 1, err
}
return handler.UploadArchive(ctx, conn, request)
})
}
func deserialize(argumentJSON string) (*pb.SSHUploadArchiveRequest, error) {
var request pb.SSHUploadArchiveRequest
if err := json.Unmarshal([]byte(argumentJSON), &request); err != nil {
return nil, err
}
return &request, nil
}
package main
import (
"testing"
"github.com/stretchr/testify/require"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func Test_deserialize(t *testing.T) {
tests := []struct {
name string
requestJSON string
want *pb.SSHUploadArchiveRequest
wantErr bool
}{
{
name: "empty",
requestJSON: "",
want: nil,
wantErr: true,
},
{
name: "empty_hash",
requestJSON: "{}",
want: &pb.SSHUploadArchiveRequest{},
wantErr: false,
},
{
name: "nil",
requestJSON: "null",
want: &pb.SSHUploadArchiveRequest{},
wantErr: false,
},
{
name: "values",
requestJSON: `{"repository": { "storage_name": "12345"} }`,
want: &pb.SSHUploadArchiveRequest{Repository: &pb.Repository{StorageName: "12345"}},
wantErr: false,
},
{
name: "invalid_json",
requestJSON: `{"gl_id": "1234`,
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := deserialize(tt.requestJSON)
require.EqualValues(t, got, tt.want, "Got %+v, wanted %+v", got, tt.want)
if tt.wantErr {
require.Error(t, err, "Wanted an error, got %+v", err)
} else {
require.NoError(t, err, "Wanted no error, got %+v", err)
}
})
}
}
package main
import (
"context"
"encoding/json"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/handler"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/logger"
"google.golang.org/grpc"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func init() {
logger.ProgName = "gitaly-upload-pack"
}
func main() {
handler.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn, requestJSON string) (int32, error) {
request, err := deserialize(requestJSON)
if err != nil {
return 1, err
}
return handler.UploadPack(ctx, conn, request)
})
}
func deserialize(requestJSON string) (*pb.SSHUploadPackRequest, error) {
var request pb.SSHUploadPackRequest
if err := json.Unmarshal([]byte(requestJSON), &request); err != nil {
return nil, err
}
return &request, nil
}
package main
import (
"testing"
"github.com/stretchr/testify/require"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func Test_deserialize(t *testing.T) {
tests := []struct {
name string
requestJSON string
want *pb.SSHUploadPackRequest
wantErr bool
}{
{
name: "empty",
requestJSON: "",
want: nil,
wantErr: true,
},
{
name: "empty_hash",
requestJSON: "{}",
want: &pb.SSHUploadPackRequest{},
wantErr: false,
},
{
name: "nil",
requestJSON: "null",
want: &pb.SSHUploadPackRequest{},
wantErr: false,
},
{
name: "values",
requestJSON: `{"repository": { "storage_name": "12345"} }`,
want: &pb.SSHUploadPackRequest{Repository: &pb.Repository{StorageName: "12345"}},
wantErr: false,
},
{
name: "invalid_json",
requestJSON: `{"gl_id": "1234`,
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := deserialize(tt.requestJSON)
require.EqualValues(t, got, tt.want, "Got %+v, wanted %+v", got, tt.want)
if tt.wantErr {
require.Error(t, err, "Wanted an error, got %+v", err)
} else {
require.NoError(t, err, "Wanted no error, got %+v", err)
}
})
}
}
require_relative 'action/custom'
module Action
end
require 'base64'
require_relative '../http_helper'
require_relative '../console_helper'
module Action
class Custom
include HTTPHelper
include ConsoleHelper
class BaseError < StandardError; end
class MissingPayloadError < BaseError; end
class MissingAPIEndpointsError < BaseError; end
class MissingDataError < BaseError; end
class UnsuccessfulError < BaseError; end
NO_MESSAGE_TEXT = 'No message'.freeze
DEFAULT_HEADERS = { 'Content-Type' => CONTENT_TYPE_JSON }.freeze
def initialize(gl_id, payload)
@gl_id = gl_id
@payload = payload
end
def execute
validate!
inform_client(info_message) if info_message
process_api_endpoints!
end
private
attr_reader :gl_id, :payload
def process_api_endpoints!
output = ''
resp = nil
data_with_gl_id = data.merge('gl_id' => gl_id)
api_endpoints.each do |endpoint|
url = "#{base_url}#{endpoint}"
json = { 'data' => data_with_gl_id, 'output' => output }
resp = post(url, {}, headers: DEFAULT_HEADERS, options: { json: json })
# Net::HTTPSuccess is the parent of Net::HTTPOK, Net::HTTPCreated etc.
case resp
when Net::HTTPSuccess, Net::HTTPMultipleChoices
true
else
raise_unsuccessful!(resp)
end
begin
body = JSON.parse(resp.body)
rescue JSON::ParserError
raise UnsuccessfulError, 'Response was not valid JSON'
end
print_flush(body['result'])
# In the context of the git push sequence of events, it's necessary to read
# stdin in order to capture output to pass onto subsequent commands
output = read_stdin
end
resp
end
def base_url
config.gitlab_url
end
def data
@data ||= payload['data']
end
def api_endpoints
data['api_endpoints']
end
def info_message
data['info_message']
end
def config
@config ||= GitlabConfig.new
end
def api
@api ||= GitlabNet.new
end
def read_stdin
Base64.encode64($stdin.read)
end
def print_flush(str)
return false unless str
$stdout.print(Base64.decode64(str))
$stdout.flush
end
def inform_client(str)
$stderr.puts(format_gitlab_output(str))
end
def format_gitlab_output(str)
format_for_stderr(str.split("\n")).join("\n")
end
def validate!
validate_payload!
validate_data!
validate_api_endpoints!
end
def validate_payload!
raise MissingPayloadError if !payload.is_a?(Hash) || payload.empty?
end
def validate_data!
raise MissingDataError unless data.is_a?(Hash)
end
def validate_api_endpoints!
raise MissingAPIEndpointsError if !api_endpoints.is_a?(Array) ||
api_endpoints.empty?
end
def raise_unsuccessful!(result)
message = "#{exception_message_for(result.body)} (#{result.code})"
raise UnsuccessfulError, format_gitlab_output(message)
end
def exception_message_for(body)
body = JSON.parse(body)
return body['message'] unless body['message'].to_s.empty?
body['result'].to_s.empty? ? NO_MESSAGE_TEXT : Base64.decode64(body['result'])
rescue JSON::ParserError
NO_MESSAGE_TEXT
end
end
end
# frozen_string_literal: true
module ConsoleHelper
LINE_PREFACE = '> GitLab:'
def write_stderr(messages)
format_for_stderr(messages).each do |message|
$stderr.puts(message)
end
end
def format_for_stderr(messages)
Array(messages).each_with_object([]) do |message, all|
all << "#{LINE_PREFACE} #{message}" unless message.empty?
end
end
end
require 'json'
class GitAccessStatus
HTTP_MULTIPLE_CHOICES = '300'.freeze
attr_reader :message, :gl_repository, :gl_project_path, :gl_id, :gl_username,
:gitaly, :git_protocol, :git_config_options, :payload,
:gl_console_messages
def initialize(status, status_code, message, gl_repository: nil,
gl_project_path: nil, gl_id: nil,
gl_username: nil, gitaly: nil, git_protocol: nil,
git_config_options: nil, payload: nil, gl_console_messages: [])
@status = status
@status_code = status_code
@message = message
@gl_repository = gl_repository
@gl_project_path = gl_project_path
@gl_id = gl_id
@gl_username = gl_username
@git_config_options = git_config_options
@gitaly = gitaly
@git_protocol = git_protocol
@payload = payload
@gl_console_messages = gl_console_messages
end
def self.create_from_json(json, status_code)
values = JSON.parse(json)
new(values["status"],
status_code,
values["message"],
gl_repository: values["gl_repository"],
gl_project_path: values["gl_project_path"],
gl_id: values["gl_id"],
gl_username: values["gl_username"],
git_config_options: values["git_config_options"],
gitaly: values["gitaly"],
git_protocol: values["git_protocol"],
payload: values["payload"],
gl_console_messages: values["gl_console_messages"])
end
def allowed?
@status
end
def custom_action?
@status_code == HTTP_MULTIPLE_CHOICES
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment