Module: FaaStRuby
- Included in:
- SpecHelper
- Defined in:
- lib/faastruby/api.rb,
lib/faastruby/cli.rb,
lib/faastruby/base.rb,
lib/faastruby/user.rb,
lib/faastruby/local.rb,
lib/faastruby/server.rb,
lib/faastruby/regions.rb,
lib/faastruby/version.rb,
lib/faastruby/function.rb,
lib/faastruby/workspace.rb,
lib/faastruby/server/app.rb,
lib/faastruby/cli/package.rb,
lib/faastruby/spec_helper.rb,
lib/faastruby/cli/commands.rb,
lib/faastruby/cli/template.rb,
lib/faastruby/local/logger.rb,
lib/faastruby/server/event.rb,
lib/faastruby/server/local.rb,
lib/faastruby/server/errors.rb,
lib/faastruby/server/logger.rb,
lib/faastruby/server/runner.rb,
lib/faastruby/local/functions.rb,
lib/faastruby/local/listeners.rb,
lib/faastruby/server/response.rb,
lib/faastruby/server/template.rb,
lib/faastruby/cli/base_command.rb,
lib/faastruby/local/processors.rb,
lib/faastruby/server/event_hub.rb,
lib/faastruby/cli/commands/help.rb,
lib/faastruby/server/subscriber.rb,
lib/faastruby/local/static_files.rb,
lib/faastruby/supported_runtimes.rb,
lib/faastruby/cli/new_credentials.rb,
lib/faastruby/cli/commands/version.rb,
lib/faastruby/local/functions/ruby.rb,
lib/faastruby/server/event_channel.rb,
lib/faastruby/local/processors/opal.rb,
lib/faastruby/server/project_config.rb,
lib/faastruby/server/runner_methods.rb,
lib/faastruby/server/function_object.rb,
lib/faastruby/local/functions/crystal.rb,
lib/faastruby/cli/commands/project/new.rb,
lib/faastruby/local/functions/function.rb,
lib/faastruby/local/listeners/listener.rb,
lib/faastruby/cli/commands/function/new.rb,
lib/faastruby/cli/commands/function/run.rb,
lib/faastruby/cli/commands/project/down.rb,
lib/faastruby/cli/commands/workspace/cp.rb,
lib/faastruby/cli/commands/workspace/rm.rb,
lib/faastruby/local/processors/function.rb,
lib/faastruby/cli/commands/account/login.rb,
lib/faastruby/cli/commands/function/test.rb,
lib/faastruby/local/processors/processor.rb,
lib/faastruby/cli/commands/account/logout.rb,
lib/faastruby/cli/commands/account/signup.rb,
lib/faastruby/cli/commands/function/build.rb,
lib/faastruby/cli/commands/project/deploy.rb,
lib/faastruby/cli/commands/workspace/list.rb,
lib/faastruby/cli/commands/account/confirm.rb,
lib/faastruby/local/processors/static_file.rb,
lib/faastruby/cli/commands/workspace/create.rb,
lib/faastruby/cli/commands/workspace/update.rb,
lib/faastruby/cli/commands/workspace/destroy.rb,
lib/faastruby/cli/commands/workspace/migrate.rb,
lib/faastruby/local/static_files/static_file.rb,
lib/faastruby/cli/commands/function/deploy_to.rb,
lib/faastruby/cli/commands/account/base_command.rb,
lib/faastruby/cli/commands/function/remove_from.rb,
lib/faastruby/cli/commands/project/base_command.rb,
lib/faastruby/cli/commands/function/base_command.rb,
lib/faastruby/cli/commands/function/update_context.rb
Defined Under Namespace
Modules: Command, Local, Logger, NewCredentials, RunnerMethods, SpecHelper
Classes: API, BaseObject, CLI, Configuration, DoubleRenderError, Event, EventChannel, EventHub, Function, FunctionObject, InvalidResponseError, Package, ProjectConfig, Response, Runner, Server, Subscriber, Template, User, Workspace
Constant Summary
collapse
- FUNCTION_NAME_REGEX =
'[a-zA-Z\-_0-9\/\.]{1,}'
- WORKSPACE_NAME_REGEX =
'[a-zA-Z0-im9_]{1}[a-zA-Z0-9\-]{1,}[a-zA-Z0-9_]{1}'
- FAASTRUBY_YAML =
'faastruby.yml'
- SPINNER_FORMAT =
:spin_2
- ROOT_DOMAIN =
ENV['FAASTRUBY_ROOT_DOMAIN'] || 'faastruby.io'
- WORKSPACE_BASE_HOST =
ENV['FAASTRUBY_WORKSPACE_BASE_HOST'] || 'faast.cloud'
- URL_PROTOCOL =
ENV['FAASTRUBY_URL_PROTOCOL'] || 'https'
- CRYSTAL_ENABLED =
crystal_present_and_supported?
- RUBY_ENABLED =
ruby_present_and_supported?
- SERVER_ROOT =
Dir.pwd
- PROJECT_YAML_FILE =
"#{SERVER_ROOT}/project.yml"
- SECRETS_FILE =
ENV['FAASTRUBY_PROJECT_SECRETS_FILE'] || "#{SERVER_ROOT}/secrets.yml"
- PROJECT_NAME =
YAML.load(File.read(PROJECT_YAML_FILE))['project']['name']
- SYNC_ENABLED =
ENV['FAASTRUBY_PROJECT_SYNC_ENABLED']
- DEPLOY_ENVIRONMENT =
ENV['FAASTRUBY_PROJECT_DEPLOY_ENVIRONMENT'] || 'stage'
- WORKSPACE_NAME =
"#{PROJECT_NAME}-#{DEPLOY_ENVIRONMENT}"
- CHDIR_MUTEX =
Mutex.new
- CRYSTAL_VERSION =
get_crystal_version.freeze
- DEFAULT_CRYSTAL_RUNTIME =
"crystal:#{CRYSTAL_VERSION}".freeze
- DEFAULT_RUBY_RUNTIME =
"ruby:#{CURRENT_MINOR_RUBY}".freeze
- DEFAULT_REGION =
'tor1'
- REGIONS =
[
'tor1'
]
- VERSION =
'0.5.27'
- STDOUT_MUTEX =
Mutex.new
- SUPPORTED_RUBY =
It is important that they are sorted in version order!
['~> 2.5.0', '~> 2.6.0']
- SUPPORTED_CRYSTAL =
['0.27.0', '0.27.2']
- CRYSTAL_LATEST =
SUPPORTED_CRYSTAL.last
- RUBY_LATEST =
SUPPORTED_RUBY.last
- SUPPORTED_RUNTIMES =
['ruby:2.5', 'ruby:2.6'] + SUPPORTED_CRYSTAL.map{|version| "crystal:#{version}"}
- CURRENT_MINOR_RUBY =
RUBY_VERSION.split('.')[0..1].join('.')
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
7
8
9
|
# File 'lib/faastruby/base.rb', line 7
def configuration
@configuration
end
|
Class Method Details
.api_host ⇒ Object
27
28
29
|
# File 'lib/faastruby/base.rb', line 27
def self.api_host
ENV['FAASTRUBY_HOST'] || "#{URL_PROTOCOL}://api.#{region}.#{ROOT_DOMAIN}"
end
|
.api_key ⇒ Object
10
11
12
|
# File 'lib/faastruby/base.rb', line 10
def self.api_key
configuration&.api_key || ENV['FAASTRUBY_API_KEY']
end
|
.api_secret ⇒ Object
14
15
16
|
# File 'lib/faastruby/base.rb', line 14
def self.api_secret
configuration&.api_secret || ENV['FAASTRUBY_API_SECRET']
end
|
18
19
20
21
|
# File 'lib/faastruby/base.rb', line 18
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
|
.credentials ⇒ Object
23
24
25
|
# File 'lib/faastruby/base.rb', line 23
def self.credentials
{api_key: api_key, api_secret: api_secret}
end
|
.crystal_present_and_supported? ⇒ Boolean
11
12
13
|
# File 'lib/faastruby/server.rb', line 11
def self.crystal_present_and_supported?
system("which crystal >/dev/null") && version_match?(SUPPORTED_CRYSTAL, get_crystal_version)
end
|
.get_crystal_version ⇒ Object
6
7
8
9
|
# File 'lib/faastruby/server.rb', line 6
def self.get_crystal_version
ver = `crystal -v|head -n1|cut -f2 -d' ' 2>/dev/null`&.chomp
ver == '' ? CRYSTAL_LATEST : ver
end
|
.region ⇒ Object
7
8
9
10
11
|
# File 'lib/faastruby/regions.rb', line 7
def self.region
ENV['FAASTRUBY_REGION'] ||= DEFAULT_REGION
raise "No such region: #{ENV['FAASTRUBY_REGION']}" unless FaaStRuby::REGIONS.include?(ENV['FAASTRUBY_REGION'])
ENV['FAASTRUBY_REGION']
end
|
.ruby_present_and_supported? ⇒ Boolean
15
16
17
|
# File 'lib/faastruby/server.rb', line 15
def self.ruby_present_and_supported?
system("which ruby >/dev/null") && version_match?(SUPPORTED_RUBY, RUBY_VERSION)
end
|
.version_match?(supported, current) ⇒ Boolean
19
20
21
22
|
# File 'lib/faastruby/server.rb', line 19
def self.version_match?(supported, current)
supported.each {|supported_version| return true if Gem::Dependency.new('', supported_version).match?('', current)}
return false
end
|
.workspace_host_for(workspace_name) ⇒ Object
31
32
33
|
# File 'lib/faastruby/base.rb', line 31
def self.workspace_host_for(workspace_name)
"#{URL_PROTOCOL}://#{workspace_name}.#{region}.#{WORKSPACE_BASE_HOST}"
end
|