Module: Bmc::Sdk

Defined in:
lib/bmc-sdk.rb,
lib/commands.rb,
lib/dtos.rb

Overview

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.

Defined Under Namespace

Classes: CreateSSHKey, CreateServer, DeleteSSHKey, DeleteServer, EditSSHKey, ErrorMessage, GetSSHKey, GetSSHKeys, GetServer, GetServers, LongServer, PowerOff, PowerOn, ProvisionedServer, Reboot, Reset, SSHKeySpec, ServerResetSpec, Shutdown

Constant Summary collapse

Entrypoint =

The API entrypoint URL.

"https://api-dev.phoenixnap.com/bmc/v1/"
TokenURL =

The OIDC token URL

"https://auth-dev.phoenixnap.com/auth/realms/BMC/protocol/openid-connect/token"
POSIXPath =

The default configuration file location on POSIX systems

"/.pnap/config"
WindowsPath =

The default configuration file location on Windows systems

'\\AppData\\Roaming\\pnap\\config'
ConfigPath =

The computed configuration file location based on the current system

OS.windows? ? Dir.home + WindowsPath : Dir.home + POSIXPath

Class Method Summary collapse

Class Method Details

.load_clientObject

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



56
57
58
59
60
61
62
# File 'lib/bmc-sdk.rb', line 56

def load_client
  cfg = load_config
  return new_client({
    client_id: cfg['client_id'],
    client_secret: cfg['client_secret']
  })
end

.load_configObject

load_config loads a YAML file from the expected file path.



68
69
70
# File 'lib/bmc-sdk.rb', line 68

def load_config
  return YAML.load_file(ConfigPath)
end

.new_client(config) ⇒ Object

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



42
43
44
45
46
47
48
49
# File 'lib/bmc-sdk.rb', line 42

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