Class: Scaled::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/scaled/client.rb

Overview

Main entry point for interacting with Tailscale API. Основна точка входу для взаємодії з Tailscale API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token: nil, auth: nil, oauth: nil, tailnet: "-", **http_options) ⇒ void

Note: exactly one auth mode must be provided: ‘api_token`, `auth`, or `oauth`. Нотатка: потрібно передати рівно один режим auth: `api_token`, `auth` або `oauth`.

Parameters:

  • api_token (String, nil) (defaults to: nil)

    Tailscale API token for Bearer auth

  • auth (#apply, nil) (defaults to: nil)

    custom authentication strategy

  • oauth (Hash, nil) (defaults to: nil)

    OAuth settings (:client_id, :client_secret, optional :scopes, :token_url)

  • tailnet (String) (defaults to: "-")

    tailnet name, or “-” for token-owned tailnet

  • http_options (Hash)

    custom HTTP options (base_url, timeouts, user_agent)



26
27
28
29
30
# File 'lib/scaled/client.rb', line 26

def initialize(api_token: nil, auth: nil, oauth: nil, tailnet: "-", **http_options)
  @tailnet = tailnet
  auth_strategy = resolve_auth(api_token: api_token, auth: auth, oauth: oauth)
  @http = HTTP.new(auth: auth_strategy, **http_options)
end

Instance Attribute Details

#tailnetObject (readonly)

Returns the value of attribute tailnet.



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

def tailnet
  @tailnet
end

Instance Method Details

#aclScaled::Resources::Acl



88
89
90
# File 'lib/scaled/client.rb', line 88

def acl
  @acl ||= Resources::Acl.new(self)
end

#delete(path, query: nil) ⇒ Hash, ...

Returns parsed response body.

Parameters:

  • path (String)

    endpoint path

  • query (Hash, nil) (defaults to: nil)

    query parameters

Returns:

  • (Hash, Array, String, nil)

    parsed response body



68
69
70
# File 'lib/scaled/client.rb', line 68

def delete(path, query: nil)
  @http.request(method: :delete, path: path, query: query)
end

#device_routesScaled::Resources::DeviceRoutes



93
94
95
# File 'lib/scaled/client.rb', line 93

def device_routes
  @device_routes ||= Resources::DeviceRoutes.new(self)
end

#devicesScaled::Resources::Devices



73
74
75
# File 'lib/scaled/client.rb', line 73

def devices
  @devices ||= Resources::Devices.new(self)
end

#get(path, query: nil) ⇒ Hash, ...

Note: use this low-level method until resource-specific clients are introduced. Нотатка: використовуйте цей low-level метод, доки не додані ресурсні клієнти.

Parameters:

  • path (String)

    endpoint path

  • query (Hash, nil) (defaults to: nil)

    query parameters

Returns:

  • (Hash, Array, String, nil)

    parsed response body



37
38
39
# File 'lib/scaled/client.rb', line 37

def get(path, query: nil)
  @http.request(method: :get, path: path, query: query)
end

#keysScaled::Resources::Keys



78
79
80
# File 'lib/scaled/client.rb', line 78

def keys
  @keys ||= Resources::Keys.new(self)
end

#logsScaled::Resources::Logs



83
84
85
# File 'lib/scaled/client.rb', line 83

def logs
  @logs ||= Resources::Logs.new(self)
end

#patch(path, body: nil, query: nil) ⇒ Hash, ...

Returns parsed response body.

Parameters:

  • path (String)

    endpoint path

  • body (Hash, Array, nil) (defaults to: nil)

    JSON body

  • query (Hash, nil) (defaults to: nil)

    query parameters

Returns:

  • (Hash, Array, String, nil)

    parsed response body



61
62
63
# File 'lib/scaled/client.rb', line 61

def patch(path, body: nil, query: nil)
  @http.request(method: :patch, path: path, body: body, query: query)
end

#post(path, body: nil, query: nil) ⇒ Hash, ...

Returns parsed response body.

Parameters:

  • path (String)

    endpoint path

  • body (Hash, Array, nil) (defaults to: nil)

    JSON body

  • query (Hash, nil) (defaults to: nil)

    query parameters

Returns:

  • (Hash, Array, String, nil)

    parsed response body



45
46
47
# File 'lib/scaled/client.rb', line 45

def post(path, body: nil, query: nil)
  @http.request(method: :post, path: path, body: body, query: query)
end

#put(path, body: nil, query: nil) ⇒ Hash, ...

Returns parsed response body.

Parameters:

  • path (String)

    endpoint path

  • body (Hash, Array, nil) (defaults to: nil)

    JSON body

  • query (Hash, nil) (defaults to: nil)

    query parameters

Returns:

  • (Hash, Array, String, nil)

    parsed response body



53
54
55
# File 'lib/scaled/client.rb', line 53

def put(path, body: nil, query: nil)
  @http.request(method: :put, path: path, body: body, query: query)
end