Remove stuff

This commit is contained in:
Wedge 2021-03-02 16:05:57 +03:00
parent 129212129b
commit f1f6d7e7ac
11 changed files with 0 additions and 231 deletions

View File

@ -1,31 +0,0 @@
class Platforms::KeyPairsController < Platforms::BaseController
before_action :authenticate_user!
def index
@key_pair = KeyPair.new
end
def create
@key_pair = KeyPair.new subject_params(KeyPair)
@key_pair.user_id = current_user.id
authorize @key_pair
if @key_pair.save
flash[:notice] = t('flash.key_pairs.saved')
redirect_to platform_key_pairs_path(@key_pair.repository.platform) and return
else
flash[:error] = t('flash.key_pairs.save_error')
end
render :index
end
def destroy
authorize @key_pair = @platform.key_pairs.find(params[:id])
if @key_pair.destroy
flash[:notice] = t('flash.key_pairs.destroyed')
else
flash[:error] = t('flash.key_pairs.destroy_error')
end
redirect_to platform_key_pairs_path(@key_pair.repository.platform)
end
end

View File

@ -1,60 +0,0 @@
module FacebookHelper
# Returns a facebook-specific image for the current page.
def facebook_meta_image
resource = get_resource
@fb_meta_image ||= avatar_url(resource, :big) if resource.respond_to?(:avatar)
@fb_meta_image ||= asset_url('fb-image.png')
@fb_meta_image
end
# Returns a facebook-specific URL for the current page.
def facebook_meta_url
@fb_meta_url ||= fb_like_url(get_resource)
end
# Returns the facebook application id.
def facebook_meta_app_id
APP_CONFIG['keys']['facebook']['id']
end
# Returns the facebook site name - used for the site:og_name meta tag.
def facebook_site_name
APP_CONFIG['project_name']
end
# Creates a 'like' URL for the given object instance.
def fb_like_url(object=nil)
# All likes for resources go to referrers#like, which redirects them
# to the appropriate target.
begin
# Make sure we're using the correct domain. This should happen automatically,
# but is a bit flaky in cucumber so set it explicitly to be safe.
#domain = current_site.present? ? current_site.domain : request.host
url = object.respond_to?(:fb_like_url) ?
object.fb_like_url : polymorphic_url(object)#, host: domain)
rescue
end if object
url ||= request.url
# Clean up unnecessary params
url.gsub!(/\?.*/, '')
url << "?page=#{params[:page]}" if params[:page].to_i > 1
url
end
protected
# Gets the current resource.
def get_resource
case controller
when Groups::BaseController
@group
when Users::BaseController
@user
else
instance_variable_get "@#{controller_name.singularize}"
end
end
end

View File

