Module: Exercism

Defined in:
lib/exercism-config.rb,
lib/exercism/config.rb,
lib/exercism/secrets.rb,
lib/exercism/tooling_job.rb

Defined Under Namespace

Classes: Config, ConfigError, Secrets, ToolingJob

Class Method Summary collapse

Class Method Details

.configObject



28
29
30
# File 'lib/exercism-config.rb', line 28

def self.config
  @config ||= ExercismConfig::RetrieveConfig.()
end

.discourse_clientObject



90
91
92
93
94
95
96
97
# File 'lib/exercism-config.rb', line 90

def self.discourse_client
  require 'discourse_api'

  DiscourseApi::Client.new("https://forum.exercism.org").tap do |client|
    client.api_key = ENV.fetch("DISCOURSE_API_KEY", Exercism.secrets.discourse_api_key)
    client.api_username = ENV.fetch("DISCOURSE_API_USERNAME", "system")
  end
end

.dynamodb_clientObject



40
41
42
# File 'lib/exercism-config.rb', line 40

def self.dynamodb_client
  Aws::DynamoDB::Client.new(ExercismConfig::GenerateAwsSettings.())
end

.ecr_clientObject



53
54
55
56
# File 'lib/exercism-config.rb', line 53

def self.ecr_client
  require 'aws-sdk-ecr'
  Aws::ECR::Client.new(ExercismConfig::GenerateAwsSettings.())
end

.envObject



24
25
26
# File 'lib/exercism-config.rb', line 24

def self.env
  @env ||= ExercismConfig::DetermineEnvironment.()
end

.octokit_clientObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/exercism-config.rb', line 58

def self.octokit_client
  require 'octokit'

  access_token = ENV.fetch(
    "GITHUB_ACCESS_TOKEN",
    self.secrets.github_access_token
  )

  @octokit_client ||= Octokit::Client.new(
    access_token: access_token
  ).tap do |c|
    c.auto_paginate = true
  end
end

.opensearch_clientObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/exercism-config.rb', line 73

def self.opensearch_client
  require 'elasticsearch'

  # For now, we're using the ElasticSearch client, but this needs to be
  # changed to the OpenSearch client once it becomes available
  Elasticsearch::Client.new(
    url: ENV.fetch("OPENSEARCH_HOST", config.opensearch_host),
    user: ENV.fetch("OPENSEARCH_USER", Exercism.env.production? ? nil : "admin"),
    password: ENV.fetch("OPENSEARCH_PASSWORD", Exercism.env.production? ? nil : "admin"),
    transport_options: {
      ssl: {
        verify: Exercism.env.production?
      }
    }
  )
end

.redis_tooling_clientObject



36
37
38
# File 'lib/exercism-config.rb', line 36

def self.redis_tooling_client
  Redis.new(url: config.tooling_redis_url)
end

.s3_clientObject



44
45
46
47
48
49
50
51
# File 'lib/exercism-config.rb', line 44

def self.s3_client
  require 'aws-sdk-s3'
  Aws::S3::Client.new(
    ExercismConfig::GenerateAwsSettings.().merge(
      force_path_style: true
    )
  )
end

.secretsObject



32
33
34
# File 'lib/exercism-config.rb', line 32

def self.secrets
  @secrets ||= ExercismConfig::RetrieveSecrets.()
end