AtlasCamp 2014: Writing Connect Add-ons for Confluence

53
June 3-5, 2014 | Berlin, Germany

description

This AtlasCamp, we're talking a lot about Atlassian Connect and the new Confluence REST API. This session will bring it all together with an overview on building a Connect add-on with Confluence. We will cover best practices when writing complex dynamic macros with respect to security, performance and maintainability.

Transcript of AtlasCamp 2014: Writing Connect Add-ons for Confluence

Page 1: AtlasCamp 2014: Writing Connect Add-ons for Confluence

June 3-5, 2014 | Berlin, Germany

Page 2: AtlasCamp 2014: Writing Connect Add-ons for Confluence

@matthewjensen

Matthew Jensen, Confluence Ecosystem, Atlassian

Writing Connect Add-ons for Confluence

Page 3: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• About Me:!• Almost 7.5 years at Atlassian

Introduction

81%

19%

Page 4: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• About Me:!• Almost 7.5 years at Atlassian!• Over four years on Confluence

development

Introduction

81%

9%

10%

Page 5: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Why is it so hard to write a Confluence plugin?

— Matthew Jensen, Confluence Ecosystem”

Page 6: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Confluence Ecosystem

Page 7: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Confluence Platform

Spac

es

Que

stio

ns

? ?????

Page 8: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Connect and

Confluence

Page 9: AtlasCamp 2014: Writing Connect Add-ons for Confluence

SAMEBUT DIFFERENT

SAME

Page 10: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Confluence Connect

DESIGN

SECURITY

PERFORMANCE

MACROS

Page 11: AtlasCamp 2014: Writing Connect Add-ons for Confluence

HiliteMeM AC R O S

Page 12: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Example

Consider a macro to pretty print your code

M AC R O S

Page 13: AtlasCamp 2014: Writing Connect Add-ons for Confluence

ExampleM AC R O S

This macro can make any code look great!

Page 14: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Example

http://bitbucket.org/mjensen/hilite-me-addon

M AC R O S

Page 15: AtlasCamp 2014: Writing Connect Add-ons for Confluence
Page 16: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Can be of any size!• Can contain sensitive information

Macro Body

CONFIDENTIAL

M AC R O S

Page 17: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Only use HTTP GET operations!• Flexibility!• This concern is new with Connect

Macro BodiesM AC R O S

Page 18: AtlasCamp 2014: Writing Connect Add-ons for Confluence

VSDynamic Macros

Static Macros

Page 19: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Dynamic Content MacrosConfluence Add onBrowser

Request

HTML

IFrame

Unformatted Code

Formatted

Requested

Returned

Macro Loaded

M AC R O S

Page 20: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Dynamic Content Macros are good:!• when they can take a while to load!• when it involves a third-party integration!• requires authentication to collect the body!• when your macro is block macro

Dynamic Content MacrosM AC R O S

Page 21: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Static Content MacrosConfluence Add onBrowser

Request

Unformatted Code

Formatted Code

Requested

Returned

M AC R O S

Page 22: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Static Content Macros are good:!• when you have many on the page!• when the body is small or not sensitive!• when you can avoid authentication

Static Content MacrosM AC R O S

Page 23: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• The Code Format Macro is a Dynamic Content Macro:!• the body can be of any size!• it integrates with a third party!• its hard to predict the render time or the size of the output

Code Format MacroM AC R O S

Page 24: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Confluence Connect

DESIGN

SECURITY

PERFORMANCE

MACROS

Page 25: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Example

• Consider a simple connect macro to include a status indicator on your page!

• Status as a parameter, and no body.

P E R F O R M A N C E

Page 26: AtlasCamp 2014: Writing Connect Add-ons for Confluence

ExampleP E R F O R M A N C E

http://bitbucket.org/mjensen/status-addon

Page 27: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Static Content MacrosConfluence Add onBrowser

status=Awesome

Awesome

Requested

Returned

P E R F O R M A N C E

Cached

Page 28: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Design allows for aggressive cache settings!• You should set appropriate cache headers for your all your

resources

Caching

