Git Product home page Git Product logo

cdk-github's Introduction

npm version PyPI version NuGet version Maven Central release
cdk-constructs: Experimental View on Construct Hub

CDK-GitHub

GitHub Constructs for use in AWS CDK .

This project aims to make GitHub's API accessible through CDK with various helper constructs to create resources in GitHub.
The target is to replicate most of the functionality of the official Terraform GitHub Provider.

Internally AWS CloudFormation custom resources and octokit are used to manage GitHub resources (such as Secrets).

๐Ÿ”ง Installation

JavaScript/TypeScript:
npm install cdk-github

Python:
pip install cdk-github

Java

Maven:
<dependency>
  <groupId>io.github.wtfjoke</groupId>
  <artifactId>cdk-github</artifactId>
  <version>VERSION</version>
</dependency>
Gradle:

implementation 'io.github.wtfjoke:cdk-github:VERSION'

Gradle (Kotlin):

implementation("io.github.wtfjoke:cdk-github:VERSION")

C#
See https://www.nuget.org/packages/CdkGithub

๐Ÿ“š Constructs

This library provides the following constructs:

๐Ÿ”“ Authentication

Currently the constructs only support authentication via a GitHub Personal Access Token. The token needs to be a stored in a AWS SecretsManager Secret and passed to the construct as parameter.

๐Ÿ‘ฉโ€๐Ÿซ Examples

The API documentation and examples in different languages are available on Construct Hub.
All (typescript) examples can be found in the folder examples.

ActionSecret

import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
import { ActionSecret } from 'cdk-github';

export class ActionSecretStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const githubTokenSecret = Secret.fromSecretNameV2(this, 'ghSecret', 'GITHUB_TOKEN');
    const sourceSecret = Secret.fromSecretNameV2(this, 'secretToStoreInGitHub', 'testcdkgithub');

    new ActionSecret(this, 'GitHubActionSecret', {
      githubTokenSecret,
      repository: { name: 'cdk-github', owner: 'wtfjoke' },
      repositorySecretName: 'A_RANDOM_GITHUB_SECRET',
      sourceSecret,
    });
  }
}

ActionEnvironmentSecret

import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
import { ActionEnvironmentSecret } from 'cdk-github';

export class ActionEnvironmentSecretStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const githubTokenSecret = Secret.fromSecretNameV2(this, 'ghSecret', 'GITHUB_TOKEN');
    const sourceSecret = Secret.fromSecretNameV2(this, 'secretToStoreInGitHub', 'testcdkgithub');

    new ActionEnvironmentSecret(this, 'GitHubActionEnvironmentSecret', {
      githubTokenSecret,
      environment: 'dev',
      repository: { name: 'cdk-github', owner: 'wtfjoke' },
      repositorySecretName: 'A_RANDOM_GITHUB_SECRET',
      sourceSecret,
    });
  }
}

GitHubResource

import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
import { StringParameter } from 'aws-cdk-lib/aws-ssm';
import { GitHubResource } from 'cdk-github';


export class GitHubResourceIssueStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const githubTokenSecret = Secret.fromSecretNameV2(this, 'ghSecret', 'GITHUB_TOKEN');
    // optional
    const writeResponseToSSMParameter = StringParameter.fromSecureStringParameterAttributes(this, 'responseBody', { parameterName: '/cdk-github/encrypted-response' });

    new GitHubResource(this, 'GitHubIssue', {
      githubTokenSecret,
      createRequestEndpoint: 'POST /repos/WtfJoke/dummytest/issues',
      createRequestPayload: JSON.stringify({ title: 'Testing cdk-github', body: "I'm opening an issue by using aws cdk ๐ŸŽ‰", labels: ['bug'] }),
      createRequestResultParameter: 'number',
      deleteRequestEndpoint: 'PATCH /repos/WtfJoke/dummytest/issues/:number',
      deleteRequestPayload: JSON.stringify({ state: 'closed' }),
      writeResponseToSSMParameter,
    });
  }
}

๐Ÿ’– Contributing

Contributions of all kinds are welcome! Check out our contributing guide.

cdk-github's People

Contributors

bautobot avatar chatii avatar wtfjoke avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

chatii

cdk-github's Issues

`ActionSecret` and `ActionEnvironmentSecret` should support JSON secrets

I have secrets created by https://github.com/time-loop/cdk-user-with-access-key which consist of a JSON blob with two keys. I want to copy both these keys over to a GH Env Secret.

This construct almost does what I need. Would you be open to refactoring it to either work with a https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.SecretValue.html as input or to add intelligence to the lambda so that it detects when the secret is a JSON blob? Maybe have the option to pass undefined as the repositorySecretName which tells the lambda that it should parse the inbound secret and publish a number of secrets?

repository props should be an interface `IRepository`

Instead of passing repositoryName and repositoryOwner, pass a single repository prop, which is an interface IRepository:

interface IGitHubRepository {
  owner: string
  name: string
}

/**
* The GitHub repository name
*/
readonly repositoryName: string;
/**
* The GitHub repository owner
* @default - user account which owns the token
*/
readonly repositoryOwner?: string;

Then your main GitHub construct would implement this interface.

Environment Secrets cannot create/update

When creating or updating Environment Secrets, the value becomes an empty string (blank).
ref: https://github.com/orgs/community/discussions/48430

It seemed that the Public key used for string encryption was different, so I created a commit like the one below, but the value still turns out to be an empty string.
commit: chatii@8213314

When the encrypted string is updated with gh api via a PUT request, it gets updated properly. Is it possible to fix this? Do you have any hints or suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.