Class: M365ActiveStorage::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/active_storage/configuration.rb

Overview

SharePoint Configuration Manager

Manages and validates all configuration parameters needed to connect to Microsoft 365 SharePoint via the Microsoft Graph API.

Responsibilities

  • Load and parse configuration parameters

  • Validate that all required parameters are present

  • Provide convenient accessors for configuration values

  • Raise informative errors for missing or invalid configurations

Required Configuration Parameters

  • ms_graph_url - The Microsoft Graph API base URL (typically graph.microsoft.com)

  • ms_graph_version - The Graph API version (e.g., “v1.0”, “beta”)

  • auth_host - The OAuth2 authentication endpoint (typically login.microsoftonline.com)

  • tenant_id - Your Azure AD tenant ID (directory ID from Azure Portal)

  • app_id - Your Azure AD application ID (client ID from your app registration)

  • secret - Your Azure AD client secret

  • site_id - The target SharePoint site ID

  • drive_id - The target SharePoint drive ID within the site

Configuration Sources

Configuration can be provided via:

  • Rails credentials (config/credentials.yml.enc)

  • Environment variables

  • Direct parameter passing

Example in config/storage.yml:

sharepoint:
  ms_graph_url: <%= Rails.application.credentials.sharepoint[:ms_graph_url] %>
  ms_graph_version: <%= Rails.application.credentials.sharepoint[:ms_graph_version] %>
  auth_host: <%= Rails.application.credentials.sharepoint[:auth_host] %>
  tenant_id: <%= Rails.application.credentials.sharepoint[:oauth_tenant] %>
  app_id: <%= Rails.application.credentials.sharepoint[:oauth_app_id] %>
  secret: <%= Rails.application.credentials.sharepoint[:oauth_secret] %>
  site_id: <%= Rails.application.credentials.sharepoint[:sharepoint_site_id] %>
  drive_id: <%= Rails.application.credentials.sharepoint[:sharepoint_drive_id] %>

Example Usage

config = M365ActiveStorage::Configuration.new(
  ms_graph_url: "https://graph.microsoft.com",
  ms_graph_version: "v1.0",
  auth_host: "https://login.microsoftonline.com",
  tenant_id: "your-tenant-id",
  app_id: "your-app-id",
  secret: "your-client-secret",
  site_id: "your-site-id",
  drive_id: "your-drive-id"
)

puts config.ms_graph_endpoint  # => "https://graph.microsoft.com/v1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Configuration

Initialize Configuration with the provided parameters

All parameters are required. Missing parameters will raise a KeyError with a detailed message listing which parameters are missing.

Examples:

config = M365ActiveStorage::Configuration.new(
  ms_graph_url: "https://graph.microsoft.com",
  ms_graph_version: "v1.0",
  # ... other required parameters
)

Parameters:

  • options (Hash)

    The configuration parameters

Options Hash (**options):

  • :ms_graph_url (String)

    The Microsoft Graph API base URL

  • :ms_graph_version (String)

    The Graph API version

  • :auth_host (String)

    The OAuth2 authentication host

  • :tenant_id (String)

    The Azure AD tenant ID

  • :app_id (String)

    The Azure AD application ID

  • :secret (String)

    The Azure AD client secret

  • :site_id (String)

    The SharePoint site ID

  • :drive_id (String)

    The SharePoint drive ID

Raises:

  • (KeyError)

    if any required parameter is missing or empty

See Also:

  • #validate_configuration!


100
101
102
103
104
105
# File 'lib/active_storage/configuration.rb', line 100

def initialize(**options)
  fetch_configuration_params(options)
  validate_configuration!
rescue KeyError => e
  raise KeyError, "Configuration error: #{e.message}"
end

Instance Attribute Details

#app_idString (readonly)

The Azure AD application ID

Returns:

  • (String)

    the current value of app_id



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def app_id
  @app_id
end

#auth_hostString (readonly)

The OAuth2 authentication host

Returns:

  • (String)

    the current value of auth_host



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def auth_host
  @auth_host
end

#drive_idString (readonly)

The SharePoint drive ID

Returns:

  • (String)

    the current value of drive_id



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def drive_id
  @drive_id
end

#ms_graph_endpointString (readonly)

The complete Graph API endpoint (url + version)

Returns:

  • (String)

    the current value of ms_graph_endpoint



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def ms_graph_endpoint
  @ms_graph_endpoint
end

#ms_graph_urlString (readonly)

The Microsoft Graph API base URL

Returns:

  • (String)

    the current value of ms_graph_url



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def ms_graph_url
  @ms_graph_url
end

#ms_graph_versionString (readonly)

The Graph API version

Returns:

  • (String)

    the current value of ms_graph_version



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def ms_graph_version
  @ms_graph_version
end

#secretString (readonly)

The Azure AD client secret

Returns:

  • (String)

    the current value of secret



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def secret
  @secret
end

#site_idString (readonly)

The SharePoint site ID

Returns:

  • (String)

    the current value of site_id



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def site_id
  @site_id
end

#tenant_idString (readonly)

The Azure AD tenant ID

Returns:

  • (String)

    the current value of tenant_id



70
71
72
# File 'lib/active_storage/configuration.rb', line 70

def tenant_id
  @tenant_id
end