infisical-license-server/lib/infisical_license_server/api/license.rb
Alexander Olofsson 243ed398a0
Initial commit
2026-02-23 18:37:34 +01:00

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'sinatra/base'
module InfisicalLicenseServer::API
class LicenseV1 < Sinatra::Base
configure :development do
require 'sinatra/reloader'
register Sinatra::Reloader
end
enable :logging
get '/plan' do
auth = request.get_header('HTTP_AUTHORIZATION')
error 401 unless InfisicalLicenseServer.config.auth? auth
plan = InfisicalLicenseServer.config.plan_for(auth)
{
currentPlan: plan['merged'].compact
}.to_json
end
patch '/license' do
auth = request.get_header('HTTP_AUTHORIZATION')
error 401 unless InfisicalLicenseServer.config.auth? auth
plan = InfisicalLicenseServer.config.plan_for(auth)
error 500 unless plan
#request.body.rewind
data = JSON.parse(request.body.read)
logger.info "Plan #{plan['plan']} uses #{data['usedSeats']} seats and #{data['usedIdentitySeats']} identities"
# Cache these for next plan request
plan['features']['membersUsed'] = data['usedSeats']
plan['features']['identitiesUsed'] = data['usedIdentitySeats']
nil
end
end
end