Skip to content

Instantly share code, notes, and snippets.

@chowdhary987
Forked from hiroyuki-sato/basic_auth.md
Created January 30, 2019 12:10
Show Gist options
  • Save chowdhary987/dae4e6910a2791a8c09553fd13d553ed to your computer and use it in GitHub Desktop.
Save chowdhary987/dae4e6910a2791a8c09553fd13d553ed to your computer and use it in GitHub Desktop.
digdag basic auth
daemon off;
#error_log /dev/stdout debug;
error_log /dev/stdout info;
events {

}
http {
        access_log /dev/stdout;
	server {
	    listen 8080;
	    server_name    example.com;

	    proxy_set_header    Host    $host;
	    proxy_set_header    X-Real-IP    $remote_addr;
	    proxy_set_header    X-Forwarded-Host       $host;
	    proxy_set_header    X-Forwarded-Server    $host;
	    proxy_set_header    X-Forwarded-For    $proxy_add_x_forwarded_for;

	    location / {
                auth_basic "Restricted";
                auth_basic_user_file "/tmp/htpasswd";
		proxy_pass    http://localhost:65432/;
	    }

	}
}
diff --git a/digdag-client/src/main/java/io/digdag/client/DigdagClient.java b/digdag-client/src/main/java/io/digdag/client/DigdagClient.java
index 771a5f62f1..a39b9fd29c 100644
--- a/digdag-client/src/main/java/io/digdag/client/DigdagClient.java
+++ b/digdag-client/src/main/java/io/digdag/client/DigdagClient.java
@@ -44,6 +44,7 @@ import io.digdag.client.api.SecretValidation;
 import io.digdag.client.api.SessionTimeTruncate;
 import io.digdag.client.config.Config;
 import io.digdag.client.config.ConfigFactory;
+import org.jboss.resteasy.client.jaxrs.BasicAuthentication;
 import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;

 import javax.ws.rs.NotFoundException;
@@ -891,7 +892,8 @@ public class DigdagClient implements AutoCloseable

     private <T> T doGet(Class<T> type, WebTarget target)
     {
-        return invokeWithRetry(target.request("application/json")
+        System.out.println("doGet");
+        return invokeWithRetry(target.register(new BasicAuthentication("foo","bar")).request("application/json")
             .headers(headers.get())
             .buildGet()).readEntity(type);
     }
digdag-0.9.28-SNAPSHOT.jar  push -e 'http://localhost:8080' foo -l debug
2018-09-10 13:55:54 +0900: Digdag v0.9.27
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider: Using manager EnhancedLocalRepositoryManager with priority 10.0 for .digdag/plugins
2018-09-10 13:55:55 +0900 [DEBUG] (main) io.digdag.core.database.DataSourceProvider: Using database URL jdbc:h2:mem:digdag-6fc7acc6-3722-46f6-afc9-d831e109f1db
Creating .digdag/tmp/archive-5948940699358947984.tar.gz...
  Archiving foo.dig
  Archiving scripts/myscript.sh
Workflows:
  foo.dig
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider: Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/hsato/.config/digdag/plugins
2018-09-10 13:55:55 +0900 [DEBUG] (main) io.digdag.cli.client.ClientCommand: Using endpoint http://localhost:8080
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.logging.LoggerProviders: Logging Provider: org.jboss.logging.Slf4jLoggerProvider
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: Provider : org.jboss.resteasy.plugins.providers.DocumentProvider,  Method : DocumentProvider
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: RESTEASY002330: Unable to retrieve config: expandEntityReferences defaults to false
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: RESTEASY002335: Unable to retrieve config: enableSecureProcessingFeature defaults to true
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: RESTEASY002325: Unable to retrieve config: disableDTDs defaults to true
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: Provider : org.jboss.resteasy.plugins.providers.DocumentProvider,  Method : DocumentProvider
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: RESTEASY002330: Unable to retrieve config: expandEntityReferences defaults to false
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: RESTEASY002335: Unable to retrieve config: enableSecureProcessingFeature defaults to true
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.jboss.resteasy.plugins.providers.DocumentProvider: RESTEASY002325: Unable to retrieve config: disableDTDs defaults to true
doGet
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.client.protocol.RequestAddCookies: CookieSpec selected: default
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.client.protocol.RequestAuthCache: Auth cache not set in the context
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.conn.BasicHttpClientConnectionManager: Get connection for route {}->http://localhost:8080
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.execchain.MainClientExec: Opening connection {}->http://localhost:8080
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.conn.DefaultHttpClientConnectionOperator: Connecting to localhost/127.0.0.1:8080
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.conn.DefaultHttpClientConnectionOperator: Connection established 127.0.0.1:54917<->127.0.0.1:8080
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.execchain.MainClientExec: Executing request GET /api/version/check?client=0.9.27 HTTP/1.1
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.execchain.MainClientExec: Proxy auth state: UNCHALLENGED
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.execchain.MainClientExec: Connection can be kept alive indefinitely
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.auth.HttpAuthenticator: Authentication required
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.auth.HttpAuthenticator: localhost:8080 requested authentication
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.auth.HttpAuthenticator: Response contains no authentication challenges
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.conn.BasicHttpClientConnectionManager: Releasing connection 127.0.0.1:54917<->127.0.0.1:8080
2018-09-10 13:55:55 +0900 [DEBUG] (main) org.apache.http.impl.conn.BasicHttpClientConnectionManager: Connection can be kept alive indefinitely
error: Status code 401: HTTP 401 Unauthorized
hsato-mbp13:foo hsato$ s
foo.dig	scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment