Skip to content

Instantly share code, notes, and snippets.

View DexterPOSH's full-sized avatar
🌱
Learning && Growing

Deepak Singh Dhami DexterPOSH

🌱
Learning && Growing
View GitHub Profile
@DexterPOSH
DexterPOSH / MyPlatform_crd.yaml
Last active October 16, 2021 05:48
Sample CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
# name must match the spec fields below, and be in the form: <plural>.<group>
name: myplatforms.contoso.com
spec:
# group name to use for REST API: /apis/<group>/<version>
group: contoso.com
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
{
"$id": "1",
"innerException": null,
"message": "No api-version was supplied for the \"POST\" request. The version must be supplied either as part of the Accept header (e.g. \"application/json; api-version=1.0\") or as a query parameter (e.g. \"?api-version=1.0\").",
"typeName": "Microsoft.VisualStudio.Services.WebApi.VssVersionNotSpecifiedException, Microsoft.VisualStudio.Services.WebApi",
"typeKey": "VssVersionNotSpecifiedException",
"errorCode": 0,
"eventId": 3000
}
@DexterPOSH
DexterPOSH / CreateAzDOEnv_Error.ps1
Last active April 13, 2020 11:32
Gist with a catch
$url = 'https://dev.azure.com/ddhami/BITPro.AzDeploy/_apis/distributedtask/environments'
$cred = Get-Credential -UserName 'vsts' -Message 'Enter AzDO Personal Access Token with privs to create env'
$encodedValue = [Convert]::ToBase64String(
[Text.Encoding]::ASCII.GetBytes(
("{0}:{1}" -f '', $cred.GetNetworkCredential().Password)
)
)
$body = @{
name = 'test-pwsh-env';
@DexterPOSH
DexterPOSH / CreateAzDOEnv.ps1
Last active April 13, 2020 11:32
Gist showing Pwsh Code snippet to create environments.
$url = 'https://dev.azure.com/ddhami/BITPro.AzDeploy/_apis/distributedtask/environments'
$cred = Get-Credential -UserName 'vsts' -Message 'Enter AzDO Personal Access Token with privs to create env'
$encodedValue = [Convert]::ToBase64String(
[Text.Encoding]::ASCII.GetBytes(
("{0}:{1}" -f '', $cred.GetNetworkCredential().Password)
)
)
$body = @{
name = 'test-pwsh-env';
@DexterPOSH
DexterPOSH / 1-hello-world.md
Created February 25, 2020 14:11
Test content file generated from Hugo CLI
title date draft
1 Hello World
2020-02-25 19:23:53 +0530
true

Introduction

Customary "Hello World" program.

Friend1

This is friend1.

@DexterPOSH
DexterPOSH / FetchAssignedPr.ps1
Last active October 15, 2019 03:58
Code snippet to fetch PRs where a user is assigned as a reviewer
# fetch all the release pipelines metadata for the project
$ProjectName = 'BitPro.AzDeploy'
# Need the UserEmail as this is the unique name
$UserEmail = 'ddhami@foo.com'
# generate a list of User & Groups names to search for in the PR
$IDs = New-Object -TypeName System.Collections.ArrayList
$UserObject = az devops user show --user $UserEmail | ConvertFrom-Json
$IDs.Add($UserObject.Id)
@DexterPOSH
DexterPOSH / azDevopsReleaseTaskAudit.ps1
Last active December 12, 2023 20:21
This PowerShell script lists out how to use Az CLI's DevOps extension to walk through the release definitions in a project and check for a specific taskId.
# Set the PAT as an Environment variable, put this in your profile.
# I only use the CLI for read operations so make sure you grant the PAT only that access
$env:AZURE_DEVOPS_EXT_PAT = "<Insert PAT Token here>"
# configure the defaults for the Az DevOps extension for Az CLI to use
az devops configure --defaults organization=https://dev.azure.com/dexterposh project=Test.Project
# see the configured defaults
az devops configure --list
@DexterPOSH
DexterPOSH / auth.go
Created May 18, 2019 05:44
getAuthorizer() method for settings struct
func (settings settings) getAuthorizer() (autorest.Authorizer, error) {
//1.Client Credentials
if settings.clientSecret != "" {
config := NewClientCredentialsConfig(settings.clientID, settings.clientSecret, settings.tenantID)
config.AADEndpoint = settings.environment.ActiveDirectoryEndpoint
config.Resource = settings.resource
return config.Authorizer()
}
//2. Client Certificate
@DexterPOSH
DexterPOSH / auth.go
Created May 18, 2019 05:36
getAuthenticationSettings() method def
func getAuthenticationSettings() (s settings, err error) {
s = settings{
tenantID: os.Getenv("AZURE_TENANT_ID"),
clientID: os.Getenv("AZURE_CLIENT_ID"),
clientSecret: os.Getenv("AZURE_CLIENT_SECRET"),
certificatePath: os.Getenv("AZURE_CERTIFICATE_PATH"),
certificatePassword: os.Getenv("AZURE_CERTIFICATE_PASSWORD"),
username: os.Getenv("AZURE_USERNAME"),
password: os.Getenv("AZURE_PASSWORD"),