module Croesus

A library for supporting connections to the Delphix API.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The version number of the Croesus Gem

@return [String]

@api public

Author: Stefano Harding <riddopic@gmail.com>

Copyright © 2014 Stefano Harding

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constants

APIError
API_ENDPOINT

API_VERSION = { type: ‘APIVersion’, major: 1, minor: 3, micro: 2 }

CoercionError
ConfigurationError
HTTP_HEADERS
InvalidArgumentCount
InvalidMethodError
InvalidStateError
NotFound
Undefined

Represents an undefined parameter used by auto-generated option methods

VERSION
ValidationError

Attributes

api_passwd[RW]

@!attribute [rw] api_passwd

@return [String] password for authentication
api_user[RW]

@!attribute [rw] api_user

@return [String] username to authenticate with
api_version[RW]
last_request[RW]

@!attribute [rw] last_request

@return [Hash] retruns the last request
last_response[RW]

@!attribute [rw] last_response

@return [Hash] retruns the last response
server[RW]

@!attribute [rw] server

@return [String] Delphix server address
session[RW]

@!attribute [rw] session

@return [Hash] retruns current session state
@return [#code] the response code from Delphix engine
@return [#headers] beautified with symbols and underscores
@return [#body] parsed response body
@return [#raw_body] un-parsed response body
verbose[RW]

@!attribute [rw] verbose

@return [Nothing] enables verbosity

Public Class Methods

api_url(resource = nil) click to toggle source

Returns the API endpoint for a given resource namespace by combining the server address with the appropriate HTTP headers.

@param resource [Resource] namespace

@return [URL] return the URL for the API endpoint

@api public

# File lib/croesus.rb, line 156
def self.api_url(resource = nil)
  'http://' + @server + resource
end
clear_default_headers() click to toggle source
# File lib/croesus/web_client/web_client.rb, line 78
def self.clear_default_headers
  @@default_headers = {}
end
cookies() click to toggle source

Establish a session with the Delphix engine and return an identifier through browser cookies. This session will be reused in subsequent calls, the same session credentials and state are preserved without requiring a re-authentication call. Sessions do not persisit between incovations.

@return [Hash] cookies

containing the new session cookies

@api public

# File lib/croesus.rb, line 174
def self.cookies
  @resp ||= Croesus.post session_url,
    { type: 'APISession', version: @api_version }
  @resp.cookies
end
default_header(name, value) click to toggle source
# File lib/croesus/web_client/web_client.rb, line 74
def self.default_header(name, value)
  @@default_headers[name] = value
end
login(user = @api_user, passwd = @api_passwd) click to toggle source

Authenticates the session so that API calls can be made. Only supports basic password authentication.

@param [String] user

user name to authenticate with

@param [String] passwd

password to authenticate with

@return [Fixnum, code]

the response code from Delphix engine

@return [Hash, headers]

headers, beautified with symbols and underscores

@return [Hash, body] body

parsed response body where applicable (JSON responses are parsed to
Objects/Associative Arrays)

@return [Hash, raw_body] raw_body

un-parsed response body

@api public

# File lib/croesus.rb, line 199
def self.login(user = @api_user, passwd = @api_passwd)
  Croesus.post login_url,
    { type: 'LoginRequest', username: user, password: passwd }
end
many(validation) click to toggle source
# File lib/croesus.rb, line 224
def self.many(validation)
  Validations::Many.new(validation)
end
optional(validation) click to toggle source
# File lib/croesus.rb, line 220
def self.optional(validation)
  Validations::Optional.new(validation)
end
timeout(seconds) click to toggle source
# File lib/croesus/web_client/web_client.rb, line 82
def self.timeout(seconds)
  @@timeout = seconds
end
to_s() click to toggle source

@!visibility private

# File lib/croesus.rb, line 229
def self.to_s
  "<#{self.class.name}:#{self.name}:#{object_id} @session=#{@session}>"
end
validate(*args) click to toggle source
# File lib/croesus.rb, line 216
def self.validate(*args)
  Base.validate(*args)
end

Private Class Methods

included(parent) click to toggle source

Hooks into the mixin process to add Croesus components to the given parent automatically.

@param [Class] parent the object this is being mixed into

# File lib/croesus.rb, line 238
def self.included(parent)
  parent.class_eval do
    include InstanceMethods
    extend  ClassMethods
    "<#{self.class.name}:#{self.name}:#{object_id} @session=#{@session}>"
  end
end

Public Instance Methods

descendants() click to toggle source

From where forth do ye descend!

# File lib/croesus.rb, line 248
def descendants
  ObjectSpace.each_object(::Class).select {|klass| klass < self }
end