Setup a Static IP for Ruby SFTP

Prerequisites

Elixir and Mix installed.

The qgpass wrapper downloaded and extracted into your bin/ folder.

Instructions

Run example
QUOTAGUARDSHIELD_URL=... ./bin/qgpass mix run -e "Qg.request_ip()"
Be sure to set QUOTAGUARDSHIELD_URL to your HTTPS proxy URL from the QuotaGuard Dashboard.


Test in Docker
docker build -t qg-shield-elixir-https-tesla-example .
docker run -e QUOTAGUARDSHIELD_URL=... qg-shield-elixir-https-tesla-example

Code Samples

# --- config/config.exs ---
import Config

config :tesla, adapter: {Tesla.Adapter.Mint, proxy: {:http, "localhost", 8080, []}}

# --- lib/qg.ex ---
defmodule Qg do
  use Tesla

  plug Tesla.Middleware.BaseUrl, "https://ip.quotaguard.com"

  @moduledoc """
  Example for connecting through the QuotaGuard proxy
  """

  @doc """
  Requesting IP echo
  """
  def request_ip do
    {:ok, response} = get("/")
    IO.puts(response.body)
  end
end

# --- mix.exs ---
defmodule Qg.MixProject do
  use Mix.Project

  def project do
    [
      app: :qg,
      version: "0.1.0",
      elixir: "~> 1.14",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:castore, "~> 1.0"},
      {:mint, "~> 1.5"},
      {:tesla, "~> 1.5"},
    ]
  end
end