Removed http basic auth in abf, added native build, changed github api gem

This commit is contained in:
Wedge 2016-03-28 12:56:04 +03:00
parent b9326ab444
commit 1338cbcb4c
19 changed files with 80 additions and 70 deletions

View File

@ -82,7 +82,7 @@ gem 'rack-utf8_sanitizer'
gem 'redis-semaphore'
#github api
gem 'github_api'
gem "octokit", "~> 4.0"
gem 'faraday-http-cache'
group :production do

View File

@ -143,8 +143,6 @@ GEM
safe_yaml (~> 1.0.0)
daemons (1.2.2)
debug_inspector (0.0.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (3.5.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@ -176,14 +174,6 @@ GEM
formtastic_i18n (0.4.1)
friendly_id (5.1.0)
activerecord (>= 4.0.0)
github_api (0.13.0)
addressable (~> 2.3)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8, < 0.10)
hashie (>= 3.4)
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.6)
oauth2
gli (2.13.1)
globalid (0.3.5)
activesupport (>= 4.1.0)
@ -198,7 +188,6 @@ GEM
has_scope (0.6.0)
actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5)
hashie (3.4.2)
highline (1.6.21)
hike (1.2.3)
hirb (0.7.3)
@ -230,7 +219,6 @@ GEM
railties (>= 3.2)
sprockets-rails
json (1.8.3)
jwt (1.5.0)
kaminari (0.16.3)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
@ -273,7 +261,6 @@ GEM
railties (>= 3.1)
mono_logger (1.1.0)
multi_json (1.11.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
nest (1.1.2)
redis
@ -291,12 +278,8 @@ GEM
rails (>= 3.1)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
octokit (4.3.0)
sawyer (~> 0.7.0, >= 0.5.3)
ohm (1.3.2)
nest (~> 1.0)
redis
@ -453,6 +436,9 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
sawyer (0.7.0)
addressable (>= 2.3.5, < 2.5)
faraday (~> 0.8, < 0.10)
schema_auto_foreign_keys (0.1.0)
schema_plus_foreign_keys (~> 0.1)
schema_plus_indexes (~> 0.2)
@ -613,7 +599,6 @@ DEPENDENCIES
ffi
font-awesome-rails
friendly_id
github_api
haml-rails
highline (~> 1.6.20)
hirb
@ -630,6 +615,7 @@ DEPENDENCIES
newrelic_rpm
ng-rails-csrf
ngmin-rails
octokit (~> 4.0)
ohm (~> 1.3.2)
ohm-expire (~> 0.1.3)
paperclip

View File

@ -18,7 +18,7 @@ class Api::V1::BaseController < ApplicationController
def check_auth
authenticate_or_request_with_http_basic do |username,pw|
if user = User.auth_by_token_or_login_pass(username, pw)
sign_in user, false
sign_in user, store: false
end
end
end

View File

@ -15,10 +15,27 @@ class Api::V1::JobsController < Api::V1::BaseController
for_platform(platform_ids).where(builder: nil).pluck('DISTINCT user_id').sample
if uid
build_lists = BuildList.scoped_to_arch(arch_ids).
for_status([BuildList::BUILD_PENDING, BuildList::RERUN_TESTS]).
for_platform(platform_ids).where(user_id: uid).where(builder: nil).oldest.order(:created_at)
if native_arch_ids.empty?
build_lists = BuildList.scoped_to_arch(arch_ids).for_platform(platform_ids).
where(native_build: false)
else
sql_normal = []
params = []
sql_normal << 'arch_id IN (?)' if !arch_ids.empty?
params << arch_ids if !arch_ids.empty?
sql_normal << 'platform_id IN (?)' if !platform_ids.empty?
params << platform_ids if !platform_ids.empty?
sql_normal << 'native_build=false'
sql_normal *= ' AND '
sql_native_arch = 'arch_id IN (?)'
params << native_arch_ids
sql_native_arch << ' AND platform_id IN (?)' if !platform_ids.empty?
params << platform_ids if !platform_ids.empty?
sql_native_arch << ' AND native_build=true'
build_lists = BuildList.where(sql_normal + ' OR ' + sql_native_arch, *params)
end
build_lists = build_lists.for_status([BuildList::BUILD_PENDING, BuildList::RERUN_TESTS]).
where(user_id: uid).where(builder: nil).oldest.order(:created_at)
if current_user.system?
@build_list = build_lists.where(external_nodes: ["", nil]).first
@build_list ||= build_lists.external_nodes(:everything).first
@ -101,6 +118,16 @@ class Api::V1::JobsController < Api::V1::BaseController
end
end
def native_arch_ids
@native_arch_ids ||= begin
arches = params[:arches].to_s.split(',')
native_arches = params[:native_arches].to_s.split(',')
native_arches &= arches if !arches.empty?
puts native_arches
native_arches.present? ? Arch.where(name: native_arches).pluck(:id) : []
end
end
def set_builder
return unless @build_list
@build_list.builder = current_user

View File

@ -3,6 +3,7 @@ class Projects::ProjectsController < Projects::BaseController
include ProjectsHelper
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:commit, :diff]
before_action :who_owns, only: [:new, :create, :mass_import, :run_mass_import]
def index

