Module: DiasporaFederation

Extended by:
Logging
Defined in:
lib/diaspora_federation.rb,
lib/diaspora_federation/entity.rb,
lib/diaspora_federation/salmon.rb,
lib/diaspora_federation/logging.rb,
lib/diaspora_federation/parsers.rb,
lib/diaspora_federation/version.rb,
lib/diaspora_federation/entities.rb,
lib/diaspora_federation/callbacks.rb,
lib/diaspora_federation/discovery.rb,
lib/diaspora_federation/federation.rb,
lib/diaspora_federation/salmon/aes.rb,
lib/diaspora_federation/validators.rb,
lib/diaspora_federation/http_client.rb,
lib/diaspora_federation/entities/like.rb,
lib/diaspora_federation/entities/poll.rb,
lib/diaspora_federation/entities/post.rb,
lib/diaspora_federation/entities/embed.rb,
lib/diaspora_federation/entities/event.rb,
lib/diaspora_federation/entities/photo.rb,
lib/diaspora_federation/properties_dsl.rb,
lib/diaspora_federation/entities/person.rb,
lib/diaspora_federation/discovery/h_card.rb,
lib/diaspora_federation/entities/comment.rb,
lib/diaspora_federation/entities/contact.rb,
lib/diaspora_federation/entities/message.rb,
lib/diaspora_federation/entities/profile.rb,
lib/diaspora_federation/entities/reshare.rb,
lib/diaspora_federation/entities/location.rb,
lib/diaspora_federation/entities/signable.rb,
lib/diaspora_federation/federation/sender.rb,
lib/diaspora_federation/salmon/exceptions.rb,
lib/diaspora_federation/entities/relayable.rb,
lib/diaspora_federation/federation/fetcher.rb,
lib/diaspora_federation/parsers/xml_parser.rb,
lib/diaspora_federation/discovery/discovery.rb,
lib/diaspora_federation/entities/retraction.rb,
lib/diaspora_federation/federation/receiver.rb,
lib/diaspora_federation/parsers/base_parser.rb,
lib/diaspora_federation/parsers/json_parser.rb,
lib/diaspora_federation/discovery/exceptions.rb,
lib/diaspora_federation/discovery/web_finger.rb,
lib/diaspora_federation/entities/poll_answer.rb,
lib/diaspora_federation/entities/conversation.rb,
lib/diaspora_federation/salmon/magic_envelope.rb,
lib/diaspora_federation/discovery/xrd_document.rb,
lib/diaspora_federation/entities/participation.rb,
lib/diaspora_federation/entities/related_entity.rb,
lib/diaspora_federation/entities/status_message.rb,
lib/diaspora_federation/entities/account_deletion.rb,
lib/diaspora_federation/validators/like_validator.rb,
lib/diaspora_federation/validators/poll_validator.rb,
lib/diaspora_federation/entities/account_migration.rb,
lib/diaspora_federation/federation/receiver/public.rb,
lib/diaspora_federation/validators/embed_validator.rb,
lib/diaspora_federation/validators/event_validator.rb,
lib/diaspora_federation/validators/photo_validator.rb,
lib/diaspora_federation/entities/poll_participation.rb,
lib/diaspora_federation/federation/receiver/private.rb,
lib/diaspora_federation/validators/h_card_validator.rb,
lib/diaspora_federation/validators/person_validator.rb,
lib/diaspora_federation/entities/event_participation.rb,
lib/diaspora_federation/parsers/relayable_xml_parser.rb,
lib/diaspora_federation/validators/comment_validator.rb,
lib/diaspora_federation/validators/contact_validator.rb,
lib/diaspora_federation/validators/message_validator.rb,
lib/diaspora_federation/validators/profile_validator.rb,
lib/diaspora_federation/validators/reshare_validator.rb,
lib/diaspora_federation/parsers/relayable_json_parser.rb,
lib/diaspora_federation/validators/location_validator.rb,
lib/diaspora_federation/federation/diaspora_url_parser.rb,
lib/diaspora_federation/federation/receiver/exceptions.rb,
lib/diaspora_federation/validators/relayable_validator.rb,
lib/diaspora_federation/federation/sender/hydra_wrapper.rb,
lib/diaspora_federation/salmon/encrypted_magic_envelope.rb,
lib/diaspora_federation/validators/retraction_validator.rb,
lib/diaspora_federation/validators/web_finger_validator.rb,
lib/diaspora_federation/validators/poll_answer_validator.rb,
lib/diaspora_federation/validators/conversation_validator.rb,
lib/diaspora_federation/validators/participation_validator.rb,
lib/diaspora_federation/entities/account_migration/signable.rb,
lib/diaspora_federation/validators/optional_aware_validator.rb,
lib/diaspora_federation/validators/related_entity_validator.rb,
lib/diaspora_federation/validators/status_message_validator.rb,
lib/diaspora_federation/federation/receiver/abstract_receiver.rb,
lib/diaspora_federation/validators/account_deletion_validator.rb,
lib/diaspora_federation/validators/account_migration_validator.rb,
lib/diaspora_federation/validators/poll_participation_validator.rb,
lib/diaspora_federation/validators/event_participation_validator.rb

