[ 
https://issues.apache.org/jira/browse/MBUILDCACHE-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17682140#comment-17682140
 ] 

ASF GitHub Bot commented on MBUILDCACHE-33:
-------------------------------------------

gnodet commented on code in PR #35:
URL: 
https://github.com/apache/maven-build-cache-extension/pull/35#discussion_r1090762647


##########
src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java:
##########
@@ -81,11 +90,58 @@ public RemoteCacheRepositoryImpl(
             RepositorySystemSession session = 
mavenSession.getRepositorySession();
             RemoteRepository repo = new RemoteRepository.Builder(
                     cacheConfig.getId(), "cache", cacheConfig.getUrl() 
).build();
-            RemoteRepository mirror = session.getMirrorSelector().getMirror( 
repo );
-            RemoteRepository repoOrMirror = mirror != null ? mirror : repo;
-            Proxy proxy = session.getProxySelector().getProxy( repoOrMirror );
-            Authentication auth = 
session.getAuthenticationSelector().getAuthentication( repoOrMirror );
-            RemoteRepository repository = new RemoteRepository.Builder( 
repoOrMirror )
+            Map<String, String> env = System.getenv();
+
+            // if direct connectivity isn't forced, resolving through maven 
settings
+            if ( !env.containsKey( MAVEN_BUILD_CACHE_DIRECT_CONNECT ) )
+            {
+                RemoteRepository mirror = 
session.getMirrorSelector().getMirror( repo );
+                if ( mirror != null )
+                {
+                    repo = mirror;
+                }
+            }
+
+            // if proxy is set by environment, use it
+            Proxy proxy;
+            if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_URL ) )
+            {
+                String proxyUrl = env.get( MAVEN_BUILD_CACHE_PROXY_URL );
+                LOGGER.debug( "Remote build cache proxy url overridden by 
environment to {}", proxyUrl );
+                URI uri = URI.create( proxyUrl );
+                if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_USER ) )

Review Comment:
   `&& env.containsKey( MAVEN_BUILD_CACHE_PASSWORD )` ?  Or cleanly fail if 
it's missing maybe.



##########
src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java:
##########
@@ -81,11 +90,58 @@ public RemoteCacheRepositoryImpl(
             RepositorySystemSession session = 
mavenSession.getRepositorySession();
             RemoteRepository repo = new RemoteRepository.Builder(
                     cacheConfig.getId(), "cache", cacheConfig.getUrl() 
).build();
-            RemoteRepository mirror = session.getMirrorSelector().getMirror( 
repo );
-            RemoteRepository repoOrMirror = mirror != null ? mirror : repo;
-            Proxy proxy = session.getProxySelector().getProxy( repoOrMirror );
-            Authentication auth = 
session.getAuthenticationSelector().getAuthentication( repoOrMirror );
-            RemoteRepository repository = new RemoteRepository.Builder( 
repoOrMirror )
+            Map<String, String> env = System.getenv();
+
+            // if direct connectivity isn't forced, resolving through maven 
settings
+            if ( !env.containsKey( MAVEN_BUILD_CACHE_DIRECT_CONNECT ) )
+            {
+                RemoteRepository mirror = 
session.getMirrorSelector().getMirror( repo );
+                if ( mirror != null )
+                {
+                    repo = mirror;
+                }
+            }
+
+            // if proxy is set by environment, use it
+            Proxy proxy;
+            if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_URL ) )
+            {
+                String proxyUrl = env.get( MAVEN_BUILD_CACHE_PROXY_URL );
+                LOGGER.debug( "Remote build cache proxy url overridden by 
environment to {}", proxyUrl );
+                URI uri = URI.create( proxyUrl );
+                if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_USER ) )
+                {
+                    LOGGER.debug( "Remote build cache proxy credentials 
overridden by environment" );
+                    Authentication proxyAuthentication = new 
AuthenticationBuilder()
+                            .addUsername( env.get( 
MAVEN_BUILD_CACHE_PROXY_USER ) )
+                            .addPassword( env.get( 
MAVEN_BUILD_CACHE_PROXY_PASSWORD ) )
+                            .build();
+                    proxy = new Proxy( uri.getScheme(), uri.getHost(), 
uri.getPort(), proxyAuthentication );
+                }
+                else
+                {
+                    proxy = new Proxy( uri.getScheme(), uri.getHost(), 
uri.getPort() );
+                }
+            }
+            else
+            {
+                proxy = session.getProxySelector().getProxy( repo );
+            }
+
+            Authentication auth;
+            if ( env.containsKey( MAVEN_BUILD_CACHE_USER ) )

Review Comment:
   `&& env.containsKey( MAVEN_BUILD_CACHE_PASSWORD )` ?  Or cleanly fail if 
it's missing maybe.





> Support remote cache credentials from environment variables 
> ------------------------------------------------------------
>
>                 Key: MBUILDCACHE-33
>                 URL: https://issues.apache.org/jira/browse/MBUILDCACHE-33
>             Project: Maven Build Cache Extension
>          Issue Type: New Feature
>            Reporter: Alexander Ashitkin
>            Priority: Major
>              Labels: pull-request-available
>
> In my current environment settings.xml are managed by a build team which is 
> not allowing any modification because the same build service is used by all 
> teams. Atop of that, maven build runs in a fresh container which doesn't have 
> any credentials injected for security reasons. Because of that cache cannot 
> read/deploy build artifacts to an authenticated http server. Still, our build 
> service allows to inject credentials from environment variables into build 
> container. Need to support cache setup without settings.xml by injecting 
> environment variables:
>  * MAVEN_BUILD_CACHE_DIRECT_CONNECT
>  * MAVEN_BUILD_CACHE_USER
>  * MAVEN_BUILD_CACHE_PASSWORD
>  * MAVEN_BUILD_CACHE_PROXY_USER
>  * MAVEN_BUILD_CACHE_PROXY_PASSWORD



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to