-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
217 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
# Example usage of the function | ||
# aws_authenticate "/path/to/your/aws_creds.json" | ||
# | ||
# Example AWS credentials JSON file: | ||
# | ||
# { | ||
# "AccessKeyId": "your-access-key-id", | ||
# "SecretAccessKey": "your-secret-access-key", | ||
# "Region": "your-aws-region" | ||
# } | ||
|
||
# Function to authenticate AWS using IAM user credentials | ||
aws_authenticate() { | ||
local creds_json="$1" | ||
|
||
# Read the contents of the file | ||
local creds_content | ||
creds_content=$(cat "$creds_json") | ||
|
||
if [[ -z "$creds_content" ]]; then | ||
echo "[ERROR] No AWS credentials provided." >&2 | ||
return 1 | ||
fi | ||
|
||
# Extract necessary fields from the JSON credentials | ||
local accessKeyId secretAccessKey region | ||
|
||
accessKeyId=$(echo "$creds_content" | jq -r '.AccessKeyId') | ||
secretAccessKey=$(echo "$creds_content" | jq -r '.SecretAccessKey') | ||
region=$(echo "$creds_content" | jq -r '.Region') | ||
|
||
if [[ -z "$accessKeyId" || -z "$secretAccessKey" || -z "$region" ]]; then | ||
echo "[ERROR] Missing required AWS credentials." >&2 | ||
return 1 | ||
fi | ||
|
||
# Set AWS credentials as environment variables | ||
export AWS_ACCESS_KEY_ID="$accessKeyId" | ||
export AWS_SECRET_ACCESS_KEY="$secretAccessKey" | ||
export AWS_DEFAULT_REGION="$region" | ||
|
||
# Test authentication by listing S3 buckets or another simple AWS service operation | ||
echo "[INFO] Testing AWS authentication..." | ||
if ! aws sts get-caller-identity >/dev/null 2>&1; then | ||
echo "[ERROR] AWS authentication failed." >&2 | ||
return 1 | ||
fi | ||
|
||
echo "[INFO] AWS authenticated successfully." | ||
} | ||
|
||
# Example usage of the function | ||
# aws_authenticate "/path/to/your/aws_creds.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
# Function to authenticate Bitwarden using API key or master password | ||
# | ||
# Example usage of the function | ||
# bitwarden_authenticate "/path/to/your/bitwarden_creds.json" | ||
# | ||
# Example Bitwarden credentials JSON file: | ||
# | ||
# { | ||
# "clientId": "your-client-id", | ||
# "clientSecret": "your-client-secret", | ||
# "masterPassword": "your-master-password" | ||
# } | ||
# | ||
|
||
# Function to authenticate Bitwarden using API key or master password | ||
bitwarden_authenticate() { | ||
local creds_json="$1" | ||
|
||
# Read the contents of the file | ||
local creds_content | ||
creds_content=$(cat "$creds_json") | ||
|
||
if [[ -z "$creds_content" ]]; then | ||
echo "[ERROR] No Bitwarden credentials provided." >&2 | ||
return 1 | ||
fi | ||
|
||
# Extract necessary fields from the JSON credentials | ||
local clientId clientSecret masterPassword | ||
|
||
clientId=$(echo "$creds_content" | jq -r '.clientId') | ||
clientSecret=$(echo "$creds_content" | jq -r '.clientSecret') | ||
masterPassword=$(echo "$creds_content" | jq -r '.masterPassword') | ||
|
||
if [[ -z "$clientId" || -z "$clientSecret" || -z "$masterPassword" ]]; then | ||
echo "[ERROR] Missing required Bitwarden credentials." >&2 | ||
return 1 | ||
fi | ||
|
||
# Log in to Bitwarden CLI using API key | ||
echo "[INFO] Authenticating Bitwarden using client ID and secret..." | ||
if ! bw login --apikey --client-id "$clientId" --client-secret "$clientSecret" >/dev/null 2>&1; then | ||
echo "[ERROR] Bitwarden login failed." >&2 | ||
return 1 | ||
fi | ||
|
||
# Unlock the vault using the master password | ||
echo "[INFO] Unlocking the Bitwarden vault..." | ||
if ! bw unlock "$masterPassword" --raw >/dev/null 2>&1; then | ||
echo "[ERROR] Failed to unlock the Bitwarden vault." >&2 | ||
return 1 | ||
fi | ||
|
||
echo "[INFO] Bitwarden authenticated and vault unlocked successfully." | ||
} | ||
|
||
# Example usage of the function | ||
# bitwarden_authenticate "/path/to/your/bitwarden_creds.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
# Function to authenticate GCP service accounts | ||
# | ||
# Example usage of the function | ||
# gcp_authenticate "/path/to/your/gcp_creds.json" | ||
# | ||
# Example GCP credentials JSON file: | ||
# | ||
# { | ||
# "type": "service_account", | ||
# "project_id": "your-project-id", | ||
# "private_key_id": "your-private-key-id", | ||
# "private_key": "your-private-key", | ||
# "client_email": "your-client-email", | ||
# "client_id": "your-client-id", | ||
# "auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
# "token_uri": "https://oauth2.googleapis.com/token", | ||
# "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
# "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-client-email" | ||
# } | ||
# | ||
|
||
# Function to authenticate GCP service accounts | ||
gcp_authenticate() { | ||
local creds_json="$1" | ||
|
||
# Read the contents of the file | ||
local creds_content | ||
creds_content=$(cat "$creds_json") | ||
|
||
if [[ -z "$creds_content" ]]; then | ||
echo "[ERROR] No GCP credentials provided." >&2 | ||
return 1 | ||
fi | ||
|
||
# Extract necessary fields from the JSON credentials | ||
local clientEmail privateKey projectId | ||
|
||
clientEmail=$(echo "$creds_content" | jq -r '.client_email') | ||
privateKey=$(echo "$creds_content" | jq -r '.private_key') | ||
projectId=$(echo "$creds_content" | jq -r '.project_id') | ||
|
||
if [[ -z "$clientEmail" || -z "$privateKey" || -z "$projectId" ]]; then | ||
echo "[ERROR] Missing required GCP credentials." >&2 | ||
return 1 | ||
fi | ||
|
||
# Create a temporary credentials file for gcloud authentication | ||
local temp_creds_file="/tmp/gcp_creds.json" | ||
echo "$creds_content" > "$temp_creds_file" | ||
|
||
echo "[INFO] Authenticating GCP service account..." | ||
if ! gcloud auth activate-service-account "$clientEmail" --key-file="$temp_creds_file" >/dev/null 2>&1; then | ||
echo "[ERROR] GCP service account authentication failed." >&2 | ||
rm -f "$temp_creds_file" | ||
return 1 | ||
fi | ||
|
||
if ! gcloud config set project "$projectId" >/dev/null 2>&1; then | ||
echo "[ERROR] Failed to set GCP project." >&2 | ||
rm -f "$temp_creds_file" | ||
return 1 | ||
fi | ||
|
||
echo "[INFO] GCP service account authenticated and project set." | ||
|
||
# Clean up temporary credentials file | ||
rm -f "$temp_creds_file" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters