A partir del 1 de octubre vamos a activar 2FA a todas las cuentas de esta instancia de Gitlab. No obstante, se recomienda activarlo cuanto antes para garantizar la seguridad de vuestra cuenta. Podeis hacerlo siguiendo las indicaciones del enlace.

As of October 1, we are going to enable 2FA to all accounts in this Gitlab instance. However, it is recommended to enable it as soon as possible to guarantee the security of your account. You can do it by following the instructions in the link.

https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html#one-time-password

Commit d7ec5f8e authored by Alonso Ibarra, Juncal's avatar Alonso Ibarra, Juncal
Browse files

Added final releases for all the DECIDE tools

parent dd2fb5aa
[submodule "statemachine"]
path = statemachine
url = https://git.code.tecnalia.com/decide/statemachine.git
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<Settings><!--This file was automatically generated by Ruby plugin.
You are allowed to:
1. Reorder generators
2. Remove generators
3. Add installed generators
To add new installed generators automatically delete this file and reload the project.
--><GeneratorsGroup><Generator name="active_record:migration" /><Generator name="active_record:model" /><Generator name="active_record:observer" /><Generator name="active_record:session_migration" /><Generator name="controller" /><Generator name="erb:controller" /><Generator name="erb:mailer" /><Generator name="erb:scaffold" /><Generator name="generator" /><Generator name="helper" /><Generator name="integration_test" /><Generator name="mailer" /><Generator name="metal" /><Generator name="migration" /><Generator name="model" /><Generator name="model_subclass" /><Generator name="observer" /><Generator name="performance_test" /><Generator name="plugin" /><Generator name="resource" /><Generator name="scaffold" /><Generator name="scaffold_controller" /><Generator name="session_migration" /><Generator name="stylesheets" /><Generator name="test_unit:controller" /><Generator name="test_unit:helper" /><Generator name="test_unit:integration" /><Generator name="test_unit:mailer" /><Generator name="test_unit:model" /><Generator name="test_unit:observer" /><Generator name="test_unit:performance" /><Generator name="test_unit:plugin" /><Generator name="test_unit:scaffold" /></GeneratorsGroup></Settings>
--><GeneratorsGroup><Generator name="active_record:application_record" /><Generator name="application_record" /><Generator name="assets" /><Generator name="bootstrap:install" /><Generator name="bootstrap:layout" /><Generator name="bootstrap:partial" /><Generator name="bootstrap:themed" /><Generator name="channel" /><Generator name="coffee:assets" /><Generator name="controller" /><Generator name="delayed_job" /><Generator name="delayed_job:active_record" /><Generator name="delayed_job:upgrade" /><Generator name="erb:controller" /><Generator name="erb:mailer" /><Generator name="erb:scaffold" /><Generator name="generator" /><Generator name="haml:application_layout" /><Generator name="helper" /><Generator name="integration_test" /><Generator name="jbuilder" /><Generator name="job" /><Generator name="js:assets" /><Generator name="less:assets" /><Generator name="mailer" /><Generator name="migration" /><Generator name="model" /><Generator name="resource" /><Generator name="rspec:controller" /><Generator name="rspec:feature" /><Generator name="rspec:helper" /><Generator name="rspec:install" /><Generator name="rspec:integration" /><Generator name="rspec:job" /><Generator name="rspec:mailer" /><Generator name="rspec:model" /><Generator name="rspec:observer" /><Generator name="rspec:request" /><Generator name="rspec:scaffold" /><Generator name="rspec:view" /><Generator name="scaffold" /><Generator name="scaffold_controller" /><Generator name="system_test" /><Generator name="task" /><Generator name="test_unit:controller" /><Generator name="test_unit:generator" /><Generator name="test_unit:helper" /><Generator name="test_unit:integration" /><Generator name="test_unit:job" /><Generator name="test_unit:mailer" /><Generator name="test_unit:model" /><Generator name="test_unit:plugin" /><Generator name="test_unit:scaffold" /><Generator name="test_unit:system" /></GeneratorsGroup></Settings>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<Settings><!--This file was automatically generated by Ruby plugin.
You are allowed to:
1. Remove rake task
2. Add existing rake tasks
To add existing rake tasks automatically delete this file and reload the project.
--><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="List versions of all Rails frameworks and the environment" fullCmd="about" taksId="about" /><RakeGroup description="" fullCmd="" taksId="active_storage"><RakeTask description="Copy over the migration needed to the application" fullCmd="active_storage:install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="" fullCmd="active_storage:install:migrations" taksId="migrations" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="app"><RakeTask description="Applies the template supplied by LOCATION=(/path/to/template) or URL" fullCmd="app:template" taksId="template" /><RakeTask description="Update configs and some other initially generated files (or use just update:configs or update:bin)" fullCmd="app:update" taksId="update" /><RakeGroup description="" fullCmd="" taksId="templates"><RakeTask description="" fullCmd="app:templates:copy" taksId="copy" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="update"><RakeTask description="" fullCmd="app:update:bin" taksId="bin" /><RakeTask description="" fullCmd="app:update:configs" taksId="configs" /><RakeTask description="" fullCmd="app:update:upgrade_guide_info" taksId="upgrade_guide_info" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="assets"><RakeTask description="Remove old compiled assets" fullCmd="assets:clean[keep]" taksId="clean[keep]" /><RakeTask description="Remove compiled assets" fullCmd="assets:clobber" taksId="clobber" /><RakeTask description="Load asset compile environment" fullCmd="assets:environment" taksId="environment" /><RakeTask description="Compile all the assets named in config.assets.precompile" fullCmd="assets:precompile" taksId="precompile" /><RakeTask description="" fullCmd="assets:clean" taksId="clean" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="cache_digests"><RakeTask description="Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)" fullCmd="cache_digests:dependencies" taksId="dependencies" /><RakeTask description="Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)" fullCmd="cache_digests:nested_dependencies" taksId="nested_dependencies" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="db"><RakeTask description="Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases" fullCmd="db:create" taksId="create" /><RakeTask description="Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to dropping the development and test databases" fullCmd="db:drop" taksId="drop" /><RakeGroup description="" fullCmd="" taksId="environment"><RakeTask description="Set the environment value for the database" fullCmd="db:environment:set" taksId="set" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="fixtures"><RakeTask description="Loads fixtures into the current environment's database" fullCmd="db:fixtures:load" taksId="load" /><RakeTask description="" fullCmd="db:fixtures:identify" taksId="identify" /></RakeGroup><RakeTask description="Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)" fullCmd="db:migrate" taksId="migrate" /><RakeGroup description="" fullCmd="" taksId="migrate"><RakeTask description="Display status of migrations" fullCmd="db:migrate:status" taksId="status" /><RakeTask description="" fullCmd="db:migrate:down" taksId="down" /><RakeTask description="" fullCmd="db:migrate:redo" taksId="redo" /><RakeTask description="" fullCmd="db:migrate:reset" taksId="reset" /><RakeTask description="" fullCmd="db:migrate:up" taksId="up" /></RakeGroup><RakeTask description="Rolls the schema back to the previous version (specify steps w/ STEP=n)" fullCmd="db:rollback" taksId="rollback" /><RakeGroup description="" fullCmd="" taksId="schema"><RakeGroup description="" fullCmd="" taksId="cache"><RakeTask description="Clears a db/schema_cache.yml file" fullCmd="db:schema:cache:clear" taksId="clear" /><RakeTask description="Creates a db/schema_cache.yml file" fullCmd="db:schema:cache:dump" taksId="dump" /></RakeGroup><RakeTask description="Creates a db/schema.rb file that is portable against any DB supported by Active Record" fullCmd="db:schema:dump" taksId="dump" /><RakeTask description="Loads a schema.rb file into the database" fullCmd="db:schema:load" taksId="load" /><RakeTask description="" fullCmd="db:schema:load_if_ruby" taksId="load_if_ruby" /></RakeGroup><RakeTask description="Loads the seed data from db/seeds.rb" fullCmd="db:seed" taksId="seed" /><RakeTask description="Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)" fullCmd="db:setup" taksId="setup" /><RakeGroup description="" fullCmd="" taksId="structure"><RakeTask description="Dumps the database structure to db/structure.sql" fullCmd="db:structure:dump" taksId="dump" /><RakeTask description="Recreates the databases from the structure.sql file" fullCmd="db:structure:load" taksId="load" /><RakeTask description="" fullCmd="db:structure:load_if_sql" taksId="load_if_sql" /></RakeGroup><RakeTask description="Retrieves the current schema version number" fullCmd="db:version" taksId="version" /><RakeTask description="" fullCmd="db:_dump" taksId="_dump" /><RakeTask description="" fullCmd="db:abort_if_pending_migrations" taksId="abort_if_pending_migrations" /><RakeTask description="" fullCmd="db:charset" taksId="charset" /><RakeTask description="" fullCmd="db:check_protected_environments" taksId="check_protected_environments" /><RakeTask description="" fullCmd="db:collation" taksId="collation" /><RakeGroup description="" fullCmd="" taksId="create"><RakeTask description="" fullCmd="db:create:all" taksId="all" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="drop"><RakeTask description="" fullCmd="db:drop:_unsafe" taksId="_unsafe" /><RakeTask description="" fullCmd="db:drop:all" taksId="all" /></RakeGroup><RakeTask description="" fullCmd="db:forward" taksId="forward" /><RakeTask description="" fullCmd="db:load_config" taksId="load_config" /><RakeTask description="" fullCmd="db:purge" taksId="purge" /><RakeGroup description="" fullCmd="" taksId="purge"><RakeTask description="" fullCmd="db:purge:all" taksId="all" /></RakeGroup><RakeTask description="" fullCmd="db:reset" taksId="reset" /><RakeGroup description="" fullCmd="" taksId="test"><RakeTask description="" fullCmd="db:test:load" taksId="load" /><RakeTask description="" fullCmd="db:test:load_schema" taksId="load_schema" /><RakeTask description="" fullCmd="db:test:load_structure" taksId="load_structure" /><RakeTask description="" fullCmd="db:test:prepare" taksId="prepare" /><RakeTask description="" fullCmd="db:test:purge" taksId="purge" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="dev"><RakeTask description="Toggle development mode caching on/off" fullCmd="dev:cache" taksId="cache" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="haml"><RakeTask description="Convert html.erb to html.haml each file in app/views" fullCmd="haml:erb2haml" taksId="erb2haml" /></RakeGroup><RakeTask description="Print out all defined initializers in the order they are invoked by Rails" fullCmd="initializers" taksId="initializers" /><RakeGroup description="" fullCmd="" taksId="jobs"><RakeTask description="Exit with error status if any jobs older than max_age seconds haven't been attempted yet" fullCmd="jobs:check[max_age]" taksId="check[max_age]" /><RakeTask description="Clear the delayed_job queue" fullCmd="jobs:clear" taksId="clear" /><RakeTask description="Start a delayed_job worker" fullCmd="jobs:work" taksId="work" /><RakeTask description="Start a delayed_job worker and exit when all available jobs are complete" fullCmd="jobs:workoff" taksId="workoff" /><RakeTask description="" fullCmd="jobs:check" taksId="check" /><RakeTask description="" fullCmd="jobs:environment_options" taksId="environment_options" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="log"><RakeTask description="Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)" fullCmd="log:clear" taksId="clear" /></RakeGroup><RakeTask description="Prints out your Rack middleware stack" fullCmd="middleware" taksId="middleware" /><RakeTask description="Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)" fullCmd="notes" taksId="notes" /><RakeGroup description="" fullCmd="" taksId="notes"><RakeTask description="Enumerate a custom annotation, specify with ANNOTATION=CUSTOM" fullCmd="notes:custom" taksId="custom" /><RakeTask description="" fullCmd="notes:fixme" taksId="fixme" /><RakeTask description="" fullCmd="notes:optimize" taksId="optimize" /><RakeTask description="" fullCmd="notes:todo" taksId="todo" /></RakeGroup><RakeTask description="Restart app by touching tmp/restart.txt" fullCmd="restart" taksId="restart" /><RakeTask description="Print out all defined routes in match order, with names" fullCmd="routes" taksId="routes" /><RakeTask description="Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)" fullCmd="secret" taksId="secret" /><RakeGroup description="" fullCmd="" taksId="seeds_for_testing"><RakeTask description="generating few records in db for testing feature - generating pdf" fullCmd="seeds_for_testing:task1" taksId="task1" /></RakeGroup><RakeTask description="Report code statistics (KLOCs, etc) from the application or engine" fullCmd="stats" taksId="stats" /><RakeGroup description="" fullCmd="" taksId="time"><RakeTask description="List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)" fullCmd="time:zones[country_or_offset]" taksId="zones[country_or_offset]" /><RakeTask description="" fullCmd="time:zones" taksId="zones" /><RakeGroup description="" fullCmd="" taksId="zones"><RakeTask description="" fullCmd="time:zones:all" taksId="all" /><RakeTask description="" fullCmd="time:zones:local" taksId="local" /><RakeTask description="" fullCmd="time:zones:us" taksId="us" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="tmp"><RakeTask description="Clear cache, socket and screenshot files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear, tmp:screenshots:clear)" fullCmd="tmp:clear" taksId="clear" /><RakeTask description="Creates tmp directories for cache, sockets, and pids" fullCmd="tmp:create" taksId="create" /><RakeGroup description="" fullCmd="" taksId="cache"><RakeTask description="" fullCmd="tmp:cache:clear" taksId="clear" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="pids"><RakeTask description="" fullCmd="tmp:pids:clear" taksId="clear" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="screenshots"><RakeTask description="" fullCmd="tmp:screenshots:clear" taksId="clear" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="sockets"><RakeTask description="" fullCmd="tmp:sockets:clear" taksId="clear" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="webdrivers"><RakeGroup description="" fullCmd="" taksId="chromedriver"><RakeTask description="Force remove chromedriver" fullCmd="webdrivers:chromedriver:remove" taksId="remove" /><RakeTask description="Remove and download updated chromedriver if necessary" fullCmd="webdrivers:chromedriver:update[version]" taksId="update[version]" /><RakeTask description="Print current chromedriver version" fullCmd="webdrivers:chromedriver:version" taksId="version" /><RakeTask description="" fullCmd="webdrivers:chromedriver:update" taksId="update" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="edgedriver"><RakeTask description="Force remove edgedriver" fullCmd="webdrivers:edgedriver:remove" taksId="remove" /><RakeTask description="Remove and download updated edgedriver if necessary" fullCmd="webdrivers:edgedriver:update[version]" taksId="update[version]" /><RakeTask description="Print current edgedriver version" fullCmd="webdrivers:edgedriver:version" taksId="version" /><RakeTask description="" fullCmd="webdrivers:edgedriver:update" taksId="update" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="geckodriver"><RakeTask description="Force remove geckodriver" fullCmd="webdrivers:geckodriver:remove" taksId="remove" /><RakeTask description="Remove and download updated geckodriver if necessary" fullCmd="webdrivers:geckodriver:update[version]" taksId="update[version]" /><RakeTask description="Print current geckodriver version" fullCmd="webdrivers:geckodriver:version" taksId="version" /><RakeTask description="" fullCmd="webdrivers:geckodriver:update" taksId="update" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="iedriver"><RakeTask description="Force remove IEDriverServer" fullCmd="webdrivers:iedriver:remove" taksId="remove" /><RakeTask description="Remove and download updated IEDriverServer if necessary" fullCmd="webdrivers:iedriver:update[version]" taksId="update[version]" /><RakeTask description="Print current IEDriverServer version" fullCmd="webdrivers:iedriver:version" taksId="version" /><RakeTask description="" fullCmd="webdrivers:iedriver:update" taksId="update" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="yarn"><RakeTask description="Install all JavaScript dependencies as specified via Yarn" fullCmd="yarn:install" taksId="install" /></RakeGroup><RakeTask description="" fullCmd="environment" taksId="environment" /><RakeGroup description="" fullCmd="" taksId="railties"><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="" fullCmd="railties:install:migrations" taksId="migrations" /></RakeGroup></RakeGroup><RakeTask description="" fullCmd="tmp" taksId="tmp" /><RakeTask description="" fullCmd="tmp/cache" taksId="tmp/cache" /><RakeTask description="" fullCmd="tmp/cache/assets" taksId="tmp/cache/assets" /><RakeTask description="" fullCmd="tmp/pids" taksId="tmp/pids" /><RakeTask description="" fullCmd="tmp/sockets" taksId="tmp/sockets" /></RakeGroup></Settings>
......@@ -3,5 +3,5 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.3.8" project-jdk-type="RUBY_SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.4.1" project-jdk-type="RUBY_SDK" />
</project>
\ No newline at end of file
......@@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ACSmI_billing.iml" filepath="$PROJECT_DIR$/.idea/ACSmI_billing.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
--require spec_helper
2.4.5
\ No newline at end of file
......@@ -18,6 +18,10 @@ gem 'authlogic'
gem 'rest-client'
gem 'attr_encrypted'
gem 'will_paginate'
gem 'vault', '~> 0.1'
gem 'prawn'
gem 'prawn-table'
......@@ -31,6 +35,17 @@ gem 'bootstrap-generators', '~> 3.3.4'
gem 'haml-rails'
gem 'aws-sdk', '~> 3'
gem 'watir'
gem 'webdrivers'
gem 'headless'
gem 'two_captcha'
gem 'money'
gem 'eu_central_bank'
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
......
This diff is collapsed.
......@@ -8,7 +8,7 @@ The below steps should be followed to install this component:
1. Install ruby version 2.4.5 (https://www.ruby-lang.org/en/downloads/ for Windows or rvm.io for Unix). Please make sure ‘ruby -v’ returns the correct version in console.
2. Install dependencies. Go to project folder and run the following: ‘gem install bundler; bundle install’. Wait until all the gems are installed.
3. Please adjust confgiuration in:
- db/seeds.rb - specify your gmail credentials in 'smtp_email' and 'smtp_password' settings in order to enable component's mailing functionality. Also, please set 'billing_component_url' setting to match you billing component installation url.
- db/seeds.rb - specify your gmail credentials in 'smtp_email' and 'smtp_password' settings in order to enable component's mailing functionality. Also, please pay attention to BILLING_COMPONENT_URL environment variable to match you billing component installation url.
- config/initializers/acsmi_ext.rb - for security reasons it is best to update ACSMI_EMAIL and INITIAL_PASSWORD with arbitrary values. Those credentials are to be used by contracting component to make API calls to ACSmI Billing.
4. Create and configure the database. Go to project folder and run the following: ‘rake db:create; rake db:migrate; rake db:seed’
5. Start the server. Run “bin/rails server -b 0.0.0.0 -p 3000 -e development”
......
class Api::V1::UsageRecordsController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :check_user, except: %i[show index]
before_action :http_basic_authenticate, only: %i[index show]
include Exceptions
def created_contract
create_report_for(create_contract_params)
end
def cancelled_contract
create_report_for(cancel_contract_params)
end
def show
errors = validate_usage_records_request
((render json: { errors: errors}, status: 422) && return) unless errors.blank?
usage_record = UsageRecord.includes(:invoice, invoice: [:user]).find_by_id(params[:id])
if usage_record
response = usage_records_for(@user, usage_record)
status = 200
else
response = "'UsageRecord' with given id wasn't found"
status = 404
end
render json: { usage_records: response}, status: status
end
def index
if params[:userIds]
users = User.where('id IN (?)', params[:userIds])
invoices = Invoice.joins(:user).where(users:{id: users}) if users.any?
else
invoices = Invoice.all
end
if params[:from_date] && params[:until_date]
invoices = invoices.select{|inv| inv.beginning >= params[:from_date].to_date && inv.ending <= params[:until_date].to_date} unless invoices.nil?
end
usage_records = UsageRecord.joins(:invoice).where(invoices:{id: invoices}).includes(:invoice, invoice: [:user]) if !invoices.nil? && invoices.any?
if !usage_records.nil? && usage_records.any?
begin
if params[:page] && params[:per_page]
usage_records = usage_records.paginate(page: params[:page], per_page: params[:per_page])
end
rescue RangeError
UsageRecord.none
end
response = usage_records_for(@user, usage_records, true)
status = 200
else
response = "'UsageRecords' for given users wasn't found"
status = 404
end
render json: { usage_records: response}, status: status
end
def create
contract = fetch_contract
if contract.nil?
state = { error: "'Contract' with given id wasn't found" }
status = 404
elsif @user.try(:admin)
user = User.find(contract.user_id)
usage_data = usage_record_params.merge(date: Date.today,
user: user,
additional_info: params[:additional_info])
usage_record = UsageReportService.call({ user: user }, usage_data)
state = { usage_record: usage_record.to_json }
status = :ok
else
state = { error: 'Unauthorized' }
status = 401
end
render json: state, status: status
rescue UsageReporterException => e
render json: { error: e.reason }, status: 422
rescue => e
render json: { error: e.message }, status: 422
end
private
def validate_usage_records_request
errors = []
if params[:id]
errors << "unsupported type of value id" unless params[:id].is_a?(String)
else
errors << "unsupported type of 'userIds' value, 'userIds' must be array of strings, like ['1', '2', '3'] " unless params[:userIds].is_a?(Array) && params[:userIds].all? {|s| s.is_a?(String)} || params[:userIds].nil?
errors << "unsupported type of 'from_date' value, 'from_date' must be in format like 'yyyy-mm-dd'" unless params[:from_date].is_a?(String) && (Date.strptime(params[:from_date], '%Y-%m-%d') rescue false) || params[:from_date].nil?
errors << "unsupported type of 'until_date' value, 'until_date' must be in format like 'yyyy-mm-dd'" unless params[:until_date].is_a?(String) && (Date.strptime(params[:until_date], '%Y-%m-%d') rescue false) || params[:until_date].nil?
if params[:from_date] && params[:until_date] && ((Date.strptime(params[:from_date], '%Y-%m-%d') rescue false) && (Date.strptime(params[:until_date], '%Y-%m-%d') rescue false))
errors << "unsupported type of date params, 'from_date' must be <= 'until date'" unless Date.strptime(params[:from_date], '%Y-%m-%d') <= Date.strptime(params[:until_date], '%Y-%m-%d')
end
errors << "unsupported type of 'page' value, 'page' must be integer in range [1..n]" unless ((Integer(params[:page]) >=1 && params[:page].to_f % 1 == 0.0)rescue false) || params[:page].nil?
errors << "unsupported type of 'per_page' value, 'per_page' must be integer in range [1..500] " unless ((Integer(params[:per_page]) >= 1 && Integer(params[:per_page]) <= 500 && params[:per_page].to_f % 1 == 0.0) rescue false) || params[:per_page].nil?
end
errors
end
def usage_record_params
params.require(:usage_record).permit(:contract_id, :usage_type, :cost)
end
def create_report_for(option)
if @user.try(:admin)
report_data = PreparingUsageReportData::Service.call(option)
UsageReportService.call(report_data[:user], report_data[:usage_data])
state = 'done'
else
state = 'credentials error'
end
render json: {state: state }, status: :ok
rescue UsageReporterException => e
render json: { state: e.reason }, status: :ok
end
def create_contract_params
{acsmi_creds: acsmi_creds, amazon_creds: amazon_creds, contracting_resource: contracting_resource, usage_type: 'contract_creation',
contracting_creds: contracting_creds, cost: contracting_pricing_data[:creation_cost], platform_id: contracting_creds[:platform_id], user: @user}
end
def cancel_contract_params
{usage_type: 'contract_cancel', contract_id: contracting_cancellation_data[:contract_id],
cost: contracting_cancellation_data[:cancel_penalty_cost], user: @user, acsmi_email: contracting_cancellation_data[:email]}
end
def check_user
user_session = UserSession.new(email: user_params[:email], password: user_params[:password])
@user = user_session.user if user_session.save
end
def user_params
params.require(:user).permit(:email, :password)
end
def amazon_creds
params.require(:amazon_creds).permit(:email, :password) rescue nil
end
def acsmi_creds
params.require(:acsmi_creds).permit(:email, :password, :full_name, :organization, :address)
end
def contracting_creds
params.require(:contracting_creds).permit(:email, :password, :platform_id)
end
def contracting_resource
params.require(:contracting_resource).permit(:contract_id, :service_id, :service_name, :resource_id, :resource_name, :contracting_method)
end
def contracting_pricing_data
params.require(:contracting_pricing_data).permit(:creation_cost)
end
def contracting_cancellation_data
params.require(:cancellation_data).permit(:contract_id, :email, :cancel_penalty_cost)
end
def fetch_contract
Contract.find_by(global_id: params[:contract_id])
end
def usage_records_for(user, usage_records, ids=nil)
if ids
return [] unless usage_records
usage_records_array = []
usage_records.each do |u_r|
usage_records_array << u_r.usage_record_to_json
end
usage_records_array
else
usage_records.usage_record_to_json
end
end
end
......@@ -4,6 +4,14 @@ class ApplicationController < ActionController::Base
private
def http_basic_authenticate
authenticate_or_request_with_http_basic do |username, password|
user_session = UserSession.new(email: username, password: password)
@user = user_session.user if user_session.save
@user.present?
end
end
def allow_iframe_for_all
response.headers.delete 'X-Frame-Options'
end
......
......@@ -2,15 +2,15 @@ class UsageRecordsController < ApplicationController
before_action :authenticated?
def index
contracts = current_user.contracts
@usage_records = UsageRecord.includes(:invoice, :contract).where(contract_id: contracts.ids) if contracts
invoice = Invoice.current_monthly_invoice(current_user)
@usage_records = invoice.usage_records.includes(:invoice, :contract) if invoice
@sidebar_tab = :usage
end
def show
@usage_record = UsageRecord.includes(:invoice, :contract).find(params[:id])
if @usage_record
@contracting_resource = @usage_record.contract.contracting_resources.first
@contracting_resource = @usage_record&.contract&.contracting_resources&.first
@description_fields = @usage_record.usage_description_fields
end
end
......
class AmazonUsageMonitorJob < ApplicationJob
def perform
users = User.select{|user| user.amazon_accounts.exists?}
return unless users.any?
users.each do |user|
amazon_accounts = user.amazon_accounts
amazon_accounts.each do |aws_ac|
next if aws_ac.has_ur_today?
ActivityLog.debug(message: "job running, user_id: #{user.id}, aws_ac_id: #{aws_ac.id}")
date = {
year: DateTime.now.year,
month: DateTime.now.month
}
usage_cost = AwsCostRetrieval.new(aws_ac.amazon_email, aws_ac.amazon_password, date).check_total_cost rescue false
ActivityLog.debug(message: "usage cost = #{usage_cost}")
next unless usage_cost
usage_records = aws_ac.current_month_aws_ur
if usage_records.any?
total_sum = UsageRecord.total_sum(usage_records)
usage_cost -= total_sum
end
next if usage_cost <= 0
usage_data = {
date: DateTime.now,
cost: usage_cost,
usage_type: 'instance_runtime',
amazon_account_id: aws_ac.id,
additional_info: {activity: 'AWS EC2 instances run'}
}
user_data = { user: user}
next unless are_data_valid?(user_data, usage_data)
UsageReportService.call(user_data, usage_data)
end
end
rescue => e
Rails.logger.error e.message
end
def after(_job)
ActivityLog.debug(message: "job enqueuing")
Delayed::Job.where('handler LIKE ?', '%AmazonUsageMonitorJob%').destroy_all
Delayed::Job.enqueue AmazonUsageMonitorJob.new, priority: 4, run_at: random_sec_time.seconds.from_now
end
private
def are_data_valid?(user, usage_data)
return false if user.values.any?(&:blank?)
usage_data.values.none?(&:blank?)
end
def random_sec_time
rand(3600..5400)
end
end
......@@ -11,6 +11,6 @@ class MonthlyInvoiceJob < ApplicationJob
end
def after(_job)
Delayed::Job.enqueue MonthlyInvoiceJob.new, run_at: Time.new.end_of_month + 120
Delayed::Job.enqueue MonthlyInvoiceJob.new, priority: 4, run_at: Time.new.end_of_month + 120
end
end
......@@ -2,16 +2,17 @@ require 'set'
require_relative '../../lib/api_clients/platform'
class PlatformUsageMonitorJob < ApplicationJob
def perform
users = fetch_users_with_contracting_resources
return unless users.any?
users.each do |user|
api = APIClients::Platform.new(user.platform_email, user.platform_password)
next if api.get_billing_items.eql?('authentication error') || api.get_billing_items.eql?('collection is empty')
next if api.home_page.include?('Invalid Email or password')
billing_items = api.get_billing_items
next if billing_items.eql?('collection is empty')
uses_instances = api.get_uses_instances
instance_types = api.get_instance_types
......@@ -59,11 +60,11 @@ class PlatformUsageMonitorJob < ApplicationJob
end
end
rescue => e
logger.error e.message
Rails.logger.error e.message
end
def after(_job)
Delayed::Job.enqueue PlatformUsageMonitorJob.new, run_at: 5.minutes.from_now
Delayed::Job.enqueue PlatformUsageMonitorJob.new, priority: 4, run_at: 5.minutes.from_now
end
private
......
class ActivityLog < ApplicationRecord
def self.info(message:message, backtrace:backtrace)
ActivityLog.create(message: message, backtrace: backtrace, log_type: 'info')
end
def self.debug(message:message, backtrace:backtrace)
ActivityLog.create(message: message, backtrace: backtrace, log_type: 'debug')
end
def self.error(message:message, backtrace:backtrace)
ActivityLog.create(message: message, backtrace: backtrace, log_type: 'error')
end
end
\ No newline at end of file
class AmazonAccount < ApplicationRecord
belongs_to :user
has_many :usage_records
attr_encrypted :amazon_email, key: "144b90f4aff258634cfa88727f8b1f09"
attr_encrypted :amazon_password, key: "edec7037329b01b4685c4e5193d696d1"
def has_ur_today?
return true if usage_records.exists? && usage_records.last.created_at > 1.day.ago
false
end
def current_month_aws_ur
invoice_id = Invoice.current_monthly_invoice(user)&.id
usage_records.where(invoice_id: invoice_id)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment