Module: Exercism

Defined in:
lib/exercism.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

.cloudfront_clientObject



43
44
45
46
# File 'lib/exercism.rb', line 43

def self.cloudfront_client
  require 'aws-sdk-cloudfront'
  Aws::CloudFront::Client.new(ExercismConfig::GenerateAwsSettings.())
end

.cloudwatch_logs_clientObject



38
39
40
41
# File 'lib/exercism.rb', line 38

def self.cloudwatch_logs_client
  require 'aws-sdk-cloudwatchlogs'
  Aws::CloudWatchLogs::Client.new(ExercismConfig::GenerateAwsSettings.())
end

.configObject



8
9
10
# File 'lib/exercism.rb', line 8

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

.discourse_clientObject



96
97
98
99
100
101
102
103
# File 'lib/exercism.rb', line 96

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



20
21
22
# File 'lib/exercism.rb', line 20

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

.ecr_clientObject



33
34
35
36
# File 'lib/exercism.rb', line 33

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

.envObject



4
5
6
# File 'lib/exercism.rb', line 4

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

.mongodb_clientObject



105
106
107
108
109
110
111
# File 'lib/exercism.rb', line 105

def self.mongodb_client
  require 'mongo'
  Mongo::Client.new(
    self.config.mongodb_url,
    database: self.config.mongodb_database_name
  )
end

.octokit_clientObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/exercism.rb', line 53

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:).tap do |c|
    c.auto_paginate = true
  end
end

.octokit_graphql_clientObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/exercism.rb', line 66

def self.octokit_graphql_client
  require 'octokit'

  access_token = ENV.fetch(
    "GITHUB_GRAPHQL_READONLY_ACCESS_TOKEN",
    self.secrets.github_graphql_readonly_access_token
  )

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

.openai_clientObject



113
114
115
116
117
# File 'lib/exercism.rb', line 113

def self.openai_client
  require 'openai'

  @openai_client ||= OpenAI::Client.new(access_token: self.secrets.openai_api_key)
end

.opensearch_clientObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/exercism.rb', line 79

def self.opensearch_client
  require 'opensearch'

  # For now, we're using the ElasticSearch client, but this needs to be
  # changed to the OpenSearch client once it becomes available
  OpenSearch::Client.new(
    host: 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



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

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

.s3_clientObject



24
25
26
27
28
29
30
31
# File 'lib/exercism.rb', line 24

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

.secretsObject



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

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

.ses_clientObject



48
49
50
51
# File 'lib/exercism.rb', line 48

def self.ses_client
  require 'aws-sdk-sesv2'
  Aws::SESV2::Client.new(ExercismConfig::GenerateAwsSettings.())
end