Skip to content

Instantly share code, notes, and snippets.

View amalgjose's full-sized avatar
🎯
Focusing

Amal G Jose amalgjose

🎯
Focusing
View GitHub Profile
@amalgjose
amalgjose / update_blob_pubic_access.py
Last active January 21, 2024 18:44
Python program to enable or disable the public access of an Azure Storage Account
from azure.identity import ClientSecretCredential
from azure.mgmt.storage import StorageManagementClient
from azure.mgmt.storage.models import StorageAccountUpdateParameters
# Enter the subscription id, resource group name and storage account name
subscription_id = "xxxxxxxx"
resource_group_name="xxxxx"
storage_account_name="xxxx"
# Update the service principle credentials below.
@amalgjose
amalgjose / azure_blob_enable_sftp.py
Last active January 18, 2024 17:35
Python program to programatically enable or disable SFTP in an Azure storage account (Azure Blob Storage)
from azure.mgmt.storage import StorageManagementClient
from azure.identity import ClientSecretCredential
# Update the below variables with the correct values
subscription_id="Your-subscription-id"
resource_group_name = "your-resource-grp-name"
storage_account_name = "your-storage-account-name"
# Update the below variables with the Service Principle credentials.
AZURE_CLIENT_ID = ""
@amalgjose
amalgjose / print_secret_databricks.py
Created January 18, 2024 14:22
Simple code snippet to print REDACTED secret in plain text within a Databricks notebook
value = dbutils.secrets.get(scope="myScope", key="myKey")
for char in value:
print(char, end='\u200B')
@amalgjose
amalgjose / migrate_secrets_multi_sp.py
Last active January 18, 2024 17:43
Python program to migrate keyvault secrets from one keyvault to another keyvault present in a different azure tenant
# pip install azure-keyvault-secrets
# pip install azure-identity
from azure.keyvault.secrets import SecretClient
from azure.identity import ClientSecretCredential
source_vault_url = "https://<sourcekeyvault>.vault.azure.net"
destination_vault_url = "https://<destkeyvault>.vault.azure.net/"
# Get the below details from Service Principle-01 (has access to source keyvault)
@amalgjose
amalgjose / migrate_secrets_same_sp.py
Last active January 18, 2024 17:43
Python program to migrate secrets from one Azure Keyvault to another
# pip install azure-keyvault-secrets
# pip install azure-identity
from azure.keyvault.secrets import SecretClient
from azure.identity import ClientSecretCredential
source_vault_url = "https://<sourcekeyvault>.vault.azure.net"
destination_vault_url = "https://<destkeyvault>.vault.azure.net/"
# Get the below details from Service Principle
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
rules:
# Allow Metrics Scraper to get metrics from the Metrics server
- apiGroups: ["metrics.k8s.io"]
resources: ["pods", "nodes"]
@amalgjose
amalgjose / ldap_conn_check.y
Created February 2, 2023 12:29
test code
import ldap
ldap_host = ""
pem_file_loc = ""
ldap_bind_dn = ""
conn = ldap.initialize(ldap_host)
conn.protocol_version = ldap.VERSION3
conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)
conn.set_option(ldap.OPT_X_TLS_CACERTFILE, pem_file_loc)
conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
@amalgjose
amalgjose / create_kafka_topics.py
Created December 29, 2022 20:59
Code snippet to create kafka topics
Topics = ["test1","test2"]
class createTopics:
def __init__(self):
self.a = AdminClient({'bootstrap.servers': 'localhost:9092',
'debug':'broker,admin,protocol',
'compression.type':'none',
'group.id':'mygroup'})
new_topics = [NewTopic(topic, num_partitions=1, replication_factor=1)
for topic in Topics]
self.a.create_topics(new_topics)
@amalgjose
amalgjose / connect_private_rds.py
Created March 22, 2022 06:03 — forked from riddhi89/connect_private_rds.py
Connecting to a private AWS RDS instance in python
from sshtunnel import SSHTunnelForwarder
import pymysql
with SSHTunnelForwarder(
('ec2-52-202-194-76.public-ec2-instance.amazonaws.com'),
ssh_username="ec2-user",
ssh_pkey="~/ssh-tunnel-rds.pem",
remote_bind_address=('private-rds-instance.ckfkidfytpr4.us-east-1.rds.amazonaws.com', 3306)
) as tunnel:
print("****SSH Tunnel Established****")
@amalgjose
amalgjose / euclidean_distance.py
Last active January 26, 2022 16:54
Python program to find the points which is closer to a point P in a two dimensional plane.
import math
n = int(input("Enter the number of points\n"))
line_points = []
for i in range(n):
x, y = input("Enter the coordinate x,y \n").split(',')
coordinates = [int(x), int(y)]
line_points.append(coordinates)
xp, yp = input("Enter the coordinate of center point P \n").split(',')