Overview

diaspora* federation library

Defined Under Namespace

Modules: Discovery, Entities, Federation, Logging, Parsers, PropertiesDSL, Salmon, Validators Classes: Callbacks, ConfigurationError, Entity, HttpClient

Constant Summary collapse

VERSION =

the gem version

"1.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Logging

included

Class Attribute Details

.callbacksCallbacks (readonly)

Callbacks instance with defined callbacks



56
57
58
# File 'lib/diaspora_federation.rb', line 56

def callbacks
  @callbacks
end

.certificate_authoritiesString .certificate_authorities=Object

Set the bundle of certificate authorities (CA) certificates

Overloads:

  • .certificate_authoritiesString

    Returns path to certificate authorities.

    Returns:

    • (String)

      path to certificate authorities

  • .certificate_authorities=Object

    Examples:

    config.certificate_authorities = AppConfig.environment.certificate_authorities.get

    Parameters:

    • value (String)

      path to certificate authorities



78
79
80
# File 'lib/diaspora_federation.rb', line 78

def certificate_authorities
  @certificate_authorities
end

.http_concurrencyInteger .http_concurrency=Object

Maximum number of parallel HTTP requests made to other pods (default: 20)

Overloads:

  • .http_concurrencyInteger

    Returns max number of parallel requests.

    Returns:

    • (Integer)

      max number of parallel requests

  • .http_concurrency=Object

    Examples:

    config.http_concurrency = AppConfig.settings.typhoeus_concurrency.to_i

    Parameters:

    • value (Integer)

      max number of parallel requests



103
104
105
# File 'lib/diaspora_federation.rb', line 103

def http_concurrency
  @http_concurrency
end

.http_redirect_limitInteger (readonly)

Max redirects to follow

Returns:

  • (Integer)

    max redirects



125
126
127
# File 'lib/diaspora_federation.rb', line 125

def http_redirect_limit
  @http_redirect_limit
end

.http_timeoutInteger .http_timeout=Object

Timeout in seconds for http-requests (default: 30)

Overloads:

  • .http_timeoutInteger

    Returns http timeout in seconds.

    Returns:

    • (Integer)

      http timeout in seconds

  • .http_timeout=Object

    Parameters:

    • value (Integer)

      http timeout in seconds



111
112
113
# File 'lib/diaspora_federation.rb', line 111

def http_timeout
  @http_timeout
end

.http_user_agentString (readonly)

User agent used for http-requests

Returns:

  • (String)

    user agent



129
130
131
# File 'lib/diaspora_federation.rb', line 129

def http_user_agent
  @http_user_agent
end

.http_verboseBoolean .http_verbose=Object

Turn on extra verbose output when sending stuff. (default: false)

Overloads:

  • .http_verboseBoolean

    Returns verbose http output.

    Returns:

    • (Boolean)

      verbose http output

  • .http_verbose=Object

    Examples:

    config.http_verbose = AppConfig.settings.typhoeus_verbose?

    Parameters:

    • value (Boolean)

      verbose http output



121
122
123
# File 'lib/diaspora_federation.rb', line 121

def http_verbose
  @http_verbose
end

.server_uriURI .server_uri=Object

The pod url

Overloads:

  • .server_uriURI

    Returns the server uri.

    Returns:

    • (URI)

      the server uri

  • .server_uri=Object

    Examples:

    with uri

    config.server_uri = URI("http://localhost:3000/")

    with configured pod_uri

    config.server_uri = AppConfig.pod_uri

    Parameters:

    • value (URI)

      the server uri



68
69
70
# File 'lib/diaspora_federation.rb', line 68

def server_uri
  @server_uri
end

.webfinger_http_fallbackBoolean .webfinger_http_fallback=Object

Configure if WebFinger discovery should fallback to http if https fails (default: false)

