2017 © Pedro Peláez
 

symfony-bundle atlassian-connect-bundle

Atlassian Connect Symfony Bundle

image

thecatontheflat/atlassian-connect-bundle

Atlassian Connect Symfony Bundle

  • Wednesday, March 7, 2018
  • by thecatontheflat
  • Repository
  • 5 Watchers
  • 27 Stars
  • 440 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 2 Open issues
  • 15 Versions
  • 4 % Grown

The README.md

Atlassian Connect Bundle

Build Status Code Coverage Scrutinizer Code Quality License Latest Stable Version Total Downloads, (*1)

About

Symfony Bundle for Atlassian Connect platform, (*2)

Installation

Step 1. Add bundle to composer dependencies

composer require thecatontheflat/atlassian-connect-bundle

Step 2. Enable the bundle

Add the bundle to config/bundles.php, (*3)

<?php

return [
    // ... other bundles
    AtlassianConnectBundle\AtlassianConnectBundle::class => ['all' => true],
]

Step 3. Bundle configuration

The bundle descriptor is used to install your app on Atlassian. When requesting descriptor - this configuration is converted to JSON., (*4)

Sample configuration in packages/atlassian-connect.yaml:, (*5)

    atlassian_connect:
        dev_tenant: 1
        descriptor:
            key: 'your-addon-key'
            name: 'Your Add-On Name'
            description: 'Your Add-On Description'
            authentication:
                type: jwt
            vendor:
                name: 'Your Vendor Name'
                url: 'https://marketplace.atlassian.com/vendors/1211528'
            baseUrl: 'https://your-production-domain.com/'
            lifecycle:
                installed: '/handshake'
            scopes: ['READ', 'WRITE', 'ACT_AS_USER'] # If you want get oauth_client_id need to add scope ACT_AS_USER
            modules:
                jiraIssueTabPanels:
                    -
                        key: 'your-addon-key-tab'
                        url: '/protected/list?issue=${issue.key}'
                        weight: 100
                        name:
                            value: 'Tab Name'

If you need to overwrite any config in dev/test environment, overwrite that config in the packages/{env}/atlassian-connect.yaml file., (*6)

Step 4. Security configuration

To configure security part - use the following configuration in your security.yml. If you have another firewall that has the "^/" pattern, be sure to set the jwt_secured_area firewall first., (*7)

    security:
        enable_authenticator_manager: true
        providers:
            jwt_user_provider:
                id: jwt_user_provider
        firewalls:
            jwt_secured_area:
                custom_authenticators:
                    - AtlassianConnectBundle\Security\JWTAuthenticator
                pattern: "^/protected"
                stateless: true
                provider: jwt_user_provider
                # If you also need an entry_point
                entry_point: AtlassianConnectBundle\Security\JWTAuthenticator

Step 5. Include Routes

Add the following configuration to config/routes.yaml:, (*8)

    ac:
        resource: "@AtlassianConnectBundle/Resources/config/routing.php"

Step 6. (Optional): Configure License Check

To perform a license check for a certain route - specify the requires_license default in your routing.yml, (*9)

    some_route:
        path: ...
        defaults:
            requires_license: true

Step 7. Update Database

bin/console doctrine:schema:update --force

Usage Examples

Signed Request

In your protected controller action you can make a signed request to JIRA instance:, (*10)

<?php declare(strict_types = 1);

namespace App\Controller;

use AtlassianConnectBundle\Service\AtlassianRestClient;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

/**
 * @Route("/protected")
 */
class ProtectedController extends Controller
{
    /**
     * @Route("/", name="main")
     */
    public function index()
    {
        $client = $this->container->get(AtlassianRestClientInterface::class);
        // Or
        // $client = $this->container->get('atlassian_connect_rest_client');

        // If you are not in a security context fetch the tenant first
        // $client->setTenant($tenant);

        // If you want to impersonate the user
        // $client->actAsUser($this->getUser()->getUserName())

        // Send request from anonymous plugin user
        $issue = $client->get('/rest/api/2/issue/KEY-XXX');

        // Send request from choosen user
        $user = $client
            ->setUser('5ds4e4352a12451789b13243') // the accountId of the user in Jira/Confluence etc.
            ->get('/rest/api/2/myself')
        ;

        return new Response([$issue, $user]);
    }
}

Whitelisting licences

You could whitelist any licence by editing related row in table tenant and setting field is_white_listed to 1. If you will also set white_listed_until - you will be able to set whitelist expiration, (*11)

Dev environment

In dev environment Tenant with id=1 would be used automatically. You could set configuration variable atlassian_connect.dev_tenant to false in order to disable it, or use another dev tenant id. It would allow you to test your plugin output for any tenant., (*12)

Custom tenant entity

If you need to add more properties to tenant entity or reverse-side of your app entity relations - you could override default Tenant entity like, (*13)

<?php
    namespace AppBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;
    use AtlassianConnectBundle\Entity\TenantTrait;
    use AtlassianConnectBundle\Entity\TenantInterface;
    use Symfony\Component\Security\Core\User\UserInterface;

    /**
     * JiraTenant
     *
     * @ORM\Table()
     * @ORM\HasLifecycleCallbacks()
     * @ORM\Entity()
     */
    class JiraTenant implements UserInterface, TenantInterface
    {
        /**
         * @ORM\OneToMany(type="MyEntity", mappedBy="jiraTenant")
         */
        protected $myEntities;

        use TenantTrait;    

        // getters/setters for your custom properties
    }

And override default one by setting parameter, (*14)

    atlassian_connect_tenant_entity_class: AppBundle\Entity\JiraTenant

In order to use it you will need to disable doctrine automapping, (*15)

    auto_mapping: false
        mappings:
            AppBundle: ~

Troubleshooting

Cant start free trial of my plugin on Jira Cloud

As soon as you will create your plugin - you will be able to access plugin manifest via url https://yourplugindomain.com/atlassian-connect.json, (*16)

You will be able to setup it in "Manage Addons" section of your Jira Cloud using "Upload addon" interface. But right now AtlassianConnectBundle support only "paid via Atlassian" model, so you will not be able to start your trial., (*17)

Instead of using manifest url directly - you should add private listing of your plugin, create token and get manifest url like, (*18)

https://marketplace.atlassian.com/files/1.0.0-AC/artifact/descriptor/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/atlassian-connect.json?access-token=xxxxxxxx, (*19)

If you will use that url from marketplace - your trial will be started automatically., (*20)

The Versions

09/06 2017

1.0.0.x-dev

1.0.0.9999999-dev

Atlassian Connect Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

by Vitaliy Zurian

09/06 2017

1.0.0

1.0.0.0

Atlassian Connect Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

by Vitaliy Zurian

23/04 2017

0.2.1

0.2.1.0

Atlassian Connect Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

by Vitaliy Zurian

01/05 2016

0.2.0

0.2.0.0

Atlassian Connect Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

by Vitaliy Zurian

30/09 2015

0.0.1

0.0.1.0

Atlassian Connect Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

by Vitaliy Zurian

30/09 2015

0.1.0

0.1.0.0

Atlassian Connect Symfony2 Bundle

  Sources   Download

MIT

The Requires

 

by Vitaliy Zurian