atlassian_connect_host 0.5.6 copy "atlassian_connect_host: ^0.5.6" to clipboard
atlassian_connect_host: ^0.5.6 copied to clipboard

outdatedDart 1 only

Atlassian Connect services for interacting with Atlassian product host

Atlassian Connect Host Services #

Introduction #

Provides services for Atlassian product host related activities such as:

  • automatically installing the addon on startup (dev mode only)
  • handling product host installation lifecycle events
  • signing (jwt) requests to the host
  • persisting host registration information (with pluggable persistence providers)
  • authenticating requests from an Atlassian host
  • creating addon session tokens (based on information from host request)
  • authenticating addon session tokens

This library can be used on it's own (e.g. as part of your own custom Dart based Atlassian Connect client framework) or as part of the Atlassian Connect Shelf based server.

Using #

Basic Usage #

Create a Host Registration Repository

The library provides an interface for repository implementations. The interface is very simple

abstract class AcHostRegistrationRepository {

  Future<AcHostRegistration> create(AcHostRegistration hostRegistration);

  Future<Option<AcHostRegistration>> findRegistrationByHostKey(String hostKey);
}

It consists of one method to create a new registration entry and one to look up by host key.

You can create your own implementation to whatever data store you like without much effort.

Currently, two implementations are provided out of the box

  • AcHostRegistrationInMemoryTestRepository. A simple in memory implementation suitable for testing and development mode only. It is very convenient as it doesn't require any set up
  • AcHostRegistrationMongoRepository. A Mongo DB implementation

To create a Mongo DB repository first follow instructions on setting up a mongo instance then call

DB db // create the mongo client DB object

final repo = new AcHostRegistrationMongoRepository(db);

Create an AddonHost object

An AddonHost represents (surprisingly) the addon host itself. Create one like so

final addonHost = new AddonHost(addonKey, baseUrl, addonSecret);

Note the addonSecret is only needed if you want to use the addon session token mechanism.

Create the AcHostService object

Now you have all you need to create a host service object

final hostService = new AcHostService(repo, addonHost);

Now you can use it as follows.

Initiate Host Installation (dev mode)

The following will attempt to contact the host with the give base url and initiate installation of the addon

hostService.installAddonToHost(hostBaseUri);

Handle the Installation Event by Registering the Host

When you get an installation lifecycle event from a host, call the registerHost method with the event (after decoding the json)

hostService.registerHost(installationEvent);

Send an HTTP Request to a Host

For example the following sends a request to Jira to fetch an issue

final jiraResponse = hostService.httpClientForHostKey(hostKey)
    .then((httpClient) => httpClient.get('rest/api/2/issue/$issueKey', signRequest: true))
    .then((req) => req.close());

jiraResponse
    .then(HttpBodyHandler.processResponse)
    .then((body) {   
       Map issueJson = body.body;
       // do something with the issue json
    });
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Atlassian Connect services for interacting with Atlassian product host

Homepage

License

unknown (LICENSE)

Dependencies

atlassian_connect_jwt, atlassian_connect_models, constrain, gcloud, http_server, logging, mongo_dart, option, path, quiver, shelf_oauth, uri, xml

More

Packages that depend on atlassian_connect_host