Skip to content

Instantly share code, notes, and snippets.

@ryu1kn
ryu1kn / README.md
Last active March 18, 2024 14:19
Getting GCP access token from a service account key JSON file

Getting GCP access token from a service account key

Use your service account's key JSON file to get an access token to call Google APIs.

Good for seeing how things work, including the creation of JWT token.

To create a JWT token, you can replace create-jwt-token.sh script with tools like step.

If you just want to get an access token for a service account,

@ryu1kn
ryu1kn / README.md
Created August 20, 2019 13:56
Google Cloud Deployment Manager sample

Google Cloud Deployment Manager samples

Usage

Creating

Using configuration

gcloud deployment-manager deployments create sample-deployment --config vm_config.yaml
@ryu1kn
ryu1kn / terraform-debug.log
Created August 16, 2019 15:26
Debug log: Terraform google provider failing to apply IAM policy when user email address has uppercase characters
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-provider-google_v2.13.0_x4: 2019/08/17 00:50:53 [DEBUG] Google API Request Details:
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-provider-google_v2.13.0_x4: ---[ REQUEST ]---------------------------------------
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-provider-google_v2.13.0_x4: POST /v1/projects/my-project:getIamPolicy?alt=json&prettyPrint=false HTTP/1.1
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-provider-google_v2.13.0_x4: Host: cloudresourcemanager.googleapis.com
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-provider-google_v2.13.0_x4: User-Agent: google-api-go-client/0.5 Terraform/0.12.6 (+https://www.terraform.io) terraform-provider-google/2.13.0
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-provider-google_v2.13.0_x4: Content-Length: 3
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-provider-google_v2.13.0_x4: Content-Type: application/json
2019-08-17T00:50:53.531+1000 [DEBUG] plugin.terraform-pr
@ryu1kn
ryu1kn / Makefile
Created August 11, 2019 14:51
Access Kubernetes API server with a service account token
# Accessing Kubernetes API server with a service account token
service_account_name := default
tmp_cacert_file := __cacert.pem
check-api:
$(MAKE) get-ca-cert > $(tmp_cacert_file)
bash -c 'curl $(shell $(MAKE) get-cluster-address)/api \
--header "Authorization: Bearer $(shell $(MAKE) get-api-token)" \
--cacert $(tmp_cacert_file)'
@ryu1kn
ryu1kn / Dockerfile
Last active May 15, 2019 08:44
SQL Server Application Intent Read Only with TinyTDS
FROM ruby:2.5
RUN apt-get update -y \
&& apt-get install -y wget build-essential libtool-bin libc6-dev libssl1.0-dev \
&& mkdir -p /opt \
&& cd /opt \
&& wget http://www.freetds.org/files/stable/freetds-1.1.6.tar.gz \
&& tar -xzf freetds-1.1.6.tar.gz \
&& cd freetds-1.1.6 \
&& ./configure --prefix=/usr/local --with-tdsver=7.3 \
@ryu1kn
ryu1kn / Makefile
Last active November 9, 2019 22:37
Encrypt/decrypt a directory using GPG with symmetric key option
# Encrypt/decrypt a directory using GPG with symmetric key option
dir_name := plain-files
encrypted_file := encrypted-dir.blob
tmp_file := tmp.tgz
encrypt-dir:
tar czf $(tmp_file) $(dir_name)
gpg --no-symkey-cache -o $(encrypted_file) -c $(tmp_file)
rm -f $(tmp_file)
@ryu1kn
ryu1kn / Makefile
Last active February 12, 2020 09:22
Manually check if a server cert can be verified with its issuer cert
SHELL := /bin/bash
openssl := /usr/local/opt/openssl@1.1/bin/openssl
work_dir := __work
message_digest_type := sha256
ifneq ($(wildcard __override.mk),)
include __override.mk
endif
@ryu1kn
ryu1kn / JsonSpec.scala
Last active August 3, 2021 13:38
spray-json. Remove empty string before deserialising JSON
import org.scalatest.{Matchers, WordSpec}
import spray.json._
object JsonHelper {
implicit class JsObjectWrap(obj: JsObject) {
def removeEmptyValues: JsObject = JsObject(obj.fields
.map {
case (key, value: JsObject) => (key, value.removeEmptyValues)
@ryu1kn
ryu1kn / mp4-download.sh
Last active January 3, 2018 09:55
mp4 downloader
#!/bin/bash
# Download MP4 files. Run the command with --help option to see more details
COMMAND_NAME=./mp4-download.sh
LOGFILE=download.log
FILENAME=""
ARGV_BASE_INDEX=1
ARGV_DEBUG=NO
ARGV__=()
@ryu1kn
ryu1kn / Makefile
Created November 1, 2017 10:29
Script to merge one repository into another
# Merge SRC_REPO into a DEST_REPO under its subdirectory NEW_DIR
# cf. https://stackoverflow.com/questions/277029/combining-multiple-git-repositories
#
# Place 2 repository and this Makefile as follows:
#
# ./
# DEST_REPO/
# Makefile
#
# Then execute