Skip to content

Instantly share code, notes, and snippets.

@jtroxel
jtroxel / snowflake_looker_roles.md
Created October 28, 2021 22:21
scheme to map Looker user attributes, defined by Groups, to a Snowflake Role and WH

An example scheme to map Looker user attributes, defined by Groups, to a Snowflake Role and WH

Lots of assumptions and assertions:

  • For Analytics data, we want to map on multiple dimensions
  • Map Compute (WH) by user Organization to track spending
  • Map Data Access (Grants) by user "Data Role" and Org, so that we can control access to schemas with sensitive or expensive data, or custom views for a particular org.
  • E.g.: Only some users should be able to see FLUENTD_EVENTS or AURORA data directly, and we might end up with Schemas like Revenue with custom stuff
  • We have looked at OAuth, but at this time it is untenable because it cant be used with PDTs and would make explore caches useless.
  • We are using a Service Account for Looker connections to Snowflake
  • The Tram "Information Architecture" is garbage, I wish I had never seen it
@jtroxel
jtroxel / snowflake_looker_roles.md
Created October 28, 2021 22:17
scheme to map Looker user attributes

An example scheme to map Looker user attributes, defined by Groups, to a Snowflake Role and WH

Lots of assumptions and assertions:

  • For Analytics data, we want to map on multiple dimensions
  • Map Compute (WH) by user's Organization to track spending
  • Map Data Access (Grants) by user's "Data Role" and Org, so that we can control access to schemas with sensitive or expensive data, or custom views for a particular org.
  • E.g.: Only some users should be able to see FLUENTD_EVENTS or AURORA data directly, and we might end up with Schemas like Revenue with custom stuff
  • We have looked at OAuth, but at this time it is untenable because it can't be used with PDTs and would make explore caches useless.
  • We are using a Service Account for Looker connections to Snowflake

So in this setup, we are authorizing as LOOKER_USER, but using the user attributes to construct the Role and WH:

@jtroxel
jtroxel / lib_fletrics.php
Created February 4, 2020 23:34
First whack at an ebstracted metrics api, that just happens to use an early form of an Event/Observer mechanism. The main ideas are to: 1) make is easy to write and read in client code 2) keep the client business logic free of resource dependencies 3) make it easy to swap out implementations of handlers, even allow multiple 4) pave the way for a…
<?php
use Flickr\Config\Config;
// Client example 1: Simple call to Event subclass (if the type is likely to be used more than once). Preferred way.
new VespaErrorEvent($type);
// Client example 2: In-line setup of generic AppEvent using a predefined handler.
new AppEvent("vespa.error{$type}", EventHandlers::metricCounter());
// Client example 3: In-line setup of generic AppEvent using lambda for act. Not sure this does anybody any good
@jtroxel
jtroxel / example_api_call_registerMigrationToken.js
Created January 18, 2019 02:54
example call for flickr.identity.registerMigrationToken
const request = require('superagent');
const flickr_endpoint = 'https://backstage-ext.flickr.com/services/rest/';
const flickr_method = 'flickr.identity.registerMigrationToken';
const flickr_api_key = '<api_key>';
const cookie_session = "<cookie_session_value>";
const sa_cookie = "<sa_value>";
request
@jtroxel
jtroxel / example_api_call_getUserAttributes.js
Created January 18, 2019 00:33
example call to flickr.identity.getUserAttributes method
const request = require('superagent');
const flickr_endpoint = 'https://backstage-ext.flickr.com/services/rest/';
const flickr_method = 'flickr.identity.getUserAttributes';
const flickr_api_key = '<get_the_api_key>';
request
.get(flickr_endpoint)
.query({
method: flickr_method,
@jtroxel
jtroxel / manage_restaurants.rb
Created March 15, 2015 20:47
ruby ActiveRecord worker logic
Vertx::EventBus.register_handler('manage-restaurants') do |message|
body = message.body
puts "Got message body #{body.inspect}"
case body['action']
when "create"
rest = Restaurant.new(body.slice('name'))
rest.save
message.reply "OK"
when "update"
id = body['id']
@jtroxel
jtroxel / server.js
Created March 15, 2015 20:39
UI integration with business logic
bus.send('manage-restaurants', // Event bus
// Payload
{
action: 'create',
name: name
},
// Reply handler
function (reply) {
console.log("Reply " + reply);
}
@jtroxel
jtroxel / server.js
Created March 14, 2015 02:00
Starting a server for routeMatcher
// Start a server listening to our routes
server.requestHandler(routeMatcher).listen(8080, 'localhost');
@jtroxel
jtroxel / server.js
Last active August 29, 2015 14:17
Javascript form post handler
// curl --data-urlencode "name=Thai Green and Sushi" -XPOST localhost:8080/restaurant
routeMatcher.post('/restaurant', function (req) {
console.log("Params: " + req.params());
req.expectMultiPart(true);
req.endHandler(function() {
// The request has been all ready so now we can look at the form attributes
var formAttributes = req.formAttributes();
var name = formAttributes.get('name');
<section data-ng-controller="PostsController" data-ng-init="find()">
<div class="page-header">
<h1>Posts</h1>
</div>
<div class="list-group">
<a data-ng-repeat="post in posts" data-ng-href="#!/posts/{{post._id}}" class="list-group-item">
<small class="list-group-item-text">
Posted on
<span data-ng-bind="post.created | date:'medium'"></span>
by