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/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/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/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'
DEFAULT_REGION =
'tor1'
REGIONS =
[
  'tor1'
]
CRYSTAL_ENABLED =
crystal_present_and_supported?
RUBY_ENABLED =
ruby_present_and_supported?
SERVER_ROOT =
Dir.pwd
PROJECT_YAML_FILE =
ENV['FAASTRUBY_PROJECT_CONFIG_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:#{RUBY_VERSION}".freeze
VERSION =
'0.5.5'
STDOUT_MUTEX =
Mutex.new
SUPPORTED_RUBY =

It is important that they are sorted in version order!

['2.5.3', '2.6.0', '2.6.1']
SUPPORTED_CRYSTAL =
['0.27.0', '0.27.2']
CRYSTAL_LATEST =
SUPPORTED_CRYSTAL.last
RUBY_LATEST =
SUPPORTED_RUBY.last
SUPPORTED_RUNTIMES =
SUPPORTED_RUBY.map{|version| "ruby:#{version}"} + SUPPORTED_CRYSTAL.map{|version| "crystal:#{version}"}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



9
10
11
# File 'lib/faastruby/base.rb', line 9

def configuration
  @configuration
end

Class Method Details

.api_hostObject



35
36
37
# File 'lib/faastruby/base.rb', line 35

def self.api_host
  ENV['FAASTRUBY_HOST'] || "https://api.#{region}.#{ROOT_DOMAIN}"
end

.api_keyObject



12
13
14
# File 'lib/faastruby/base.rb', line 12

def self.api_key
  configuration&.api_key || ENV['FAASTRUBY_API_KEY']
end

.api_secretObject



16
17
18
# File 'lib/faastruby/base.rb', line 16

def self.api_secret
  configuration&.api_secret || ENV['FAASTRUBY_API_SECRET']
end

.configure {|configuration| ... } ⇒ Object

Yields:



20
21
22
23
# File 'lib/faastruby/base.rb', line 20

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

.credentialsObject



25
26
27
# File 'lib/faastruby/base.rb', line 25

def self.credentials
  {api_key: api_key, api_secret: api_secret}
end

.crystal_present_and_supported?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/faastruby/server.rb', line 11

def self.crystal_present_and_supported?
  system("which crystal >/dev/null") && SUPPORTED_CRYSTAL.include?(get_crystal_version)
end

.get_crystal_versionObject



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

.regionObject



29
30
31
32
33
# File 'lib/faastruby/base.rb', line 29

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

Returns:

  • (Boolean)


15
16
17
# File 'lib/faastruby/server.rb', line 15

def self.ruby_present_and_supported?
  system("which ruby >/dev/null") && SUPPORTED_RUBY.include?(RUBY_VERSION)
end

.workspace_host_for(workspace_name) ⇒ Object



39
40
41
# File 'lib/faastruby/base.rb', line 39

def self.workspace_host_for(workspace_name)
  "https://#{workspace_name}.#{region}.#{WORKSPACE_BASE_HOST}"
end