-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
802 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'redis' | ||
|
||
module Travis::API::V3 | ||
class Models::Storage | ||
|
||
attr_reader :id, :value | ||
|
||
def initialize(attrs) | ||
puts "ATTRS: #{attrs.inspect}" | ||
@id = attrs.fetch(:id) | ||
@value = attrs[:value] | ||
end | ||
|
||
def public? | ||
true | ||
end | ||
|
||
def get | ||
puts "ID: #{id.inspect}, VAL: #{value.inspect}" | ||
@value = Travis.redis.get(id) || 0 | ||
|
||
|
||
puts "ID: #{id.inspect}, VAL: #{value.inspect}" | ||
self | ||
end | ||
|
||
def create | ||
Travis.redis.set(id, value) | ||
self | ||
end | ||
|
||
def delete | ||
Travis.redis.del(id) | ||
@value = 0 | ||
self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Travis::API::V3 | ||
class Queries::Storage < Query | ||
params :user, :id,:value, prefix: :storage | ||
|
||
PERMITTED_OPTIONS = [:billing_wizard_state] | ||
|
||
def find | ||
Models::Storage.new(id: option_id).get if valid? | ||
end | ||
|
||
def update | ||
Models::Storage.new(id: option_id, value: value).create if valid? | ||
end | ||
|
||
def delete | ||
Models::Storage.new(id: option_id).delete if valid? | ||
end | ||
|
||
private | ||
def option_id | ||
"#{user}::storage::#{id}" | ||
end | ||
|
||
def valid? | ||
PERMITTED_OPTIONS.include? id.to_sym | ||
end | ||
|
||
|
||
def user | ||
params['user.id'] | ||
end | ||
|
||
def id | ||
params['id'] | ||
end | ||
|
||
def value | ||
params['value'] | ||
end | ||
|
||
def redis | ||
Travis.redis | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Travis::API::V3 | ||
class RecaptchaClient | ||
class ConfigurationError < StandardError; end | ||
|
||
def verify(token) | ||
response = connection.post('/recaptcha/api/siteverify') do |req| | ||
req.headers['Content-Type'] = 'application/x-www-form-urlencoded' | ||
req.body = URI.encode_www_form({ secret: recaptcha_secret, response: token }) | ||
end | ||
handle_errors_and_respond(response) { |r| r['success'] } | ||
end | ||
|
||
private | ||
|
||
def handle_errors_and_respond(response) | ||
case response.status | ||
when 200, 201 | ||
yield(JSON.parse(response.body)) if block_given? | ||
when 204 | ||
true | ||
else | ||
raise Travis::API::V3::ServerError, 'ReCaptcha system error' | ||
end | ||
end | ||
|
||
def connection | ||
@connection ||= Faraday.new(url: recaptcha_url, ssl: { ca_path: '/usr/lib/ssl/certs' }) do |conn| | ||
conn.use OpenCensus::Trace::Integrations::FaradayMiddleware if Travis::Api::App::Middleware::OpenCensus.enabled? | ||
conn.adapter Faraday.default_adapter | ||
end | ||
end | ||
|
||
def recaptcha_url | ||
Travis.config.recaptcha.endpoint || raise(ConfigurationError, 'No recaptcha url configured') | ||
end | ||
|
||
def recaptcha_secret | ||
Travis.config.recaptcha.secret || raise(ConfigurationError, 'No recaptcha secret configured') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module Travis::API::V3 | ||
class Renderer::Allowance < ModelRenderer | ||
representation(:minimal, :id) | ||
representation(:standard, :subscription_type, :public_repos, :private_repos, :concurrency_limit, :user_usage, :pending_user_licenses, :id) | ||
representation(:standard, :subscription_type, :public_repos, :private_repos, :concurrency_limit, :user_usage, :pending_user_licenses, | ||
:payment_changes_block_credit, :payment_changes_block_captcha, :credit_card_block_duration, :captcha_block_duration, :id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Travis::API::V3 | ||
class Renderer::Storage < ModelRenderer | ||
representation(:standard,:id, :value) | ||
|
||
def id | ||
model.id.split('::')&.last || id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.