View File

@ -4,25 +4,17 @@ module Project::GithubApi
extend ActiveSupport::Concern
def github_data
Github.repos.get user: github_get_organization, repo: name rescue nil
Octokit.repo github_get_organization + '/' + name rescue nil
end
def github_branches
Github.repos.branches user: github_get_organization, repo: name rescue nil
Octokit.branches github_get_organization + '/' + name rescue []
end
def github_tags
Github.repos.tags user: github_get_organization, repo: name rescue nil
Octokit.tags github_get_organization + '/' + name rescue []
end
def find_blob_and_raw_of_spec_file(project_version)
end
def update_file(path, data, options = {})
end
def github_get_organization
return github_organization if github_organization.presence
APP_CONFIG['github_organization']

View File

@ -97,7 +97,6 @@ class MassBuild < ActiveRecord::Base
if increase_rt
inc_rt_sem = Redis::Semaphore.new(:increase_release_tag_lock)
inc_rt_sem.lock
ratelimit_remaining = Github_blobs_api.ratelimit_remaining
end
projects_list.lines.each do |name|
@ -110,18 +109,11 @@ class MassBuild < ActiveRecord::Base
# Ensures that user has rights to create a build_list
next unless ProjectPolicy.new(user, project).write?
if increase_rt
if ratelimit_remaining <= 1
ratelimit_remaining = Github_blobs_api.ratelimit_remaining
#if that's still less that or equal 1
if ratelimit_remaining <= 1
#just to make sure it really resets wait additional 5 seconds
ratelimit_reset_wait = Github_blobs_api.ratelimit_reset - Time.now.to_i + 5
sleep ratelimit_reset_wait
ratelimit_remaining = Github_blobs_api.ratelimit_remaining
end
ratelimit = Github_blobs_api.ratelimit
if ratelimit.remaining <= 1
sleep ratelimit.resets_in
end
count = project.increase_release_tag(project_version, "MassBuild##{id}: Increase release tag")
ratelimit_remaining -= count
project.increase_release_tag(project_version, "MassBuild##{id}: Increase release tag")
end
arches_list.each do |arch|
rep_id = (project.repository_ids & save_to_platform.repository_ids).first

View File

@ -216,13 +216,14 @@ class Project < ActiveRecord::Base
end
def increase_release_tag(project_version, message)
file = Github_blobs_api.get github_get_organization, name, '/' + name + '.spec', ref: project_version rescue return 1
decoded_content = Base64.decode64(file.content)
new_content = Project.replace_release_tag decoded_content
return 1 if new_content == decoded_content
Github_blobs_api.update github_get_organization, name, '/' + name + '.spec', path: '/' + name + '.spec',\
message: message, content: new_content, sha: file.sha rescue return 2
return 2
file = Github_blobs_api.contents github_get_organization + '/' + name, path: '/' + name + '.spec', ref: project_version rescue nil
if file
decoded_content = Base64.decode64(file.content)
new_content = Project.replace_release_tag decoded_content
return if new_content == decoded_content
Github_blobs_api.update_contents github_get_organization + '/' + name, '/' + name + '.spec',\
message, file.sha, new_content, branch: project_version rescue nil
end
end
protected

