Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / app.js
Created October 11, 2017 16:57
NodeJS app to access Google Cloud Identity Aware Proxy
const request = require('request');
const log4js = require("log4js");
const jwt = require('jsonwebtoken');
const logger = log4js.getLogger();
const secure_IAAP_URL = 'https://YOUR_PROTECTED_PAGE';
const iap_clientID = 'client_id_for_iaap.apps.googleusercontent.com';
@salrashid123
salrashid123 / ApacheTransport.java
Created October 16, 2017 13:26
proxy-ApacheTransport
JacksonFactory jsonFactory = new JacksonFactory();
HttpHost proxy = new HttpHost("127.0.0.1",3128);
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
httpClient.addRequestInterceptor(new HttpRequestInterceptor(){
@Override
public void process(org.apache.http.HttpRequest request, HttpContext context) throws HttpException, IOException {
if (request.getRequestLine().getMethod().equals("CONNECT"))
@salrashid123
salrashid123 / proxy-googleapis.java
Created October 16, 2017 13:29
Proxy-GoogleAPIs
com.google.api.client.googleapis.auth.oauth2.GoogleCredential credential = com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(mHttpTransport,jsonFactory);
if (credential.createScopedRequired())
credential = credential.createScoped(Arrays.asList(StorageScopes.DEVSTORAGE_READ_ONLY));
com.google.api.services.storage.Storage service = new com.google.api.services.storage.Storage.Builder(mHttpTransport, jsonFactory, credential)
.setApplicationName("oauth client")
.build();
@salrashid123
salrashid123 / ProxyGoogleCloud.java
Created October 16, 2017 13:30
Proxy-GoogleCloud
HttpTransportFactory hf = new HttpTransportFactory(){
@Override
public HttpTransport create() {
return mHttpTransport;
}
};
com.google.auth.oauth2.GoogleCredentials credential = com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(hf);
if (credential.createScopedRequired())
credential = credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/devstorage.read_write"));
TransportOptions options = HttpTransportOptions.newBuilder().setHttpTransportFactory(hf).build();
@salrashid123
salrashid123 / Proxy-GoGoogleCLoud.go
Created October 16, 2017 13:31
Proxy-GoGoogleCLoud.go
import (
"log"
"cloud.google.com/go/storage"
"cloud.google.com/go/pubsub"
"golang.org/x/net/context"
"google.golang.org/api/iterator"
)
const (
projectID = "your_project"
)
@salrashid123
salrashid123 / Proxy-GoogleCloudCS.cs
Created October 16, 2017 13:32
Proxy-GoogleCloudCS.cs
string CREDENTIAL_FILE_PKCS12 = "/path/to/your/service0-account.p12";
string serviceAccountEmail = "[email protected]";
var certificate = new X509Certificate2(CREDENTIAL_FILE_PKCS12, "notasecret",X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
//Scopes = new[] { StorageService.Scope.DevstorageReadOnly, PublisherClient.DefaultScopes },
Scopes = PublisherClient.DefaultScopes.Append(StorageService.Scope.DevstorageReadOnly),
HttpClientFactory = new ProxySupportedHttpClientFactory()
}.FromCertificate(certificate));
@salrashid123
salrashid123 / Proxy-NodeGoogleCloud.js
Created October 16, 2017 13:33
Proxy-NodeGoogleCloud.js
var log4js = require("log4js");
var logger = log4js.getLogger();
const Pubsub = require('@google-cloud/pubsub');
var gcloud = require('google-cloud');
var gcs = gcloud.storage();
gcs.getBuckets(function(err, buckets) {
if (!err) {
buckets.forEach(function(value){
logger.info(value.id);
});
@salrashid123
salrashid123 / Proxy-JavaGoogleCloudAuth.java
Created October 16, 2017 13:33
Proxy-JavaGoogleCloudAuth.java
System.setProperty("https.proxyHost", "localhost");
System.setProperty("https.proxyPort", "3128");
Authenticator.setDefault(
new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"user1", "user1".toCharArray());
}
}
@salrashid123
salrashid123 / main.go
Created January 2, 2018 16:33
Getting a google id token in golang for cloud endpoints and identity proxy
package main
import (
"io/ioutil"
"log"
"net/http"
"net/url"
"strings"
"crypto/rsa"
@salrashid123
salrashid123 / lamp-dm.sh
Created January 9, 2018 14:24
lamp-blog: DM Output
$ gcloud deployment-manager deployments create yy60 --config cluster.yaml
NAME TYPE STATE ERRORS INTENT
yy60-cluster-as compute.v1.regionAutoscaler COMPLETED []
yy60-cluster-beb compute.beta.backendBucket COMPLETED []
yy60-cluster-bes compute.v1.backendService COMPLETED []
yy60-cluster-config runtimeconfig.v1beta1.config COMPLETED []
yy60-cluster-firewall-80 compute.v1.firewall COMPLETED []
yy60-cluster-hc-http compute.v1.httpHealthCheck COMPLETED []
yy60-cluster-igm compute.v1.regionInstanceGroupManager COMPLETED []
yy60-cluster-it compute.v1.instanceTemplate COMPLETED []