How to: Secrets Mapping on GitHub

  1. PowerShell script will receive the following parameters:
  • $PAT = Personal Access token to connect on GitHub organization;
  • $Organization = GitHub Organization name;
  • $Connstr = connection string to Azure SQL Database that stores the report information. To create this report, it’s necessary to create previously a Azure SQL Server and Database and run a script below:
$UriOrganization = "https://api.github.com/orgs/$($organization)"$OrganizationResult = Invoke-RestMethod -Headers $headers -Uri $UriOrganizationWrite-Host $OrganizationResult.id
$uriOrganizationSecrets = "$($UriOrganization)/actions/secrets"$OrganizationSecretsResult = Invoke-RestMethod -Headers $headers -Uri $uriOrganizationSecretsforeach ($orgSecret in $OrganizationSecretsResult.secrets)
{
Write-Host $orgSecret.name
}
$uriRepositories = "$($UriOrganization)/repos"$RepositoriesResult = Invoke-RestMethod -Headers $headers -Uri $uriRepositoriesforeach ($repo in $RepositoriesResult)
{
Write-Host $repo.name
}
$uriRepositoriesSecrets = "$($UriRepositoriesOwner)/$($repo.name)/actions/secrets"    $RepositoriesSecretsResult = Invoke-RestMethod -Headers $headers -Uri $uriRepositoriesSecrets    foreach ($repoSecret in $RepositoriesSecretsResult.secrets)    
{
Write-Host $repoSecret.name
}
$uriRepositoriesEnvironments = "$($UriRepositoriesOwner)/$($repo.name)/environments"    $RepositoriesEnvironmentsResult = Invoke-RestMethod -Headers $headers -Uri $uriRepositoriesEnvironments    foreach ($repoenvironment in $RepositoriesEnvironmentsResult.environments)    
{
Write-Host $repoenvironment.name
}
$uriRepositoriesEnvironmentsSecrets = "https://api.github.com/repositories/$($repo.id)/environments/$($repoenvironment.name)/secrets"        $RepositoriesEnvironmentsSecrets = Invoke-RestMethod -Headers $headers -Uri $uriRepositoriesEnvironmentsSecrets        foreach ($repoenvironmentsecret in $RepositoriesEnvironmentsSecrets.secrets)
{
Write-Host $repoenvironmentsecret.name
}
  • Repositories (1) = Filter report using Repositories field;
  • Environments (2) = Filter report using Environments field;
  • Secrets Name (3) = Filter report using Secret name field;
  • Organization Secrets (4) = list all organization secrets;
  • Repositories Secrets (5) = List all information about repositories and secrets. If the respective secret is mapped on a repository, the same will be marked (green ticks on a grid);
  • Repositories Environments Secrets (5) = List all information about repositories, environments and secrets. If the respective secret is mapped on a repository and environment, the same will be marked (green ticks on a grid).

--

--

--

Tech Solution Architect Manager na Accenture

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Psychology of Testing in Software testing.

An Introduction to Smart Contracts

Faster Android development with data binding

What I’ve learned from joining a hackathon with only 1.5 months of coding experience

ELI5: Data Structures Basics

6 Things You’re Doing Wrong with Your REST API

Thinking RPA for Your Enterprise? Ask These Questions First

H3: First half of the 12-factor app

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinicius Moura

Vinicius Moura

Tech Solution Architect Manager na Accenture

More from Medium

Mirroring Git Repositories

DOCKER — CMD vs ENTRYPOINT

How to: Create Dashboard to visualize Branches ahead/behind on GitHub

Create a YAML Manifest Template in Monokle