View File

@ -68,6 +68,7 @@ class BuildListPolicy < ApplicationPolicy
include_testing_subrepository
project_id
project_version
native_build
save_buildroot
save_to_platform_id
save_to_repository_id

View File

@ -22,7 +22,7 @@ h4.offset10= t("activerecord.attributes.build_list.preferences")
name= 'build_list[auto_create_container]' ]
= BuildList.human_attribute_name :auto_create_container
- %i(include_testing_subrepository use_cached_chroot use_extra_tests save_buildroot).each do |kind|
- %i(include_testing_subrepository use_cached_chroot use_extra_tests save_buildroot native_build).each do |kind|
.checkbox
label
- checked = params[:build_list].try(:[], kind)

View File

@ -20,7 +20,7 @@ Rails.application.configure do
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 10.minutes }
config.cache_store = :redis_store, 'redis://localhost:6379/0', { expires_in: 10.minutes }
# Do not eager load code on boot.
config.eager_load = false

View File

@ -52,7 +52,7 @@ Rails.application.configure do
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
config.cache_store = :redis_store, (ENV["REDIS_URL"].to_s + '/cache'), { expires_in: 10.minutes }
config.cache_store = :redis_store, (ENV["REDIS_URL"].to_s), { expires_in: 10.minutes }
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"

View File

@ -45,9 +45,6 @@ Devise.setup do |config|
# Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
config.http_authenticatable = true
# If http headers should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true

View File

@ -1,9 +1,14 @@
#configuration of Github api gem
Github.configure do |c|
c.basic_auth = ENV["GITHUB_LOGIN"] + ":" + ENV["GITHUB_PASSWORD"]
c.auto_pagination = true
end
Github_blobs_api = Octokit::Client.new(login: ENV['GITHUB_REPO_BOT_LOGIN'], password: ENV['GITHUB_REPO_BOT_PASSWORD'])
#for updating repo contents
Github_blobs_api = Github::Client::Repos::Contents.new(basic_auth: ENV['GITHUB_REPO_BOT_LOGIN'] + ":" + ENV['GITHUB_REPO_BOT_PASSWORD'])
Octokit.configure do |c|
c.login = ENV["GITHUB_LOGIN"]
c.password = ENV["GITHUB_PASSWORD"]
end
Octokit.middleware = Faraday::RackBuilder.new do |builder|
store = ActiveSupport::Cache.lookup_store(:redis_store, ENV['REDIS_URL'].to_s + '/1')
builder.use Faraday::HttpCache, store: store, shared_cache: false
builder.use Octokit::Response::RaiseError
builder.adapter Faraday.default_adapter
end

View File

@ -1,3 +1,3 @@
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_rosa_session'
Rails.application.config.session_store :cookie_store, key: '_abf_session'

View File

@ -12,6 +12,7 @@ en:
extra_mass_builds: Extra mass builds
auto_create_container: Create container automatically
use_cached_chroot: Use cached chroot
native_build: Native build
use_extra_tests: Use extra tests
save_buildroot: Save RPM build root
container_path: Container path

View File

@ -15,6 +15,7 @@ ru:
use_extra_tests: Использовать дополнительные тесты
save_buildroot: Сохранить RPM build root
container_path: Путь до контейнера
native_build: Нативная сборка
status: Статус
project_id: Проект
project: Проект

View File

@ -0,0 +1,5 @@
class AddNativeBuildToBuildLists < ActiveRecord::Migration
def change
add_column :build_lists, :native_build, :boolean, default: false
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160323122230) do
ActiveRecord::Schema.define(version: 20160326104007) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -112,6 +112,7 @@ ActiveRecord::Schema.define(version: 20160323122230) do
t.boolean "save_buildroot", default: false, null: false
t.string "hostname"
t.string "fail_reason"
t.boolean "native_build", default: false
end
add_index "build_lists", ["project_id", "save_to_repository_id", "build_for_platform_id", "arch_id"], name: "maintainer_search_index"