Giter Club home page Giter Club logo

servers-maven-extension's Introduction

servers-maven-extension

Maven 3+ extension for exposing settings.xml/servers to ${}. What this means is that you can reference content of <servers>...</servers> section (in form of ${settings.servers.<server id>.<property>}) from any pom.xml file within your project. Also, starting from 1.2.0 release any part of <servers>...</servers> can be overridden with user specified properties (-Dsettings.servers.<server id>.<property>=<value>).

${settings.servers.server.<server id>.<property>} format is also supported for the backwards compatibility with 1.0.0 release.

(see #7 for security implications)

Usage

Include following extension declaration into the (root) pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    ...
    <build>
        ...
        <extensions>
            ...
            <extension>
                <groupId>com.github.shyiko.servers-maven-extension</groupId>
                <artifactId>servers-maven-extension</artifactId>
                <version>1.3.1</version>
            </extension>
            ...
        </extensions>
        ...
    </build>

</project>

Example

settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <servers>
        <server>
            <id>ssh-server</id>
            <username>username</username>
            <privateKey>${user.home}/.ssh/id_rsa</privateKey>
        </server>
    </servers>
    ...

</settings>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    ...
    <build>
        <plugins>
            <plugin>
                <groupId>...</groupId>
                <artifactId>...</artifactId>
                <configuration>
                    <location>
                        scp://${settings.servers.ssh-server.username}:from-key-file@${ssh-server.url}
                    </location>
                    <keyfile>${settings.servers.ssh-server.privateKey}</keyfile>
                    ...
                </configuration>
            </plugin>
        </plugins>
        <extensions>
            <extension>
                <groupId>com.github.shyiko.servers-maven-extension</groupId>
                <artifactId>servers-maven-extension</artifactId>
                <version>1.3.1</version>
            </extension>
        </extensions>
    </build>

</project>

License

Apache License, Version 2.0

servers-maven-extension's People

Contributors

azzazzel avatar shyiko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

servers-maven-extension's Issues

Eclipse integration ?

Hi Stanley,

This is a very useful extension. Thank you!

We successfully used it for a multi-module project where we need username/password for tests calling a web service and we do not want to store them in source control in plaintext in the pom.xml.

It all works well in pure Maven builds (on CI build server) and also with the Intellij IDE (we use Community Edition) and its Maven integration.

But in Eclipse (tested in Oxygen and Mars) the extension does not seem to have any effect. None of the property expressions of the form ${settings.servers.*} are substituted.

Is this a known limitation? Do you know if we need to install or configure something in Eclipse to make the extension work within the Eclipse Maven life-cycle integration?

Thanks
Oliver

Server properties not being interpreted

I've bound a command to the deploy lifecycle that needs the server username and password, but it doesn't interpret them correctly. When I run mvn with -X I get the below output, showing that it's just using the literal values.

<location>scp://${settings.servers.server.eApp.username}:${settings.servers.server.eApp.password}

I have the extension installed in my pom.xml as shown below.

    <build>
    <extensions>
        <!--Lets us access the server variables from settings.xml with the following syntax ${settings.servers.server.<server id>.<property>}-->
        <extension>
            <groupId>com.github.shyiko.servers-maven-extension</groupId>
            <artifactId>servers-maven-extension</artifactId>
            <version>1.0.0</version>
        </extension>
    </extensions>

Suppress password output in build log

Assume you have a settings.xml with this content:

        <server>
            <id>generic-snapshot-local</id>
            <username>SRNME</username>
            <password>PSSWRD</password>
        </server>

Further assume Maven is running at the DEBUG log level.
In that case, you can expect the following to appear in the log output:

[DEBUG] properties used {..., settings.servers.server.generic-release-local.username=SRNME, ..., settings.servers.server.generic-release-local.password=PSSWRD, ...}

Now cleartext passwords are NOT what you want to see in a build log: Developers will forget to delete them because they are occupied with whatever other problem they are trying to solve, usually under pressure from a deadline.
(Background: I'm in the Fintech industry. Having logs with passwords is not just a no-no and a slap on the fingers, it's the kind of stuff that can get you fired. As it stands, I cannot use the plugin.)

I can see two alternatives how to deal with this:
a) Somehow suppress the output in the logs. This affects not just the outputs from Maven itselfs but also that of plugins, though one could arguably maintain the position that plugins have no business printing all properties willy-nilly (in my build, that's just install4j-maven-plugin, but more may exist).
b) Clearly document the security implications in the documentation of server-maven-extension.

I guess (b) is necessary to do first, because doing (a) is going to be pretty difficult, and if Maven internally does not have a way to mark properties as "secret, do not print", (b) will have to stay even if (a) is implemented.

Support for Encrypted Passwords Appears to be Broken

I am receiving this error when using encrypted passwords in my settings.xml file:

[ERROR] Failed to expose settings.servers.*: Illegal group reference -> [Help 1]
org.apache.maven.MavenExecutionException: Failed to expose settings.servers.*
        at com.github.shyiko.sme.ServersExtension.afterProjectsRead(ServersExtension.java:97)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:266)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.IllegalArgumentException: Illegal group reference
        at java.util.regex.Matcher.appendReplacement(Matcher.java:857)
        at com.github.shyiko.sme.ServersExtension.decryptInlinePasswords(ServersExtension.java:106)
        at com.github.shyiko.sme.ServersExtension.afterProjectsRead(ServersExtension.java:74)
        ... 14 more

Contents of POM:

<build>
        <extensions>
            <extension>
                <groupId>com.github.shyiko.servers-maven-extension</groupId>
                <artifactId>servers-maven-extension</artifactId>
                <version>1.3.0</version>
            </extension>
        </extensions>
...

If I escape the curly braces with an '', the error goes away, but then the strings are not recognized as encrypted passwords.

Any help would be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.