Class: MythicBeasts::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mythic_beasts/proxy.rb

Overview

IPv4 to IPv6 Proxy API

Manages IPv4-to-IPv6 proxy endpoints for making IPv6-only servers accessible via IPv4. Useful for cost-effective IPv6-only VPS deployments.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:



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

def initialize(client)
  @client = client
end

Instance Method Details

#add(domain, hostname, endpoints) ⇒ Hash

Add proxy endpoints for a hostname without replacing existing ones

Examples:

client.proxy.add(
  "example.com",
  "www",
  [{address: "2a00:1098:4c4::1", site: "all"}]
)

Parameters:

  • domain (String)

    the domain name

  • hostname (String)

    the hostname (use “@” for the domain itself)

  • endpoints (Array<Hash>)

    array of endpoint configurations

Options Hash (endpoints):

  • :address (String)

    IPv6 address

  • :site (String)

    proxy server location or “all”

  • :proxy_protocol (Boolean)

    enable PROXY protocol (optional)

Returns:

  • (Hash)

    API response



86
87
88
# File 'lib/mythic_beasts/proxy.rb', line 86

def add(domain, hostname, endpoints)
  @client.post("/proxy/endpoints/#{domain}/#{hostname}", body: {endpoints: endpoints})
end

#create_simple(domain, hostname, ipv6_address, proxy_protocol: false) ⇒ Hash

Convenience method: Create a simple proxy endpoint for a server

Examples:

# Make staging.example.com point to IPv6-only server
client.proxy.create_simple(
  "example.com",
  "staging",
  "2a00:1098:4c4::1"
)

Parameters:

  • domain (String)

    the domain name

  • hostname (String)

    the hostname (use “@” for root domain)

  • ipv6_address (String)

    the IPv6 address of your server

  • proxy_protocol (Boolean) (defaults to: false)

    enable PROXY protocol (default: false)

Returns:

  • (Hash)

    API response



141
142
143
144
145
146
147
148
149
# File 'lib/mythic_beasts/proxy.rb', line 141

def create_simple(domain, hostname, ipv6_address, proxy_protocol: false)
  endpoint = {
    address: ipv6_address,
    site: "all"
  }
  endpoint[:proxy_protocol] = true if proxy_protocol

  add(domain, hostname, [endpoint])
end

#delete(domain, hostname) ⇒ Hash

Delete all proxy endpoints for a hostname

Examples:

client.proxy.delete("example.com", "www")

Parameters:

  • domain (String)

    the domain name

  • hostname (String)

    the hostname

Returns:

  • (Hash)

    API response



97
98
99
# File 'lib/mythic_beasts/proxy.rb', line 97

def delete(domain, hostname)
  @client.delete("/proxy/endpoints/#{domain}/#{hostname}")
end

#delete_endpoint(domain, hostname, address, site = nil) ⇒ Hash

Delete a specific proxy endpoint

Examples:

client.proxy.delete_endpoint("example.com", "www", "2a00:1098:4c4::1")

Parameters:

  • domain (String)

    the domain name

  • hostname (String)

    the hostname

  • address (String)

    the IPv6 address

  • site (String) (defaults to: nil)

    the proxy site (optional, defaults to “all”)

Returns:

  • (Hash)

    API response



110
111
112
113
114
# File 'lib/mythic_beasts/proxy.rb', line 110

def delete_endpoint(domain, hostname, address, site = nil)
  path = "/proxy/endpoints/#{domain}/#{hostname}/#{address}"
  path += "/#{site}" if site
  @client.delete(path)
end

#listArray<Hash>

List all proxy endpoints accessible to the authenticated user

Examples:

endpoints = client.proxy.list
# => [{"domain" => "example.com", "hostname" => "www", "address" => "2a00:...", "site" => "all"}]

Returns:

  • (Array<Hash>)

    array of endpoint configurations



22
23
24
25
# File 'lib/mythic_beasts/proxy.rb', line 22

def list
  response = @client.get("/proxy/endpoints")
  response["endpoints"] || response[:endpoints] || []
end

#list_for_domain(domain) ⇒ Array<Hash>

List proxy endpoints for a specific domain

Examples:

endpoints = client.proxy.list_for_domain("example.com")

Parameters:

  • domain (String)

    the domain name

Returns:

  • (Array<Hash>)

    array of endpoint configurations for the domain



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

def list_for_domain(domain)
  response = @client.get("/proxy/endpoints/#{domain}")
  response["endpoints"] || response[:endpoints] || []
end

#list_for_hostname(domain, hostname) ⇒ Array<Hash>

List proxy endpoints for a specific hostname

Examples:

endpoints = client.proxy.list_for_hostname("example.com", "www")

Parameters:

  • domain (String)

    the domain name

  • hostname (String)

    the hostname (use “@” for the domain itself)

Returns:

  • (Array<Hash>)

    array of endpoint configurations



45
46
47
48
# File 'lib/mythic_beasts/proxy.rb', line 45

def list_for_hostname(domain, hostname)
  response = @client.get("/proxy/endpoints/#{domain}/#{hostname}")
  response["endpoints"] || response[:endpoints] || []
end

#replace(domain, hostname, endpoints) ⇒ Hash

Create or replace proxy endpoints for a hostname

This replaces ALL existing endpoints for the hostname.

Examples:

client.proxy.replace(
  "example.com",
  "www",
  [{address: "2a00:1098:4c4::1", site: "all"}]
)

Parameters:

  • domain (String)

    the domain name

  • hostname (String)

    the hostname (use “@” for the domain itself)

  • endpoints (Array<Hash>)

    array of endpoint configurations

Options Hash (endpoints):

  • :address (String)

    IPv6 address

  • :site (String)

    proxy server location or “all”

  • :proxy_protocol (Boolean)

    enable PROXY protocol (optional)

Returns:

  • (Hash)

    API response



67
68
69
# File 'lib/mythic_beasts/proxy.rb', line 67

def replace(domain, hostname, endpoints)
  @client.put("/proxy/endpoints/#{domain}/#{hostname}", body: {endpoints: endpoints})
end

#sitesArray<String>

List available proxy server locations

Examples:

sites = client.proxy.sites
# => ["sov", "ams", "hex"]

Returns:

  • (Array<String>)

    array of site codes (e.g., [“sov”, “ams”, “hex”])



122
123
124
125
# File 'lib/mythic_beasts/proxy.rb', line 122

def sites
  response = @client.get("/proxy/sites")
  response["sites"] || response[:sites] || []
end