Skip to content

Instantly share code, notes, and snippets.

View GarupanOjisan's full-sized avatar

GarupanOjisan GarupanOjisan

View GitHub Profile
@GarupanOjisan
GarupanOjisan / verify_jwt.go
Created January 12, 2020 20:20
verifying jwt
func verifyJWT(publicKeyPath string, token string) (bool, error) {
t, err := jwt.Parse(token, func(token *jwt.Token) (i interface{}, err error) {
if token.Method != (jwt.SigningMethodRS256) {
return nil, fmt.Errorf("invalid signing method")
}
verifyBytes, err := ioutil.ReadFile(publicKeyPath)
if err != nil {
return nil, err
}
return jwt.ParseRSAPublicKeyFromPEM(verifyBytes)
@GarupanOjisan
GarupanOjisan / jwt_signing.go
Created January 12, 2020 20:19
signing jwt
func createJWT(privateKeyPath string, algorithm string, expiration time.Duration) (string, error) {
claims := jwt.StandardClaims{
Audience: "example",
ExpiresAt: time.Now().Add(expiration).Unix(),
IssuedAt: time.Now().Unix(),
}
keyBytes, err := ioutil.ReadFile(privateKeyPath)
if err != nil {
return "", err
@GarupanOjisan
GarupanOjisan / gist:9b067c39bedab0e53c97087abc382f2a
Created January 2, 2020 12:58
grpcurl test for grpc-example project on GKE
grpcurl -plaintext -proto=./proto/user.proto -d '{"id": 1}' <SERVICE EXTERNAL IP>:80 user.UserService/Get
@GarupanOjisan
GarupanOjisan / k_apply.sh
Created January 2, 2020 12:55
kubectl apply for grpc-example project
kubectl apply -f ./kubernetes
@GarupanOjisan
GarupanOjisan / deployment.yaml
Created January 2, 2020 12:54
k8s deployment for grpc-example
apiVersion: apps/v1
kind: Deployment
metadata:
name: grpc-example
spec:
replicas: 1
template:
metadata:
labels:
app: grpc-example
@GarupanOjisan
GarupanOjisan / service.yaml
Created January 2, 2020 12:52
k8s service file for grpc-example project
apiVersion: v1
kind: Service
metadata:
name: grpc-example
spec:
ports:
- port: 80
targetPort: 9000
protocol: TCP
name: http2
@GarupanOjisan
GarupanOjisan / build_and_push_gcr.sh
Created January 2, 2020 12:51
building an image for grpc-example project to GCR
docker build -t grpc-example:v0.0.1 -f ./docker/Dockerfile .
docker tag grpc-example:v0.0.1 asia.gcr.io/<YOUR PROJECT_ID>/grpc-example:v0.0.1
docker push asia.gcr.io/<YOUR PROJECT_ID>/grpc-example:v0.0.1
@GarupanOjisan
GarupanOjisan / deploy_cloudendponts_grpc-example.sh
Created January 2, 2020 12:45
deploy a service to cloud endpoints
gcloud endpoints services deploy ./api_config.yaml ./proto/user.pb
@GarupanOjisan
GarupanOjisan / api_config.yaml
Created January 2, 2020 12:43
api_config.yaml for grpc-example
type: google.api.Service
config_version: 3
name: user.endpoints.<YOUR PROJECT_ID>.cloud.goog
apis:
- name: user.UserService
usage:
rules:
@GarupanOjisan
GarupanOjisan / create_user.pb.sh
Created January 2, 2020 12:40
creating self-describing message
protoc --go_out=plugins=grpc:. ./proto/user.proto --descriptor_set_out=./proto/user.pb