/foreman_api

Ruby bindings for Forman's rest API

Primary LanguageRubyMIT LicenseMIT

Foreman API bindings for Ruby

Summary

Usage:

require 'foreman_api'
require 'logger' # optional

architectures = ForemanApi::Resources::Architecture.new(
  {
    :logger => Logger.new(STDOUT), # optional
    :base_url => 'http://foreman-url', 
    :username => 'admin', 
    :password => 'changeme'
  })

puts architectures.index.inspect

Description

This gem contains Foreman API bindings for the Ruby language. The bindings are generated from API documentation using Apidoc tool.

The bindings brings support for new versioned API which is not complete yet. The number of supported controllers is limited but more are coming soon.

Regenerating bindings

The code for generating the bindings is a part of this repo. The generator needs a running Foreman instance to load the apidoc.json.

Usage:

bin/generate.rb -h
Script for generating API bindings for Foreman API from Apipie docs.
    -u, --url FOREMAN_APIDOC_URL     By default http://localhost:3000/apidoc
    -h, --help

Only files under lib/foreman_api/resources are touched by the generator.

Authentication

Foreman API uses OAuth for authentication, you need to provide url, key and secret. Also, it is required to provide user which will be used for the request if oauth_map_users setting in the Foreman instance is set, otherwise 401 error will occur and Foreman log will state “users mapping error”.

When setting base_url make sure it *does not* include trailing slash, otherwise request can be refused with 401.

require 'foreman_api'

architectures = ForemanApi::Resources::Architecture.new(
  {
    :base_url => 'http://foreman-url', 
    :oauth => {
      :consumer_key    => 'katello',
      :consumer_secret => "shhhh" 
    }
  },{
    :headers => {
      :foreman_user => "admin",
    }
  })

puts architectures.index.inspect

License

The bindings are released under MIT license