2020-11-23 15:35:03 +08:00
|
|
|
|
# == Schema Information
|
|
|
|
|
|
#
|
|
|
|
|
|
# Table name: ci_cloud_accounts
|
|
|
|
|
|
#
|
2020-12-30 13:47:00 +08:00
|
|
|
|
# id :integer not null, primary key
|
|
|
|
|
|
# user_id :integer not null
|
|
|
|
|
|
# ip_num :integer
|
|
|
|
|
|
# account :string(255)
|
|
|
|
|
|
# secret :string(255)
|
|
|
|
|
|
# created_at :datetime not null
|
|
|
|
|
|
# updated_at :datetime not null
|
|
|
|
|
|
# ci_user_id :integer
|
|
|
|
|
|
# server_type :integer default("0")
|
2020-11-23 15:35:03 +08:00
|
|
|
|
#
|
|
|
|
|
|
# Indexes
|
|
|
|
|
|
#
|
|
|
|
|
|
# dev_ops_cloud_accounts_p_u_ip (user_id,ip_num)
|
|
|
|
|
|
#
|
|
|
|
|
|
|
2020-08-21 10:46:37 +08:00
|
|
|
|
class Ci::CloudAccount < Ci::LocalBase
|
2020-07-10 14:08:16 +08:00
|
|
|
|
belongs_to :user
|
2020-09-10 10:53:12 +08:00
|
|
|
|
belongs_to :ci_user, class_name: 'Ci::User', foreign_key: :ci_user_id, optional: true
|
2020-07-10 14:08:16 +08:00
|
|
|
|
|
2020-12-18 13:14:30 +08:00
|
|
|
|
# server_type column: 0: 自有服务器;1: trustie提供服务器
|
|
|
|
|
|
SERVER_TYPE_SELF = 0
|
|
|
|
|
|
SERVER_TYPE_TRUSTIE = 1
|
|
|
|
|
|
|
2020-07-10 14:08:16 +08:00
|
|
|
|
def drone_host
|
|
|
|
|
|
[drone_ip, ":80"].join
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def drone_ip
|
|
|
|
|
|
IPAddr.new(self.ip_num, Socket::AF_INET).to_s
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def drone_url
|
2020-08-21 10:46:37 +08:00
|
|
|
|
["http://", self.drone_host].join
|
2020-07-10 14:08:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def visible_secret
|
|
|
|
|
|
Base64.decode64(secret)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.encrypted_secret(str)
|
|
|
|
|
|
Base64.encode64(str.strip).gsub(/\n/, '')
|
|
|
|
|
|
end
|
2020-07-14 15:06:09 +08:00
|
|
|
|
|
2020-09-04 17:35:29 +08:00
|
|
|
|
def authenticate_url
|
|
|
|
|
|
[drone_url, '/login'].join
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2020-07-10 14:08:16 +08:00
|
|
|
|
end
|