Class: KineticSdk::Filehub

Inherits:
Object
  • Object
show all
Includes:
Utils::KineticHttpUtils
Defined in:
lib/kinetic_sdk/filehub/filehub-sdk.rb,
lib/kinetic_sdk/filehub/lib/filestores.rb,
lib/kinetic_sdk/filehub/lib/access_keys.rb

Overview

Filehub is a Ruby class that acts as a wrapper for the Kinetic FileHub REST API without having to make explicit HTTP requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::KineticHttpUtils

#default_headers, default_headers, #default_jwt_headers, default_jwt_headers, #delete, #encode, #gateway_retry_delay, #gateway_retry_limit, #get, #head, #header_accept_json, header_accept_json, #header_basic_auth, header_basic_auth, header_bearer_auth, #header_bearer_auth, #header_content_json, header_content_json, header_user_agent, #header_user_agent, #max_redirects, #mimetype, #patch, #post, #post_multipart, #put, #redirect_url, #stream_download_to_file

Constructor Details

#initialize(opts = {}) ⇒ Filehub

Initalize the FileHub SDK with the web server URL and configuration user credentials, along with any custom option values.

Example: using a configuration file

KineticSdk::Filehub.new({
  config_file: "/opt/config1.yaml"
})

Example: using a properties hash

KineticSdk::Filehub.new({
  app_server_url: "http://localhost:8080/kinetic-filehub",
  username: "admin",
  password: "admin",
  options: {
    log_level: "debug",
    ssl_verify_mode: "peer",
    ssl_ca_file: "/usr/local/self_signing_ca.pem"
  }
})

If the +config_file+ option is present, it will be loaded first, and any additional options will overwrite any values in the config file

Parameters:

  • opts (Hash) (defaults to: {})

    Kinetic FileHub properties

Options Hash (opts):

  • :config_file (String)

    optional - path to the YAML configuration file

    • Ex: /opt/config/filehub-configuration1.yaml
  • :app_server_url (String)

    the URL to the Kinetic Filehub web application.

  • :username (String)

    the username for the user

  • :password (String)

    the password for the user

  • :options (Hash<Symbol, Object>) — default: {}

    optional settings

    • :gateway_retry_limit (FixNum) (defaults to: 5) max number of times to retry a bad gateway
    • :gateway_retry_delay (Float) (defaults to: 1.0) number of seconds to delay before retrying a bad gateway
    • :log_level (String) (defaults to: off) level of logging - off | error | warn | info | debug
    • :log_output (String) (defaults to: STDOUT) where to send output - STDOUT | STDERR
    • :max_redirects (Fixnum) (defaults to: 5) maximum number of redirects to follow
    • :ssl_ca_file (String) full path to PEM certificate used to verify the server
    • :ssl_verify_mode (String) (defaults to: none) - none | peer


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 61

def initialize(opts={})
  # initialize any variables
  options = {}

  # process the configuration file if it was provided
  unless opts[:config_file].nil?
    options.merge!(YAML::load_file opts[:config_file])
  end

  # process the configuration hash if it was provided
  options.merge!(opts)

  # process any individual options
  @options = options.delete(:options) || {}
  # setup logging
  log_level = @options[:log_level] || @options["log_level"]
  log_output = @options[:log_output] || @options["log_output"]
  @logger = KineticSdk::Utils::KLogger.new(log_level, log_output)

  @username = options[:username]
  @password = options[:password]
  @server = options[:app_server_url].chomp('/')
  @api_url = "#{@server}/app/api/v1"
  @version = 1
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



13
14
15
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 13

def api_url
  @api_url
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 13

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 13

def options
  @options
end

#passwordObject (readonly)

Returns the value of attribute password.



13
14
15
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 13

def password
  @password
end

#serverObject (readonly)

Returns the value of attribute server.



13
14
15
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 13

def server
  @server
end

#usernameObject (readonly)

Returns the value of attribute username.



13
14
15
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 13

def username
  @username
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/kinetic_sdk/filehub/filehub-sdk.rb', line 13

def version
  @version
end

Instance Method Details

#add_access_key(slug, payload, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add an Access Key for a Filestore

Parameters:

  • slug (String)

    slug of the filestore

  • payload (Hash)

    properties for the access key

    • +description+
    • +id+
    • +secret+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



13
14
15
16
# File 'lib/kinetic_sdk/filehub/lib/access_keys.rb', line 13

def add_access_key(slug, payload, headers=default_headers)
  @logger.info("Adding Access Key for Filestore \"#{slug}\"")
  post("#{@api_url}/filestores/#{slug}/access-keys", payload, headers)
