Skip to content

Instantly share code, notes, and snippets.

View amalgjose's full-sized avatar
🎯
Focusing

Amal G Jose amalgjose

🎯
Focusing
View GitHub Profile
from lxml import etree
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, DateTime
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
# Database connection details
DATABASE_URI = 'postgresql+psycopg2://username:password@localhost:5432/dbname'
# Initialize SQLAlchemy engine and session
@amalgjose
amalgjose / download_from_s3_to_dbfs.py
Created September 11, 2024 20:59
Python program to download files from S3 to DBFS in Databricks
import os
import boto3
aws_access_key = ""
aws_secret_key = ""
bucket_name = ""
region_name = ""
# Path of the files in S3 bucket
prefix_path = ""
# Path to be written in DBFS
@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)