Skip to content

Commit a6be270

Browse files
authored
merge from master (#1260)
* bundler update * merge from master 31.10.22 * usr/group update * ship:docker
1 parent ef4b8f8 commit a6be270

File tree

233 files changed

+5621
-766
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+5621
-766
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ env:
2121
- CI_NODE_INDEX=1
2222
- CI_NODE_INDEX=2
2323

24-
cache: bundler
25-
2624
services:
2725
- redis-server
2826

Dockerfile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,40 @@ FROM ruby:2.7.5-slim
33
LABEL maintainer Travis CI GmbH <[email protected]>
44

55
RUN ( \
6-
bundle config set no-cache 'true'; \
6+
mkdir -p /app/vendor /app/cache; \
7+
groupadd -r travis -g 1000 && \
8+
useradd -u 1000 -r -g travis -s /bin/sh -c "travis user" -d "/app" travis;\
9+
chown -R travis:travis /app; \
10+
apt-get update ; \
11+
apt-get upgrade -y ; \
12+
apt-get install -y --no-install-recommends git make gcc g++ libpq-dev libjemalloc-dev xz-utils \
13+
&& rm -rf /var/lib/apt/lists/*; \
14+
gem update --system; \
15+
bundle config set app_config /app; \
16+
bundle config set cache_path /app; \
717
bundle config --global frozen 1; \
818
bundle config set deployment 'true'; \
9-
mkdir -p /app; \
19+
chown -R travis:travis /usr/local/bundle; \
1020
)
1121

22+
23+
1224
WORKDIR /app
1325

26+
USER travis
1427
COPY Gemfile* /app/
15-
1628
RUN ( \
17-
apt-get update ; \
18-
apt-get upgrade -y ; \
19-
apt-get install -y --no-install-recommends git make gcc g++ libpq-dev libjemalloc-dev \
20-
&& rm -rf /var/lib/apt/lists/* \
21-
gem install bundler -v '2.3.6'; \
2229
bundle config set without 'development test'; \
2330
bundler install --verbose --retry=3; \
2431
bundle config set frozen true; \
25-
apt-get remove -y gcc g++ make git perl && apt-get -y autoremove; \
32+
)
33+
USER root
34+
RUN ( apt-get remove -y gcc g++ make git perl xz-utils && apt-get -y autoremove; \
2635
bundle clean && rm -rf /app/vendor/bundle/ruby/2.7.0/cache/*; \
2736
for i in `find /app/vendor/ -name \*.o -o -name \*.c -o -name \*.h`; do rm -f $i; done; \
2837
)
2938

39+
USER travis
3040
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
3141

3242
COPY . /app

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,4 @@ RUBY VERSION
527527
ruby 2.7.5p203
528528

529529
BUNDLED WITH
530-
2.3.7
530+
2.3.24

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
https://api.travis-ci.org
66

7+
## WARNING!!!!!
8+
Master branch is designed for .com only. If you would like to deploy changes for .org please use org-only branch
79
## Requirements
810

911
You will need the following packages to get travis-api to work:

lib/travis.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class GithubApiError < StandardError; end
3131
class AdminMissing < StandardError; end
3232
class RepositoryMissing < StandardError; end
3333
class LogAlreadyRemoved < StandardError; end
34+
class LogExpired < StandardError; end
35+
class LogAccessDenied < StandardError; end
3436
class AuthorizationDenied < StandardError; end
3537
class JobUnfinished < StandardError; end
3638

lib/travis/api/app/endpoint.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def endpoint(link, query_values = {})
120120
require 'travis/api/app/endpoint/branches'
121121
require 'travis/api/app/endpoint/broadcasts'
122122
require 'travis/api/app/endpoint/builds'
123+
require 'travis/api/app/endpoint/build_backups'
123124
require 'travis/api/app/endpoint/documentation'
124125
require 'travis/api/app/endpoint/endpoints'
125126
require 'travis/api/app/endpoint/env_vars'

lib/travis/api/app/endpoint/authorization.rb

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class Authorization < Endpoint
106106
get '/handshake/?:provider?' do
107107
method = org? ? :handshake : :vcs_handshake
108108
params[:provider] ||= 'github'
109-
110109
send(method) do |user, token, redirect_uri|
111110
if target_ok? redirect_uri
112111
content_type :html
@@ -128,6 +127,21 @@ class Authorization < Endpoint
128127
halt 401, 'could not resolve github token'
129128
end
130129

130+
get '/confirm_user/:token' do
131+
content_type :json
132+
Travis::RemoteVCS::User.new.confirm_user(token: params[:token])
133+
{ status: 200 }.to_json
134+
rescue Travis::RemoteVCS::ResponseError
135+
halt 404, 'The token is expired or not found.'
136+
end
137+
138+
get '/request_confirmation/:id' do
139+
content_type :json
140+
Travis::RemoteVCS::User
141+
.new.request_confirmation(id: current_user.id)
142+
{ status: 200 }.to_json
143+
end
144+
131145
private
132146

133147
# update first login date if not set
@@ -166,7 +180,8 @@ def handshake
166180
if params[:code]
167181
unless state_ok?(params[:state])
168182
log_with_request_id("[handshake] Handshake failed (state mismatch)")
169-
halt 400, 'state mismatch'
183+
handle_invalid_response
184+
return
170185
end
171186

172187
endpoint.path = config[:access_token_path]
@@ -196,7 +211,8 @@ def remote_vcs_user
196211
def vcs_handshake
197212
if params[:code]
198213
unless state_ok?(params[:state], params[:provider])
199-
halt 400, 'state mismatch'
214+
handle_invalid_response
215+
return
200216
end
201217

202218
vcs_data = remote_vcs_user.authenticate(
@@ -210,7 +226,9 @@ def vcs_handshake
210226
return
211227
end
212228

213-
yield serialize_user(User.find(vcs_data['user']['id'])), vcs_data['token'], payload(params[:provider])
229+
user = User.find(vcs_data['user']['id'])
230+
update_first_login(user)
231+
yield serialize_user(user), vcs_data['token'], payload(params[:provider])
214232
else
215233
state = vcs_create_state(params[:origin] || params[:redirect_uri])
216234

@@ -259,6 +277,18 @@ def cookie_name(provider = :github)
259277

260278
# VCS HANDSHAKE END
261279

280+
def clear_state_cookies
281+
response.delete_cookie cookie_name(:github)
282+
response.delete_cookie cookie_name(:gitlab)
283+
response.delete_cookie cookie_name(:bitbucket)
284+
response.delete_cookie cookie_name(:assembla)
285+
end
286+
287+
def handle_invalid_response
288+
clear_state_cookies
289+
redirect to("https://#{Travis.config.host}/")
290+
end
291+
262292
def create_state
263293
state = SecureRandom.urlsafe_base64(16)
264294
redis.sadd('github:states', state)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'travis/api/app'
2+
require 'travis/api/app/responders/base'
3+
4+
class Travis::Api::App
5+
class Endpoint
6+
class BuildBackups < Endpoint
7+
include Helpers::Accept
8+
9+
before { authenticate_by_mode! }
10+
11+
get '/' do
12+
prefer_follower do
13+
respond_with service(:find_build_backups, params)
14+
end
15+
end
16+
end
17+
end
18+
end

lib/travis/api/app/endpoint/env_vars.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def update
2727
respond_with(record, type: :validation_error, version: :v2)
2828
end
2929
end
30+
3031
end
3132
end
3233
end

lib/travis/api/app/endpoint/jobs.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,7 @@ class Jobs < Endpoint
9393
# the way we use responders makes it hard to validate proper format
9494
# automatically here, so we need to check it explicitly
9595
if accepts?('text/plain')
96-
archived_log_path = resource.archived_url
97-
98-
if params[:cors_hax]
99-
status 204
100-
headers['Access-Control-Expose-Headers'] = 'Location'
101-
headers['Location'] = archived_log_path
102-
attach_log_token if job.try(:private?)
103-
else
104-
redirect archived_log_path, 307
105-
end
96+
respond_with resource.archived_log_content
10697
elsif accepts?('application/json')
10798
attach_log_token if job.try(:private?)
10899
respond_with resource.as_json

0 commit comments

Comments
 (0)