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, OsConfiguration, PowerOff, PowerOn, ProvisionedServer, Reboot, Reset, SSHKeySpec, ServerResetSpec, Shutdown

Constant Summary collapse

Entrypoint =

The API entrypoint URL.

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

The OIDC token URL

"https://auth.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'

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.



60
61
62
63
64
65
66
# 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_configObject

load_config loads a YAML file from the expected file path.



72
73
74
# File 'lib/bmc-sdk.rb', line 72

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.



46
47
48
49
50
51
52
53
# 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