npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@johnlewisandpartners/composer-dag-trigger

v1.0.4

Published

Module that makes it easy to trigger a dag on GCP composer

Downloads

8

Readme

Composer Dag Trigger

This is a module that can be used to trigger a DAG on GCP composer. It handles all the authentication so that this can be easily added to a cloud function.
It is adapted from https://cloud.google.com/composer/docs/how-to/using/triggering-with-gcf

Setup

To authenticate to Cloud IAP, grant the Appspot Service Account (used by Cloud Functions) the Service Account Token Creator role on itself. To do this, execute the following command in the gcloud command-line tool or Cloud Shell:

gcloud iam service-accounts add-iam-policy-binding \
[email protected] \
--member=serviceAccount:[email protected] \
--role=roles/iam.serviceAccountTokenCreator

Usage

  const composerTriggerDag = require('@johnlewisandpartners/composer-dag-trigger');

  exports.triggerDag = function triggerDag(event, callback) {
    const DAG_NAME = 'my_dag';
    const CURRENT_DATE = new Date();
    const runId = `my-trigger-run_${CURRENT_DATE.toISOString()}`;
    const data = {
        data_to_pass: 'test_data'
    };
    const AIRFLOW_WEB_URL = 'https://xxxxxxxxxxxxxxxxx-tp.appspot.com'
    const PROJECT_ID = 'your-project-id'
    const CLIENT_ID =  'xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com'
    const triggerDagParams = {
        dagName: DAG_NAME,
        runId,
        data,
        composerWebUrl: AIRFLOW_WEB_URL,
        projectId: PROJECT_ID,
        clientId: CLIENT_ID,
        callback,
   };

   composerTriggerDag.triggerDag(triggerDagParams);
  }

DAG_NAME should be the name of the dag you want to trigger.
runId is an optional param allowing you to specify the run id in airflow.
data is a JSON object containing data that you want to pass to the dag. This is available in the dag in the conf object.
AIRFLOW_WEB_URL should be the base URL of your composer instance.
PROJECT_ID should be the GCP project that airflow is in.
CLIENT_ID is the client id of the identity aware proxy running in front of composer. This can either be retrieved by navigating to composer and taking it from the sign in page, or by using this command

COMPOSER_ENVIRONMENT=mycomposerinstance
COMPOSER_LOCATION=europe-west-1
AIRFLOW_WEB_URL=`gcloud composer environments describe ${COMPOSER_ENVIRONMENT} --location ${COMPOSER_LOCATION} --format="get(config.airflow_uri)"`

# get the client id to be used in the trigger script so it can do proper oauth
CLIENT_ID=`curl ${AIRFLOW_WEB_URL} -I -s | grep -i "^location: "|grep -o "[?&]client_id=[^&]*"|cut -d= -f2`
echo $CLIENT_ID