Class: Captive::ClusterEndpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/captive/cluster_endpoint.rb

Overview

Où joindre le cluster : le gem est public, il ne porte ni l'adresse du kube-apiserver ni son CA (ADR 0018). Le dashboard les sert à tout utilisateur authentifié.

Constant Summary collapse

URL =
"https://dashboard.captive.dev/api/cluster"

Instance Method Summary collapse

Constructor Details

#initialize(http: HttpClient.new) ⇒ ClusterEndpoint

Returns a new instance of ClusterEndpoint.



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

def initialize(http: HttpClient.new)
  @http = http
end

Instance Method Details

#fetch(token) ⇒ Object



16
17
18
19
20
21
# File 'lib/captive/cluster_endpoint.rb', line 16

def fetch(token)
  data = @http.get(URL, "Authorization" => "Bearer #{token}")
  { server: data.fetch("server"), certificate_authority_data: data.fetch("certificate_authority_data") }
rescue KeyError, JSON::ParserError
  raise AuthError, "Le dashboard n'a pas fourni l'adresse du cluster. Réessaie : captive login"
end