@ -1,81 +0,0 @@
require 'open3'
class KeyPair < ActiveRecord::Base
belongs_to :repository
belongs_to :user
attr_accessor :fingerprint
attr_encrypted :secret, key: APP_CONFIG['keys']['key_pair_secret_key']
validates :repository, :user, presence: true
validates :secret, :public, presence: true, length: { maximum: 10000 }, on: :create
validates :repository_id, uniqueness: { message: I18n.t("activerecord.errors.key_pair.repo_key_exists") }
validate :check_keys
before_create { |record| record.key_id = @fingerprint }
after_create { |record| record.repository.resign }
protected
def check_keys
dir = Dir.mktmpdir 'keys-', APP_CONFIG['tmpfs_path']
begin
%w(pubring secring).each do |kind|
filename = "#{dir}/#{kind}"
open("#{filename}.txt", "w") { |f| f.write self.send(kind == 'pubring' ? :public : :secret) }
system "gpg --homedir #{dir} --dearmor < #{filename}.txt > #{filename}.gpg"
end
public_key = get_info_of_key "#{dir}/pubring.gpg"
secret_key = get_info_of_key "#{dir}/secring.gpg"
if correct_key?(public_key, :public) & correct_key?(secret_key, :secret)
if public_key[:fingerprint] != secret_key[:fingerprint]
errors.add :secret, I18n.t('activerecord.errors.key_pair.wrong_keys')
else
stdin, stdout, stderr = Open3.popen3("echo '\n\n\n\n\nsave' | LC_ALL=en gpg --command-fd 0 --homedir #{dir} --edit-key #{secret_key[:keyid]} passwd")
output = stderr.read
if output =~ /Invalid\spassphrase/
errors.add :secret, I18n.t('activerecord.errors.key_pair.key_has_passphrase')
else
@fingerprint = secret_key[:fingerprint]
end
end
end
ensure
# remove the directory.
FileUtils.remove_entry_secure dir
end
end
def correct_key?(info, field)
if info.empty? || info[:type].blank? || info[:fingerprint].blank? || info[:keyid].blank?
errors.add field, I18n.t('activerecord.errors.key_pair.wrong_key')
return false
else
if info[:type] != field
errors.add field, I18n.t("activerecord.errors.key_pair.wrong_#{field}_key")
return false
end
end
return true
end
def get_info_of_key(file_path)
results = {}
str = %x[ gpg --with-fingerprint #{file_path} | sed -n 1,2p]
info = str.strip.split("\n")
if info.size == 2
results[:fingerprint] = info[1].gsub(/.*\=/, '').strip.gsub(/\s/, ':')
results[:type] = info[0] =~ /^pub\s/ ? :public : nil
results[:type] ||= info[0] =~ /^sec\s/ ? :secret : nil
if keyid = info[0].match(/\/[\w]+\s/)
results[:keyid] = keyid[0].strip[1..-1]
end
end
return results
end
end

View File

@ -34,7 +34,6 @@ class Platform < ActiveRecord::Base
belongs_to :owner, polymorphic: true belongs_to :owner, polymorphic: true
has_many :repositories, dependent: :destroy has_many :repositories, dependent: :destroy
has_many :key_pairs, through: :repositories
has_many :projects, through: :repositories has_many :projects, through: :repositories
has_many :products, dependent: :destroy has_many :products, dependent: :destroy

View File

@ -35,8 +35,6 @@ class User < Avatar
has_many :own_groups, foreign_key: :owner_id, class_name: 'Group', dependent: :destroy has_many :own_groups, foreign_key: :owner_id, class_name: 'Group', dependent: :destroy
has_many :own_platforms, as: :owner, class_name: 'Platform', dependent: :destroy has_many :own_platforms, as: :owner, class_name: 'Platform', dependent: :destroy
has_many :key_pairs
validates :uname, presence: true, validates :uname, presence: true,
uniqueness: { case_sensitive: false }, uniqueness: { case_sensitive: false },
format: { with: /\A#{NAME_REGEXP.source}\z/ }, format: { with: /\A#{NAME_REGEXP.source}\z/ },

View File

@ -28,8 +28,3 @@
- if policy(@platform).local_admin_manage? - if policy(@platform).local_admin_manage?
li class=('active' if act == :members && contr == :platforms) li class=('active' if act == :members && contr == :platforms)
= link_to t("layout.platforms.members"), members_platform_path(@platform) = link_to t("layout.platforms.members"), members_platform_path(@platform)
/ - if policy(@platform).edit?
/ li class=('active' if contr == :key_pairs)
/ = link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform)
/ li class=('active' if contr == :tokens)
/ = link_to t('layout.tokens.header'), platform_tokens_path(@platform)

View File

@ -1,18 +0,0 @@
table.table.table-striped
thead
tr
th= t("activerecord.attributes.key_pair.repository_id")
th= t("activerecord.attributes.key_pair.key_id")
th= t("activerecord.attributes.key_pair.user_id")
th= t("layout.delete")
tbody
- @platform.repositories.each do |repository|
- if repository.key_pair
tr
td= repository.name
td= repository.key_pair.key_id
td= link_to repository.key_pair.user.fullname, user_path(repository.key_pair.user)
td.buttons
- if policy(repository.key_pair).destroy?
= link_to platform_key_pair_path(@platform, repository.key_pair), method: :delete, data: { confirm: t("layout.key_pairs.confirm_delete") } do
span.glyphicon.glyphicon-remove

View File

@ -1,9 +0,0 @@
h3
= t("layout.key_pairs.header")
= simple_form_for @key_pair, url: platform_key_pairs_path(@platform) do |f|
= f.input :public, as: :text
= f.input :secret, as: :text
= f.input :repository_id, collection: key_pair_repository_options(@platform)
= submit_button_tag

View File

@ -1,9 +0,0 @@
- set_meta_tags title: [title_object(@platform), t('layout.key_pairs.header')]
= render 'platforms/base/submenu'
.container.col-md-offset-2.col-md-8
.row
- if policy(@platform).edit?
= render 'new'
hr
= render 'list'

View File

@ -1,14 +0,0 @@
/ link rel='canonical' href=facebook_meta_url
/ meta property='og:title' content=facebook_meta_title
/ meta property='og:type' content='website'
/ meta property='og:url' content=facebook_meta_url
/ meta property='og:image' content=facebook_meta_image
/ meta property='og:site_name' content=facebook_site_name
/ meta property='fb:app_id' content=facebook_meta_app_id
/ meta property='og:description' content=facebook_meta_description
/ meta name='Description' content=facebook_meta_description
/ meta property='twitter:card' content='summary'
/ meta property='twitter:site' content='@abf_io'
/ meta property='twitter:image' content=facebook_meta_image
/ meta property='twitter:url' content=facebook_meta_url

View File

@ -174,7 +174,6 @@ Rails.application.routes.draw do
put :sync_lock_file put :sync_lock_file
end end
end end
resources :key_pairs, only: [:create, :index, :destroy]
resources :tokens, only: [:create, :index, :show, :new] do resources :tokens, only: [:create, :index, :show, :new] do
member do member do
post :withdraw post :withdraw