Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Couchbase Mobile

Couchbase Mobile

Avatar for James Nocentini

James Nocentini

July 15, 2015

More Decks by James Nocentini

Other Decks in Programming

Transcript

  1. Topics • App Server • Data modelling • Sync Function

    • Enabling SSL • Continuous deployment
  2. ES6 Goodies • Template string, string interpolation • Fat Arrow

    functions • Constants • Modules, Classes • Generator, Promises, Proxies
  3. name : hideki password : letmein name : pasin password

    : letmein name : jim password : letmein access(user_name, channel_names) channel(channel_name) role(role_name, channel_name) requireAccess(channel_name) requireRole(role_name) requireUser(user_name)
  4. Sync Function • Read: access • Write: requireAccess, requireUser, requireRole

    • Grant a user access to multiple channels by simply assigning a role • Any user can give another user access to the Sync Function
  5. name : hideki password : letmein name : pasin password

    : letmein name : jim password : letmein access(user_name, channel_names) channel(channel_name) role(role_name, channel_name) requireAccess(channel_name) requireRole(role_name) requireUser(user_name)
  6. name : hideki password : letmein name : pasin password

    : letmein name : jim password : letmein channel(channel_name) role(role_name, channel_name)
  7. Sync Function User 1 User 2 User 3 Channel X

    Channel Y Channel Z Channel X Channel Y Channel Z Channel X Channel Y
  8. function(doc, oldDoc) { if (doc.type == "task") { channel("list-" +

    doc.list_id); } else if (doc.type == "list") { channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id); } else if (doc.type == "profile") { channel("profiles"); access(doc._id, "profiles"); } } { "_id": "[email protected]", "type": "profile" } Sync  Gateway list-123 list-453 profiles Sync Function
  9. function(doc, oldDoc) { if (doc.type == "task") { channel("list-" +

    doc.list_id); } else if (doc.type == "list") { channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id); } else if (doc.type == "profile") { access(doc._id, "profiles"); } } { "_id": "123" "type": "list", "title": "Home List", "owner": "[email protected]", "members": [ "[email protected]", "[email protected]" ] } Sync  Gateway list-123 list-453 profiles Sync Function
  10. function(doc, oldDoc) { if (doc.type == "task") { channel("list-" +

    doc.list_id); } else if (doc.type == "list") { channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id); } else if (doc.type == "profile") { access(doc._id, "profiles"); } } { "_id": "999" "type": "task", "list_id": "123", "title": "Buy some hummus" } Sync  Gateway list-123 list-453 profiles Sync Function
  11. function(doc, oldDoc) { if (doc.type == "task") { channel("list-" +

    doc.list_id); } else if (doc.type == "list") { channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id); } else if (doc.type == "profile") { access(doc._id, "profiles"); } } { "_id": "123" "type": "list", "title": "Home List", "owner": "[email protected]", "members": [ "[email protected]", "[email protected]" ] } Sync  Gateway list-123 list-453 profiles Sync Function
  12. P2P

  13. P2P

  14. Enabling SSL • Enabling SSL • It’s important for your

    users data! • Sync Gateway config • Replicator config
  15. WWDC 2015 "App Transport Security (ATS) lets an app add

    a declaration to its Info.plist file that specifies the domains with which it needs secure communication. ATS prevents accidental disclosure, provides secure default behaviour, and is easy to adopt. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one. If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible."
  16. Sync Gateway Android iOS {
 "SSLCert": "/path/to/cert.pem",
 "SSLKey": "/path/to/privkey.pem",
 "databases":

    {
 "db": {
 "server": "walrus:"
 }
 }
 } sync-gateway-config.json Application.java AppDelegate.swift private static final String SYNC_URL = "https://10.10.106.24:4984/db/"; Replication pull = database.createPullReplication(SYNC_URL);
 pull.setContinuous(true); 
 pull.start(); let SYNC_URL = "https://10.10.106.24:4984/db/" let pull = database.createPullReplication(SYNC_URL) pull.continuous = true pull.start()
  17. Self signed certificates $ openssl genrsa -out privkey.pem 2048 $

    openssl req -new -x509 -key privkey.pem -out cert.pem -days 1095 Source: https://www.openssl.org/docs/HOWTO/certificates.txt
  18. Sync Gateway $ docker run -d -p 4984:4984 -p 4985:4985

    couchbase/sync-gateway http://git.io/vq25r $ docker run -d -p 8091:8091 couchbase/server
  19. Gulp /Users/jamesnocentini/Downloads/couchbase-sync-gateway/bin/sync_gateway —-help -adminInterface="127.0.0.1:4985": Address to bind admin interface to

    -bucket="sync_gateway": Name of bucket -configServer="": URL of server that can return database configs -dbname="": Name of Couchbase Server database (defaults to name of bucket) -deploymentID="": Customer/project identifier for stats reporting -interface=":4984": Address to bind to -log="": Log keywords, comma separated -logFilePath="": Path to log file -personaOrigin="": Base URL that clients use to connect to the server -pool="default": Name of pool -pretty=false: Pretty-print JSON responses -profileInterface="": Address to bind profile interface to -url="walrus:": Address of Couchbase server -verbose=false: Log more info about requests Source: https://www.openssl.org/docs/HOWTO/certificates.txt
  20. Gulp $ gulp --server "walrus:" $ gulp --server "http://localhost:8091" Source:

    https://www.openssl.org/docs/HOWTO/certificates.txt
  21. Restarting Sync Gateway 1.Setup repo for your Sync Gateway Config

    2.Setup Circle CI with the GitHub repo 3.Run the container with the new config: $ gulp production $ docker run -d -p 4984:4984 \ -p 4985:4985 \ couchbase/sync-gateway \ ./dist/sync_gateway_config.json 4.Resync the database: $ curl -vX POST -H 'Content-Type: application/json' \ :4985/db/_resync/
  22. What’s coming: BLIP You can think of BLIP as an

    extension that adds a number of useful features that aren't supported by the WebSocket protocol