Class: Kontena::StacksClient
- Inherits:
-
Client
- Object
- Client
- Kontena::StacksClient
show all
- Defined in:
- lib/kontena/stacks_client.rb
Constant Summary
collapse
- ACCEPT_JSON =
{ 'Accept' => 'application/json' }
- ACCEPT_YAML =
{ 'Accept' => 'application/yaml' }
- CT_YAML =
{ 'Content-Type' => 'application/yaml' }
Constants inherited
from Client
Client::ACCEPT, Client::AUTHORIZATION, Client::CLIENT_ID, Client::CLIENT_SECRET, Client::CONTENT_JSON, Client::CONTENT_TYPE, Client::CONTENT_URLENCODED, Client::JSON_REGEX, Client::X_KONTENA_VERSION
Instance Attribute Summary
Attributes inherited from Client
#api_url, #default_headers, #host, #http_client, #last_response, #logger, #options, #path_prefix, #token
Instance Method Summary
collapse
Methods inherited from Client
#authentication_ok?, #basic_auth_header, #bearer_authorization_header, #client_id, #client_secret, #debug, #delete, #error, #exchange_code, #get, #get_stream, #initialize, #patch, #post, #put, #refresh_request_params, #refresh_token, #request, #server_version, #token_account, #token_expired?
Instance Method Details
#destroy(stack_name, version = nil) ⇒ Object
59
60
61
62
|
# File 'lib/kontena/stacks_client.rb', line 59
def destroy(stack_name, version = nil)
raise_unless_token
delete(path_to(stack_name, version), {})
end
|
#full_uri(stack_name, version = nil) ⇒ Object
23
24
25
|
# File 'lib/kontena/stacks_client.rb', line 23
def full_uri(stack_name, version = nil)
URI.join(api_url, path_to(stack_name, version)).to_s
end
|
#path_to(stack_name, version = nil) ⇒ Object
27
28
29
|
# File 'lib/kontena/stacks_client.rb', line 27
def path_to(stack_name, version = nil)
version ? "/stack/#{stack_name}/version/#{version}" : "/stack/#{stack_name}"
end
|
#pull(stack_name, version = nil) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/kontena/stacks_client.rb', line 46
def pull(stack_name, version = nil)
raise_unless_read_token
get(path_to(stack_name, version), nil, ACCEPT_YAML, options[:read_requires_token])
rescue StandardError => ex
ex.message << " : #{path_to(stack_name, version)}"
raise ex, ex.message
end
|
#push(stack_name, version, data) ⇒ Object
31
32
33
34
|
# File 'lib/kontena/stacks_client.rb', line 31
def push(stack_name, version, data)
raise_unless_token
post('/stack/', data, {}, CT_YAML, true)
end
|
#raise_unless_read_token ⇒ Object
16
17
18
19
20
21
|
# File 'lib/kontena/stacks_client.rb', line 16
def raise_unless_read_token
return false unless options[:read_requires_token]
unless token && token['access_token']
raise Kontena::Errors::StandardError.new(401, "Stack registry requires authentication")
end
end
|
#raise_unless_token ⇒ Object
10
11
12
13
14
|
# File 'lib/kontena/stacks_client.rb', line 10
def raise_unless_token
unless token && token['access_token']
raise Kontena::Errors::StandardError.new(401, "Stack registry write operations require authentication")
end
end
|
#search(query) ⇒ Object
54
55
56
57
|
# File 'lib/kontena/stacks_client.rb', line 54
def search(query)
raise_unless_read_token
get('/search', { q: query }, ACCEPT_JSON, options[:read_requires_token])['stacks']
end
|
#show(stack_name, stack_version = nil) ⇒ Object
36
37
38
39
|
# File 'lib/kontena/stacks_client.rb', line 36
def show(stack_name, stack_version = nil)
raise_unless_read_token
get("#{path_to(stack_name, stack_version)}", nil, ACCEPT_JSON, options[:read_requires_token])
end
|
#versions(stack_name) ⇒ Object
41
42
43
44
|
# File 'lib/kontena/stacks_client.rb', line 41
def versions(stack_name)
raise_unless_read_token
get("#{path_to(stack_name, nil)}/versions", nil, ACCEPT_JSON, options[:read_requires_token])['versions']
end
|