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 / auth.go
Created May 17, 2019 13:58
NewAuthorizerFromEnvironment() method def from github.com/Azure/go-autorest/autorest/azure/auth package
// NewAuthorizerFromEnvironment creates an Authorizer configured from environment variables in the order:
// 1. Client credentials
// 2. Client certificate
// 3. Username password
// 4. MSI
func NewAuthorizerFromEnvironment() (autorest.Authorizer, error) {
settings, err := getAuthenticationSettings()
if err != nil {
return nil, err
}
@DexterPOSH
DexterPOSH / SetPSDefaultParametersValue.ps1
Created May 7, 2019 14:05
SetPSDefaultParametersValue for Search-AzGraph cmdlet
$subscriptions = Get-AzSubscription
$PSDefaultParameterValues=@{"Search-AzGraph:Subscription"= $subscriptions.ID }
@DexterPOSH
DexterPOSH / GetMethods() SearchAzureRmGraph.cs
Created May 7, 2019 13:58
Method definition from SearchAzureRmGraph.cs
// Snipped code
private IEnumerable<string> GetSubscriptions()
{
if (this.Subscription != null)
{
return this.Subscription;
}
var accountSubscriptions = this.DefaultContext.Account.GetSubscriptions();
if (accountSubscriptions.Length > 0)
@DexterPOSH
DexterPOSH / File.go
Last active January 11, 2019 07:07
Auth file struct for Azure GoLang SDK
// File represents the authentication file
type file struct {
ClientID string `json:"clientId,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
SubscriptionID string `json:"subscriptionId,omitempty"`
TenantID string `json:"tenantId,omitempty"`
ActiveDirectoryEndpoint string `json:"activeDirectoryEndpointUrl,omitempty"`
ResourceManagerEndpoint string `json:"resourceManagerEndpointUrl,omitempty"`
GraphResourceID string `json:"activeDirectoryGraphResourceId,omitempty"`
SQLManagementEndpoint string `json:"sqlManagementEndpointUrl,omitempty"`
@DexterPOSH
DexterPOSH / NewAuthorizerFromFile.go
Created January 11, 2019 06:53
Snippet of the NewAuthorizerFromFile function from the Azure GoLang SDK
// NewAuthorizerFromFile creates an Authorizer configured from a configuration file.
func NewAuthorizerFromFile(baseURI string) (autorest.Authorizer, error) {
fileLocation := os.Getenv("AZURE_AUTH_LOCATION")
if fileLocation == "" {
return nil, errors.New("auth file not found. Environment variable AZURE_AUTH_LOCATION is not set")
}
contents, err := ioutil.ReadFile(fileLocation)
if err != nil {
return nil, err
@DexterPOSH
DexterPOSH / testAzVMQuota.ps1
Last active September 21, 2018 16:23
test for a VMSKU deployment does not exceed VM SKU Family & Region Quota
Describe "VM Sku Quota validation. Region - $Location" -Tag "Azure","Cloud", "Quota" {
#TODO - wrap these as helper functions
# Credit - Irwin for refactoring the logic below.
$vmSKU = Get-AzureRmComputeResourceSku | Where-Object -FilterScript {
$PSItem.Locations.Contains($Location) -and
$PSitem.ResourceType -eq 'VirtualMachines' -and
$PSitem.Name -eq $VMSkuName
}
@DexterPOSH
DexterPOSH / GetMember.py
Last active February 6, 2018 05:30
Basic & crude GetMember function, it helps me in exploring objects in Python REPL.
import inspect
def GetMember(object, width=100):
print("TypeName: {}\n".format(repr(object)))
print("{0:<40} {1:<60} {2:<100}".format('Name', 'MemberType', 'Signature'))
print("{0:<40} {1:<60} {2:<100}".format('----', '----------', '---------'))
members = inspect.getmembers(object)
for member in members:
name = str(member[0])
membertype = type(member[1])
@DexterPOSH
DexterPOSH / FormatList.py
Created February 6, 2018 05:28
Basic FormatList function, it helps me seeing the attributes on a Python object.
def FormatList(object, width=100):
keys = [i for i in dir(object) if ( not str(i).startswith('__'))]
if keys:
for key in keys:
print("{0:<40} : {1:<80}".format(key, (str(getattr(object, key)))[:width]))
@DexterPOSH
DexterPOSH / README.md
Created December 19, 2017 06:25 — forked from trinitronx/README.md
A shell script to install latest Ansible via pip + dependencies

omnibus-ansible

Install latest Ansible via pip + dependencies via a shell script

This file is used to install ansible in test kitchen when you set in the kitchen.yaml file

require_ansible_omnibus: true

By default test kitchen will always download and use the latest version of this install file.

WARNING: AS SOON AS YOU MERGE CODE HERE IT IS INSTANTLY AVAILABLE TO EVERYONE DOING OMNIBUS KITCHEN ANSIBLE INSTALLS:

@DexterPOSH
DexterPOSH / WindowsCredentialVault.psm1
Created November 12, 2017 11:03 — forked from guitarrapc/WindowsCredentialVault.psm1
PowerShell Windows Credential Vault Module
function InitializeWindowsCredential
{
Write-Verbose ("Loading PasswordVault Class.")
[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
}
InitializeWindowsCredential
function ConvertTo-PasswordCredential
{