This is useful for example for development environments where https isn’t available.

This setting only applies to the WebFinger route from RFC 7033 /.well-known/webfinger. Legacy WebFinger flow unconditionally falls back to http.

Overloads:

  • .webfinger_http_fallbackBoolean

    Returns webfinger http fallback enabled.

    Returns:

    • (Boolean)

      webfinger http fallback enabled

  • .webfinger_http_fallback=Object

    Examples:

    config.webfinger_http_fallback = AppConfig.server.rails_environment == "development"

    Parameters:

    • value (Boolean)

      webfinger http fallback enabled



93
94
95
# File 'lib/diaspora_federation.rb', line 93

def webfinger_http_fallback
  @webfinger_http_fallback
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Configure the federation library

Examples:

DiasporaFederation.configure do |config|
  config.server_uri = URI("http://localhost:3000/")

  config.define_callbacks do
    # callback configuration
  end
end

Yields:

  • (_self)

Yield Parameters:



141
142
143
# File 'lib/diaspora_federation.rb', line 141

def configure
  yield self
end

.define_callbacks(&block) ⇒ Object

Define the callbacks

In order to communicate with the application which uses the diaspora_federation gem callbacks are introduced. The callbacks are used for getting required data from the application or posting data to the application.

Callbacks are implemented at the application side and must follow these specifications:

fetch_person_for_webfinger

Fetches person data from the application to form a WebFinger reply
@param [String] diaspora* ID of the person
@return [DiasporaFederation::Discovery::WebFinger] person webfinger data

fetch_person_for_hcard

Fetches person data from the application to reply for an HCard query
@param [String] guid of the person
@return [DiasporaFederation::Discovery::HCard] person hcard data

save_person_after_webfinger

After the gem had made a person discovery using WebFinger it calls this callback
so the application saves the person data
@param [DiasporaFederation::Entities::Person] person data

fetch_private_key

Fetches a private key of a person by her diaspora* ID from the application
@param [String] diaspora* ID of the person
@return [OpenSSL::PKey::RSA] key

fetch_public_key

Fetches a public key of a person by her diaspora* ID from the application
@param [String] diaspora* ID of the person
@return [OpenSSL::PKey::RSA] key

fetch_related_entity

Fetches a related entity by a given guid
@param [String] entity_type (Post, Comment, Like, etc)
@param [String] guid of the entity
@return [DiasporaFederation::Entities::RelatedEntity] related entity

queue_public_receive

Queue a public salmon xml to process in background
@param [String] data salmon slap xml or magic envelope xml

queue_private_receive

Queue a private salmon xml to process in background
@param [String] guid guid of the receiver person
@param [String] data salmon slap xml or encrypted magic envelope json
@return [Boolean] true if successful, false if the user was not found

receive_entity

After the xml was parsed and processed the gem calls this callback to persist the entity
@param [DiasporaFederation::Entity] entity the received entity after processing
@param [Object] recipient_id identifier for the recipient of private messages or nil for public,
  see {Receiver.receive_private}

fetch_public_entity

Fetch a public entity from the database
@param [String] entity_type (Post, StatusMessage, etc)
@param [String] guid the guid of the entity

fetch_person_url_to

Fetch the url to path for a person
@param [String] diaspora_id
@param [String] path

update_pod

Update the pod status
@param [String] url the pod url
@param [Symbol, Integer] status the error as {Symbol} or the http-status as {Integer} if it was :ok

Examples:

config.define_callbacks do
  on :some_event do |arg1|
    # do something
  end
end

Parameters:

  • block (Proc)

    the callbacks to define

See Also:



225
226
227
# File 'lib/diaspora_federation.rb', line 225

def define_callbacks(&block)
  @callbacks.instance_eval(&block)
end

.validate_configObject

Validates if the engine is configured correctly

called from after_initialize

Raises:



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/diaspora_federation.rb', line 233

def validate_config
  configuration_error "server_uri: Missing or invalid" unless @server_uri.respond_to? :host

  unless defined?(::Rails) && !::Rails.env.production?
    configuration_error "certificate_authorities: Not configured" if @certificate_authorities.nil?
    unless File.file? @certificate_authorities
      configuration_error "certificate_authorities: File not found: #{@certificate_authorities}"
    end
  end

  validate_http_config

  unless @callbacks.definition_complete?
    configuration_error "Missing handlers for #{@callbacks.missing_handlers.join(', ')}"
  end

  logger.info "successfully configured the federation library"
end