Skip to content

Instantly share code, notes, and snippets.

@sohalloran
sohalloran / webhook.py
Created February 9, 2024 15:57
Webhook python service for lambda - used by the terraform script
from __future__ import print_function
from datetime import datetime
import boto3, os, json
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
now = datetime.now()
s3 = boto3.resource('s3')
@sohalloran
sohalloran / Webhook_for_DataCloud
Created February 9, 2024 15:56
Webhook for Data Cloud Data Action. Create a lambda function to take a request and store it in an S3 bucket. Create the destination S3 bucket. Assign roles and policies. Output the new webhook endpoint
# Webhook for Data Cloud Data Action
# Create a lambda function to take a request and store it in an S3 bucket
# Create the destination S3 bucket
# Assign roles and policies
# Output the new webhook endpoint
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
@sohalloran
sohalloran / S3_for_DataCloud.tf
Last active February 9, 2024 15:59
Creates an S3 bucket, uploads a CSV data file into the S3 bucket. Creates a user with the necessary roles for Data Cloud to access the data. Outputs the credentials to use in the Data Cloud config. (Note the secret will only be visible by reading the .tfstate file)
# Creates an S3 bucket
# Uploads a CSV data file into the S3 bucket
# Create a user with the necessary roles for Data Cloud to access the data
# Output the credentials to use in the Data Cloud config
# (Note the secret will only be visible by reading the .tfstate file)
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
/* APEX */
public class AccountCount {
@AuraEnabled(cacheable=true)
public static Integer getCount() {
return [select count() from Account];
}
}
/* LWC (JS) */
import { LightningElement, wire } from "lwc";
const crypto = require("crypto");
const algorithm = "aes-256-cbc";
const ENCRYPTION_KEY = Buffer.from(
"b7zfYEKhkmVrl9P3yGN/p+3AOkjWK5D6s2JOJzW6lpo=",
"base64",
);
const IV_LENGTH = 16;
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
/*
Apex encryption
String clearText = 'A sample message';
String key = 'b7zfYEKhkmVrl9P3yGN/p+3AOkjWK5D6s2JOJzW6lpo=';
Blob cipherText = Crypto.encryptWithManagedIV('AES256', EncodingUtil.base64Decode(key), Blob.valueOf(clearText));
String encodedCipherText = EncodingUtil.base64Encode(cipherText);
System.debug(key);
System.debug(encodedCipherText);
*/
#!/bin/sh
mkdir pdfs
cd pdfs
curl -LO https://developer.salesforce.com/resource/pdfs/Lightning_Components_Cheatsheet.pdf
curl -LO https://resources.docs.salesforce.com/sfdc/pdf/actions_impl_guide.pdf
curl -LO https://resources.docs.salesforce.com/sfdc/pdf/analytics.pdf
curl -LO https://resources.docs.salesforce.com/sfdc/pdf/apex_ajax.pdf
curl -LO https://resources.docs.salesforce.com/sfdc/pdf/apex_api.pdf
<apex:page id="PersistentLoginPage"
applyBodyTag="false"
applyHtmlTag="false"
showHeader="false"
showChat="false"
sidebar="false"
standardStylesheets="false"
action="{!persistentLogin}"
controller="PersistentLoginController">
/*
Run Client App Auth Flow - as follows
1. Request a JWT to be created for a Community user from an IDP org with a csid
2. Pass the JWT to the SP org for an access token using the Oauth JWT bearer flow
3. If we get an 'invalid_grant' then send the JWT to a registration service for Just In Time user provisioning
4. On success retry the Oauth JWT bearer flow (step 2)
5. On success verify it works with an example API call to query the user object
- Components
- NodeJS App to Simulate a Client App
while getopts m:b:d:n: option
do
case "${option}"
in
m) MESSAGE=${OPTARG};;
b) BRANCH=${OPTARG};;
d) DEFAULTORG=${OPTARG};;
n) SCRATCHORGNAME=${OPTARG};;
esac
done