Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enterprise to master. #1316

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
11175e2
Update OS for enterprise ship:docker
DamianSzymanski Mar 18, 2021
c73e9ee
gem updates (#1192)
GbArc Apr 21, 2021
4a759ca
trivy scan added, docker fix (#1196)
GbArc Jul 6, 2021
5ee50d2
trivy fix
GbArc Jul 7, 2021
ba2c4dc
security updates [ship:docker] (#1200)
gbarc80 Aug 2, 2021
26be255
gh update
GbArc Aug 2, 2021
a89750c
update to use latest docker
GbArc Oct 21, 2021
82d5198
added region to s3 query
GbArc Nov 23, 2021
52adedb
gh update - gh token fix (#1223)
GbArc Feb 8, 2022
b968fac
share envs to forks (#1232)
GbArc Mar 16, 2022
40153e7
extended default timeouts for db, temp workaround for tcie
GbArc May 4, 2022
95b0da0
timeout spec fix
GbArc May 4, 2022
2bce53f
Upgrade gems (#1233)
makemp May 17, 2022
41af887
removed trivy
GbArc May 17, 2022
6e817cc
gem updates (#1237)
GbArc May 17, 2022
d8b682f
w/a: removed set_tags call for raven, todo - migrate to new api'
GbArc Jun 1, 2022
eaefc8a
rack update -> 2.2.3.1
GbArc Jun 8, 2022
c12eb15
job query optimization ship:docker (#1240)
GbArc Jun 14, 2022
8d8d693
console fix after pry update
GbArc Jun 29, 2022
978635f
gem updates + extended access rights for tokens (#1246)
GbArc Aug 26, 2022
e036f1b
restarted_by feature - merge from master (#1248)
GbArc Sep 7, 2022
0bd5566
putting api on a diet (ship:docker) (#1250)
GbArc Oct 5, 2022
ef4b8f8
bump google-protobuf to 3.19.6
GbArc Oct 14, 2022
a6be270
merge from master (#1260)
GbArc Dec 14, 2022
cd697da
sinatra up to 2.2.3 (#1264)
GbArc Dec 28, 2022
415f12c
bump travis-lock, travis-settings
GbArc Jan 11, 2023
fe48847
simplecov moved to test group
GbArc Jan 11, 2023
edfd3a7
sinatra bump to 2.2.4, hostname added for cache queries
GbArc Jan 30, 2023
22f7893
activesupport up to 6.1.7.2
GbArc Feb 2, 2023
fedd96c
managing email subscriptions for whole org
gbarc-dt May 26, 2023
9deeb71
Update gem database_cleaner
Jun 26, 2023
09ac6dd
Fix for SUPP-725 ship:docker (#1295)
piccadilly-circus Aug 28, 2023
ab08a8c
[BSFY-277] Add tag_name to build request (#1305)
AndriiMysko Feb 21, 2024
c567088
API merge. Enterprise to master.
Mar 19, 2024
b3b45c1
API merge. Enterprise to master.
Mar 20, 2024
83d6944
TravisCI API merge. Enterprise to master.
Mar 21, 2024
27fec3b
TravisCI API. Review fixes.
Apr 2, 2024
063ffb3
repo spec
gbarc-dt Apr 2, 2024
e830a80
specs, ship:docker
gbarc-dt Apr 2, 2024
ad89c7b
TravisCI API. Adding libcurl library.
Apr 3, 2024
74fb28d
Merge branch 'dt-e3-0-update' of https://github.com/travis-ci/travis-…
Apr 3, 2024
e4d67d7
libcurl4 ship:docker
gbarc-dt Apr 4, 2024
ec37998
allowance for tcie ship:docker
gbarc-dt Apr 9, 2024
68eef36
allowance ship:docker
gbarc-dt Apr 9, 2024
43ef552
Dockerfile revert ship:docker
gbarc-dt Apr 12, 2024
45efe5c
endpoint updates ship:docker
gbarc-dt Apr 16, 2024
f435814
Implement legacy roles option
AndriiMysko Apr 17, 2024
b192120
test
gbarc-dt Apr 17, 2024
5721958
Merge remote-tracking branch 'origin/dt-e3-0-legacy-roles' into dt-e3…
gbarc-dt Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: ruby
group: edge

import:
- travis-ci/build-configs:db-setup.yml
Expand All @@ -19,12 +20,11 @@ env:
- CI_NODE_INDEX=1
- CI_NODE_INDEX=2

cache: bundler

services:
- redis-server

before_install:
- 'gem install rubygems-update -v 3.4.22'
- 'gem update --system'

jobs:
Expand Down
44 changes: 44 additions & 0 deletions Dockerfile.tcie
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM ruby:3.2.2-slim

LABEL maintainer Travis CI GmbH <[email protected]>

RUN ( \
mkdir -p /app/vendor /app/cache; \
groupadd -r travis -g 1000 && \
useradd -u 1000 -r -g travis -s /bin/sh -c "travis user" -d "/app" travis;\
chown -R travis:travis /app; \
apt-get update ; \
apt-get upgrade -y ; \
apt-get install -y --no-install-recommends git make gcc g++ libpq-dev libjemalloc-dev xz-utils libcurl4 curl \
&& rm -rf /var/lib/apt/lists/*; \
gem update --system; \
bundle config set app_config /app; \
bundle config set cache_path /app; \
bundle config --global frozen 1; \
bundle config set deployment 'true'; \
chown -R travis:travis /usr/local/bundle; \
)



WORKDIR /app

USER travis
COPY Gemfile* /app/
RUN ( \
bundle config set without 'development test'; \
bundler install --verbose --retry=3; \
bundle config set frozen true; \
)
USER root
RUN ( apt-get remove -y gcc g++ make git perl xz-utils && apt-get -y autoremove; \
bundle clean && rm -rf /app/vendor/bundle/ruby/2.7.0/cache/*; \
for i in `find /app/vendor/ -name \*.o -o -name \*.c -o -name \*.h`; do rm -f $i; done; \
)

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

COPY . /app

CMD ["./script/server-buildpacks"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DOCKER ?= docker

.PHONY: docker-build
docker-build:
$(DOCKER) build -t $(DOCKER_DEST) .
$(DOCKER) build --no-cache --pull -t $(DOCKER_DEST) . -f Dockerfile.tcie

.PHONY: docker-login
docker-login:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Build Status](https://travis-ci.com/travis-ci/travis-api.svg?branch=master)](https://travis-ci.com/travis-ci/travis-api)


https://api.travis-ci.org

## WARNING!!!!!
Expand Down
2 changes: 1 addition & 1 deletion lib/travis.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'pusher'
require 'travis/support'
require 'travis/support/database'
#require 'travis/support/database'
require 'travis/errors'

module Travis
Expand Down
5 changes: 1 addition & 4 deletions lib/travis/api/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ def self.setup(options = {})
FileUtils.touch('/tmp/app-initialized') if ENV['DYNO'] # Heroku
end

def self.new(options = {})
setup(options)
super()
end

def self.deploy_sha
@deploy_sha ||= ENV['HEROKU_SLUG_COMMIT'] || SecureRandom.hex(5)
Expand Down Expand Up @@ -186,6 +182,7 @@ def initialize(options = {})

# Rack protocol
def call(env)
#app.after { ActiveRecord::Base.clear_active_connections! }
app.call(env)
rescue
if Endpoint.production?
Expand Down
4 changes: 2 additions & 2 deletions lib/travis/api/app/endpoint/builds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Builds < Endpoint


service = Travis::Enqueue::Services::CancelModel.new(current_user, { build_id: params[:id] })
auth_for_repo(service&.target&.repository&.id, 'repository_build_cancel')
auth_for_repo(service&.target&.repository&.id, 'repository_build_cancel') unless Travis.config.legacy_roles

if !service.authorized?
json = { error: {
Expand Down Expand Up @@ -60,7 +60,7 @@ class Builds < Endpoint
service = Travis::Enqueue::Services::RestartModel.new(current_user, build_id: params[:id])
disallow_migrating!(service.repository)

auth_for_repo(service.repository.id, 'repository_build_restart')
auth_for_repo(service.repository.id, 'repository_build_restart') unless Travis.config.legacy_roles

result = if !service.accept?
status 400
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/api/app/endpoint/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Hooks < Endpoint

put '/:id?', scope: :private do
service = service(:update_hook, id: params[:id] || params[:hook][:id], active: params[:hook][:active])
auth_for_repo(params[:id] || params[:hook][:id], 'repository_state_update')
auth_for_repo(params[:id] || params[:hook][:id], 'repository_state_update') unless Travis.config.legacy_roles
disallow_migrating!(service.repo)
respond_with service
end
Expand Down
4 changes: 2 additions & 2 deletions lib/travis/api/app/endpoint/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Jobs < Endpoint

service = Travis::Enqueue::Services::CancelModel.new(current_user, { job_id: params[:id] })

auth_for_repo(service&.target&.repository&.id, 'repository_build_cancel')
auth_for_repo(service&.target&.repository&.id, 'repository_build_cancel') unless Travis.config.legacy_roles

if !service.authorized?
json = { error: {
Expand Down Expand Up @@ -65,7 +65,7 @@ class Jobs < Endpoint

service = Travis::Enqueue::Services::RestartModel.new(current_user, { job_id: params[:id] })

auth_for_repo(service&.repository&.id, 'repository_build_restart')
auth_for_repo(service&.repository&.id, 'repository_build_restart') unless Travis.config.legacy_roles
disallow_migrating!(service.repository)

result = if !service.accept?
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/api/app/endpoint/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Logs < Endpoint

repo = Travis::API::V3::Models::Repository.find(job.repository.id)

auth_for_repo(repo.id, 'repository_log_view')
auth_for_repo(repo.id, 'repository_log_view') unless Travis.config.legacy_roles

repo_can_write = current_user ? !!repo.users.where(id: current_user.id, permissions: { push: true }).first : false

Expand Down
20 changes: 10 additions & 10 deletions lib/travis/api/app/endpoint/repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Repos < Endpoint
# Get settings for a given repository
#
get '/:id/settings', scope: :private do
auth_for_repo(params['id'], 'repository_settings_read')
auth_for_repo(params['id'], 'repository_settings_read') unless Travis.config.legacy_roles
settings = service(:find_repo_settings, params).run
if settings
respond_with({ settings: settings.simple_attributes }, version: :v2)
Expand All @@ -83,7 +83,7 @@ class Repos < Endpoint
patch '/:id/settings', scope: :private do
payload = JSON.parse request.body.read

auth_for_repo(params['id'], 'repository_settings_update')
auth_for_repo(params['id'], 'repository_settings_update') unless Travis.config.legacy_roles
if payload['settings'].blank? || !payload['settings'].is_a?(Hash)
halt 422, { "error" => "Settings must be passed with a request" }
end
Expand Down Expand Up @@ -115,14 +115,14 @@ class Repos < Endpoint
#
# json(:repository_key)
get '/:id/key' do
auth_for_repo(params['id'], 'repository_settings_read')
auth_for_repo(params['id'], 'repository_settings_read') unless Travis.config.legacy_roles
respond_with service(:find_repo_key, params), version: :v2
respond_with service(:find_repo_key, params), type: :ssl_key, version: :v2
end

post '/:id/key' do

auth_for_repo(params['id'], 'repository_settings_create')
auth_for_repo(params['id'], 'repository_settings_create') unless Travis.config.legacy_roles
service = service(:regenerate_repo_key, params)
disallow_migrating!(service.repo)
respond_with service, version: :v2
Expand All @@ -141,14 +141,14 @@ class Repos < Endpoint

# List caches for a given repo. Can be filtered with `branch` and `match` query parameter.
get '/:repository_id/caches', scope: :private do
auth_for_repo(params['repository_id'], 'repository_cache_view')
auth_for_repo(params['repository_id'], 'repository_cache_view') unless Travis.config.legacy_roles
respond_with service(:find_caches, params), type: :caches, version: :v2
end

# Delete caches for a given repo. Can be filtered with `branch` and `match` query parameter.
delete '/:repository_id/caches', scope: :private do

auth_for_repo(params['repository_id'], 'repository_cache_delete')
auth_for_repo(params['repository_id'], 'repository_cache_delete') unless Travis.config.legacy_roles
respond_with service(:delete_caches, params), type: :caches, version: :v2
end

Expand Down Expand Up @@ -197,7 +197,7 @@ class Repos < Endpoint
repo = service(:find_repo, params).run
halt 404 unless repo

auth_for_repo(repo&.id, 'repository_settings_read')
auth_for_repo(repo&.id, 'repository_settings_read') unless Travis.config.legacy_roles
respond_with service(:find_repo_key, params), type: :ssl_key, version: :v2
end

Expand All @@ -206,7 +206,7 @@ class Repos < Endpoint
halt 404 unless repo


auth_for_repo(repo&.id, 'repository_settings_create')
auth_for_repo(repo&.id, 'repository_settings_create') unless Travis.config.legacy_roles
service = service(:regenerate_repo_key, params)
disallow_migrating!(service.repo)
respond_with service, version: :v2
Expand All @@ -226,14 +226,14 @@ class Repos < Endpoint
# List caches for a given repo. Can be filtered with `branch` and `match` query parameter.
get '/:owner_name/:name/caches', scope: :private do
repo = service(:find_repo, params).run
auth_for_repo(repo&.id, 'repository_cache_view')
auth_for_repo(repo&.id, 'repository_cache_view') unless Travis.config.legacy_roles
respond_with service(:find_caches, params), type: :caches, version: :v2
end

# Delete caches for a given repo. Can be filtered with `branch` and `match` query parameter.
delete '/:owner_name/:name/caches', scope: :private do
repo = service(:find_repo, params).run
auth_for_repo(repo&.id, 'repository_cache_delete')
auth_for_repo(repo&.id, 'repository_cache_delete') unless Travis.config.legacy_roles
respond_with service(:delete_caches, params), type: :caches, version: :v2
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/travis/api/app/endpoint/setting_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ def define_routes!
# Rails style methods for easy overriding
def index

auth_for_repo(repo.id, 'repository_settings_read')
auth_for_repo(repo.id, 'repository_settings_read') unless Travis.config.legacy_roles

respond_with(collection, type: name, version: :v2)
end

def show
auth_for_repo(repo.id, 'repository_settings_read')
auth_for_repo(repo.id, 'repository_settings_read') unless Travis.config.legacy_roles

respond_with(record, type: singular_name, version: :v2)
end

def update

auth_for_repo(repo.id, 'repository_settings_update')
auth_for_repo(repo.id, 'repository_settings_update') unless Travis.config.legacy_roles

disallow_migrating!(repo)

Expand All @@ -77,7 +77,7 @@ def update

def create

auth_for_repo(repo.id, 'repository_settings_create')
auth_for_repo(repo.id, 'repository_settings_create') unless Travis.config.legacy_roles

disallow_migrating!(repo)

Expand All @@ -101,7 +101,7 @@ def create
end

def destroy
auth_for_repo(repo.id, 'repository_settings_delete')
auth_for_repo(repo.id, 'repository_settings_delete') unless Travis.config.legacy_roles

disallow_migrating!(repo)

Expand Down
4 changes: 2 additions & 2 deletions lib/travis/api/app/endpoint/singleton_settings_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_settings_class(name)
end

def update
auth_for_repo(parent.repository.id, 'repository_settings_update')
auth_for_repo(parent.repository.id, 'repository_settings_update') unless Travis.config.legacy_roles

disallow_migrating!(parent.repository)

Expand All @@ -32,7 +32,7 @@ def update
end

def destroy
auth_for_repo(parent.repository.id, 'repository_settings_delete')
auth_for_repo(parent.repository.id, 'repository_settings_delete') unless Travis.config.legacy_roles

disallow_migrating!(parent.repository)

Expand Down
9 changes: 9 additions & 0 deletions lib/travis/api/enqueue/services/restart_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def billing?
# there is no billing for .org
return true if Travis.config.org?

# there is no billing for .enterprise
return true if !!Travis.config.enterprise

@_billing_ok ||= begin
jobs = target.is_a?(Job) ? [target] : target.matrix

Expand Down Expand Up @@ -106,11 +109,17 @@ def permission?
end

def build_permission?
return build_permission_legacy? if Travis.config.legacy_roles

# nil value is considered true
return true if authorizer.for_repo(repository.id,'repository_build_restart')

false
rescue Travis::API::V3::AuthorizerError
build_permission_legacy?
end

def build_permission_legacy?
return false if repository.permissions.find_by(user_id: current_user.id).build == false
return false if repository.owner_type == 'Organization' && repository.owner.memberships.find_by(user_id: current_user.id)&.build_permission == false

Expand Down
2 changes: 2 additions & 0 deletions lib/travis/api/v3/extensions/preferences.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'active_support/all'

module Travis::API::V3
module Extensions
module Preferences
Expand Down
2 changes: 2 additions & 0 deletions lib/travis/api/v3/models/fingerprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def calculate(source)
rsa_key = OpenSSL::PKey::RSA.new(source)
public_ssh_rsa = "\x00\x00\x00\x07ssh-rsa" + rsa_key.e.to_s(0) + rsa_key.n.to_s(0)
OpenSSL::Digest::MD5.new(public_ssh_rsa).hexdigest.scan(/../).join(':')
rescue OpenSSL::PKey::RSAError
nil
end

module_function :calculate
Expand Down
2 changes: 2 additions & 0 deletions lib/travis/api/v3/models/key_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def fingerprint_source
def public_key
return unless value.decrypt
OpenSSL::PKey::RSA.new(value.decrypt).public_key.to_s
rescue OpenSSL::PKey::RSAError
nil
end

def to_h
Expand Down
13 changes: 0 additions & 13 deletions lib/travis/api/v3/models/leads.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/travis/api/v3/models/user_settings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json'

module Travis::API::V3
class Models::UserSettings < Models::JsonSlice
child Models::UserSetting
Expand Down
Loading