res.setHeader(!!! ! 'Cache-Control',!!! ! ['private','max-age=3600']!);

routes/index.js

P E R F O R M A N C E

Page 29: AtlasCamp 2014: Writing Connect Add-ons for Confluence
Page 30: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• A versioned URL allows you to control when your cached content is refreshed

Versioned URLs

app.get('/v1/my-macro',! function (req, res) { … }!)

routes/index.js

P E R F O R M A N C E

Page 31: AtlasCamp 2014: Writing Connect Add-ons for Confluence
Page 32: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• The macro body can be passed as a parameter!• This can allow you to use caching on your resources, even

when the body is needed

Body as a Parameter

"staticContentMacros": [{! "url": "/macro?body={macro.body}", ! …!}]

atlassian-connect.json

P E R F O R M A N C E

Page 33: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Body as a ParameterConfluence Add onBrowser

Rendered

Requested

Returned

body=Awesome

P E R F O R M A N C E

Cached

Page 34: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Body is limited to 128 characters!• May appear in Confluence logs!• May be tracked in caches or proxies

Body as a ParameterP E R F O R M A N C E

Page 35: AtlasCamp 2014: Writing Connect Add-ons for Confluence
Page 36: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Some integrations happen synchronously!• Remote Conditions and Static Content Macros

Synchronous Callbacks

Confluence Add onBrowser

Request

Slow Response

!#$

P E R F O R M A N C E

Page 37: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Confluence Connect

DESIGN

SECURITY

PERFORMANCE

MACROS

Page 38: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Do you need to store any data at all?

Data StorageS E C U R I T Y

Page 39: AtlasCamp 2014: Writing Connect Add-ons for Confluence
Page 40: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Web Security

Vulnerable area

Permitted to user Permitted to add on

S E C U R I T Y

READADMIN

Page 41: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Use JWT for simple integration with Confluence REST api!• Define your scopes to be as restrictive as possible

Web Security

{! "key": "my-addon",! "scopes": [ "read" ],! "authentication": { "type": "jwt" },! …!} atlassian-connect.json

S E C U R I T Y

Page 42: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Confluence Connect

DESIGN

SECURITY

PERFORMANCE

MACROS

Page 43: AtlasCamp 2014: Writing Connect Add-ons for Confluence

• Static add ons contain only html and javascript files

Static Add Ons

Confluence Add onBrowser

D E S I G N

Page 44: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Coming Up

Page 45: AtlasCamp 2014: Writing Connect Add-ons for Confluence

BlueprintsC O M I N G U P

Page 46: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Blueprints

"blueprints": [{! "key": "hello-world-blueprint",! "name": { "value": "Hello World Blueprint" },! "template": {! "url": “/blueprints/hello-world.xml”! },! "icon": { "url": "/blueprints/hello-world.png" }!}]

atlassian-connect.json

C O M I N G U P

Page 47: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Blueprints

<table><tbody>! <tr><th>Name</th><th>Date</th></tr>! <tr>! <td>! <ac:placeholder>Enter today's date here</ac:placeholder>! </td>! <td>! <at:var at:name="user"/>! </td>! </tr>!</tbody></table>

atlassian-connect.json

C O M I N G U P

Page 48: AtlasCamp 2014: Writing Connect Add-ons for Confluence

BlueprintsC O M I N G U P

Page 49: AtlasCamp 2014: Writing Connect Add-ons for Confluence

BlueprintsC O M I N G U P

Page 50: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Blueprints

https://bitbucket.org/mjensen/hello-blueprint-connect

https://ecosystem.atlassian.net/browse/AC-1082

Example Plugin

Blueprints Ongoing Work

Help us set the direction!

C O M I N G U P

Page 51: AtlasCamp 2014: Writing Connect Add-ons for Confluence

CQLC O M I N G U P

Page 52: AtlasCamp 2014: Writing Connect Add-ons for Confluence

We need you!

Yes you!

C O M I N G U P

Page 53: AtlasCamp 2014: Writing Connect Add-ons for Confluence

Questions?@matthewjensen

[email protected]