You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/11/03 03:01:31 UTC

[GitHub] [maven-build-cache-extension] AlexanderAshitkin opened a new pull request, #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

AlexanderAshitkin opened a new pull request, #35:
URL: https://github.com/apache/maven-build-cache-extension/pull/35

   Introduces set of environment variables to provide remote cache settings from environment variables. 
   The feature is to support cases when developers do not have access to settings xml and lack access to build infrastructure (managed build containers)
   
    - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MNG) filed 
          for the change (usually before you start working on it).  Trivial changes like typos do not 
          require a JIRA issue.  Your pull request should address just this issue, without 
          pulling in other changes.
    - [ ] Each commit in the pull request should have a meaningful subject line and body.
    - [ ] Format the pull request title like `[MNG-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `MNG-XXX` with the appropriate JIRA issue. Best practice
          is to use the JIRA issue title in the pull request title and in the first line of the 
          commit message.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [ ] You have run the [Core IT][core-its] successfully.
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under 
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   [core-its]: https://maven.apache.org/core-its/core-it-suite/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] AlexanderAshitkin closed pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by "AlexanderAshitkin (via GitHub)" <gi...@apache.org>.
AlexanderAshitkin closed pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars
URL: https://github.com/apache/maven-build-cache-extension/pull/35


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] gnodet commented on a diff in pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] AlexanderAshitkin commented on pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by "AlexanderAshitkin (via GitHub)" <gi...@apache.org>.
AlexanderAshitkin commented on PR #35:
URL: https://github.com/apache/maven-build-cache-extension/pull/35#issuecomment-1419159403

   > @AlexanderAshitkin have you tried using environment variable interpolation from `settings.xml` ?
   > Also it would be nice to add a bit of documentation about available solutions (settings.xml with or without interpolation / env vars).
   
   No, I haven't. Also I can't modify settings in xml in my current project, so it will not work for me in any case. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] AlexanderAshitkin commented on pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by "AlexanderAshitkin (via GitHub)" <gi...@apache.org>.
AlexanderAshitkin commented on PR #35:
URL: https://github.com/apache/maven-build-cache-extension/pull/35#issuecomment-1419160683

   @gnodet @michael-o I feel like there is no consensus for this change yet, I'm declining this pr so far. Need to agree on the design first.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] gnodet commented on pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #35:
URL: https://github.com/apache/maven-build-cache-extension/pull/35#issuecomment-1410137399

   @AlexanderAshitkin have you tried using environment variable interpolation from `settings.xml` ?
   Also it would be nice to add a bit of documentation about available solutions (settings.xml with or without interpolation / env vars).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] michael-o commented on pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #35:
URL: https://github.com/apache/maven-build-cache-extension/pull/35#issuecomment-1409297594

   I still consider this wrong and credentials must come from `settings.xml`. There you can use env var interpolation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] AlexanderAshitkin commented on pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by GitBox <gi...@apache.org>.
AlexanderAshitkin commented on PR #35:
URL: https://github.com/apache/maven-build-cache-extension/pull/35#issuecomment-1303960662

   > I have expressed my objections in the JIRA issue and why I consider this wrong.
   
   Discussed in Jira. There are strong reasons why using credentials from settings.xml in CI environment creates either security risks either unnecessary complicates maintenance. I'm happy to implement better solution as long as solution which addresses these absolutely basic concerns offered.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-build-cache-extension] rmannibucau commented on pull request #35: [MBUILDCACHE-33] Allow to set remote cache credentials from env vars

Posted by "rmannibucau (via GitHub)" <gi...@apache.org>.
rmannibucau commented on PR #35:
URL: https://github.com/apache/maven-build-cache-extension/pull/35#issuecomment-1409439167

   +1 to make settings.xml optional, it creates issues or complicated maintenance for nothing - leading to set it fully in env vars soletimes - but ultimatly it should be configurable from the env in setting reader (without materializing the file) to benefit maven as a whole and not require specific config each time IMHO.
   Can we hope to work toward that?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org