end

#add_filestore(payload, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add a Filestore

Parameters:

  • payload (Hash)

    properties for the bridge

    • +accessKeys+
    • +adapterClass+
    • +name+
    • +properties+
    • +slug+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



14
15
16
17
# File 'lib/kinetic_sdk/filehub/lib/filestores.rb', line 14

def add_filestore(payload, headers=default_headers)
  @logger.info("Adding Filestore \"#{payload['name']}\" with slug \"#{payload['slug']}\"")
  post("#{@api_url}/filestores", payload, headers)
end

#delete_access_key(slug, id, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete an Access Key for a Filestore

Parameters:

  • slug (String)

    slug of the filestore

  • id (String)

    id (key) of the access key

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



24
25
26
27
# File 'lib/kinetic_sdk/filehub/lib/access_keys.rb', line 24

def delete_access_key(slug, id, headers=default_headers)
  @logger.info("Deleting Access Key #{id} for Filestore \"#{slug}\"")
  delete("#{@api_url}/filestores/#{slug}/access-keys/#{id}", headers)
end

#delete_filestore(slug, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete a Filestore

Parameters:

  • slug (String)

    slug of the filestore

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



24
25
26
27
# File 'lib/kinetic_sdk/filehub/lib/filestores.rb', line 24

def delete_filestore(slug, headers=default_headers)
  @logger.info("Deleting Filestore \"#{slug}\"")
  delete("#{@api_url}/filestores/#{slug}", headers)
end

#find_access_key(slug, id, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find an Access Key for a Filestore

Parameters:

  • slug (String)

    slug of the filestore

  • id (String)

    id (key) of the access key

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



47
48
49
50
# File 'lib/kinetic_sdk/filehub/lib/access_keys.rb', line 47

def find_access_key(slug, id, params={}, headers=default_headers)
  @logger.info("Finding Access Key \"#{id}\" for Filestore \"#{slug}\"")
  get("#{@api_url}/filestores/#{slug}/access-keys/#{id}", params, headers)
end

#find_access_keys(slug, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find Access Keys for a Filestore

Parameters:

  • slug (String)

    slug of the filestore

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



35
36
37
38
# File 'lib/kinetic_sdk/filehub/lib/access_keys.rb', line 35

def find_access_keys(slug, params={}, headers=default_headers)
  @logger.info("Finding Access Keys for Filestore \"#{slug}\"")
  get("#{@api_url}/filestores/#{slug}/access-keys", params, headers)
end

#find_filestore(slug, params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find a Filestore

Parameters:

  • slug (String)

    slug of the filestore

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



45
46
47
48
# File 'lib/kinetic_sdk/filehub/lib/filestores.rb', line 45

def find_filestore(slug, params={}, headers=default_headers)
  @logger.info("Finding Filestore \"#{slug}\"")
  get("#{@api_url}/filestores/#{slug}", params, headers)
end

#find_filestores(params = {}, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find Filestore

Parameters:

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



34
35
36
37
# File 'lib/kinetic_sdk/filehub/lib/filestores.rb', line 34

def find_filestores(params={}, headers=default_headers)
  @logger.info("Find Filestores")
  get("#{@api_url}/filestores", params, headers)
end

#update_access_key(slug, id, payload, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a Filestore Access Key

Parameters:

  • slug (String)

    slug of the filestore

  • id (String)

    id (key) of the access key

  • payload (Hash)

    properties for the access key

    • +description+
    • +secret+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



61
62
63
64
# File 'lib/kinetic_sdk/filehub/lib/access_keys.rb', line 61

def update_access_key(slug, id, payload, headers=default_headers)
  @logger.info("Updating Access Key \"#{id}\" for Filestore \"#{slug}\"")
  put("#{@api_url}/filestores/#{slug}/access-keys/#{id}", payload, headers)
end

#update_filestore(slug, payload, headers = default_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a Filestore

Parameters:

  • slug (String)

    slug of the filestore

  • payload (Hash)

    properties for the bridge

    • +accessKeys+
    • +adapterClass+
    • +name+
    • +properties+
    • +slug+
  • headers (Hash) (defaults to: default_headers)

    hash of headers to send, default is basic authentication and accept JSON content type

Returns:



61
62
63
64
# File 'lib/kinetic_sdk/filehub/lib/filestores.rb', line 61

def update_filestore(slug, payload, headers=default_headers)
  @logger.info("Updating Filestore \"#{slug}\"")
  put("#{@api_url}/filestores/#{slug}", payload, headers)
end