module Bmc::Sdk

This module provides commands and DTOs for working with the BMC API documented at developers.phoenixnap.com/docs/bmc/1/overview. Module functions provided here which load configuration assume that client credentials are located in a YAML file at $HOME/.pnap/config.

Constants

ConfigPath
Entrypoint

The API entrypoint URL.

POSIXPath

The default configuration file location on POSIX systems

TokenURL

The OIDC token URL

WindowsPath

The default configuration file location on Windows systems

Public Class Methods

load_client() click to toggle source

load_client is a shortcut function which loads configuration from the expected location and uses that configuration to produce a new client.

# File lib/bmc-sdk.rb, line 60
def load_client
  cfg = load_config
  return new_client({
    client_id: cfg['client_id'],
    client_secret: cfg['client_secret']
  })
end
load_config() click to toggle source

load_config loads a YAML file from the expected file path.

# File lib/bmc-sdk.rb, line 72
def load_config
  return YAML.load_file(ConfigPath)
end
new_client(config) click to toggle source

This function creates a new HTTP client with integrated OAuth2 with the provided configuration.

# File lib/bmc-sdk.rb, line 46
def new_client(config)
  cfg = config.dup
  client = OAuth2::Client.new(
    cfg[:client_id],
    cfg[:client_secret],
    token_url: TokenURL)
  return client.client_credentials.get_token
end

Private Instance Methods

load_client() click to toggle source

load_client is a shortcut function which loads configuration from the expected location and uses that configuration to produce a new client.

# File lib/bmc-sdk.rb, line 60
def load_client
  cfg = load_config
  return new_client({
    client_id: cfg['client_id'],
    client_secret: cfg['client_secret']
  })
end
load_config() click to toggle source

load_config loads a YAML file from the expected file path.

# File lib/bmc-sdk.rb, line 72
def load_config
  return YAML.load_file(ConfigPath)
end
new_client(config) click to toggle source

This function creates a new HTTP client with integrated OAuth2 with the provided configuration.

# File lib/bmc-sdk.rb, line 46
def new_client(config)
  cfg = config.dup
  client = OAuth2::Client.new(
    cfg[:client_id],
    cfg[:client_secret],
    token_url: TokenURL)
  return client.client_credentials.get_token
end