public String getCredentialsKey() { return key != null ? key : getProjectProperty(CredentialsPlugin.CREDENTIALS_KEY_PROPERTY); }
public String getCredentialsKey() { return key != null ? key : getProjectProperty(CredentialsPlugin.CREDENTIALS_KEY_PROPERTY); }
private String getProjectProperty(String key) { return (String) getProject().getProperties().get(key); }
@Override public void apply(Project project) { String passphrase = getProjectProperty(CREDENTIALS_PASSPHRASE_PROPERTY, DEFAULT_PASSPHRASE, project); String credentialsFileName = deriveFileNameFromPassphrase(passphrase); CredentialsEncryptor credentialsEncryptor = CredentialsEncryptor.withPassphrase(passphrase.toCharArray()); CredentialsPersistenceManager credentialsPersistenceManager = new CredentialsPersistenceManager(credentialsFile); CredentialsContainer credentialsContainer = new CredentialsContainer(credentialsEncryptor, credentialsPersistenceManager.readCredentials()); project.getExtensions().getExtraProperties().set(CREDENTIALS_CONTAINER_PROPERTY, credentialsContainer); LOGGER.debug("Registered property '" + CREDENTIALS_CONTAINER_PROPERTY + "'"); addCredentials.setDescription("Adds the credentials specified through the project properties 'credentialsKey' and 'credentialsValue'."); addCredentials.setGroup("Credentials"); addCredentials.setCredentialsEncryptor(credentialsEncryptor); addCredentials.setCredentialsPersistenceManager(credentialsPersistenceManager); addCredentials.getOutputs().upToDateWhen(AlwaysFalseSpec.INSTANCE); LOGGER.debug(String.format("Registered task '%s'", addCredentials.getName())); removeCredentials.setDescription("Removes the credentials specified through the project property 'credentialsKey'."); removeCredentials.setGroup("Credentials"); removeCredentials.setCredentialsPersistenceManager(credentialsPersistenceManager); removeCredentials.getOutputs().upToDateWhen(AlwaysFalseSpec.INSTANCE); LOGGER.debug(String.format("Registered task '%s'", removeCredentials.getName()));
@TaskAction void addCredentials() throws IOException { // get credentials key and value from the project properties String key = getCredentialsKey(); String value = getCredentialsValue(); char[] placeholderValue = new char[value.length()]; Arrays.fill(placeholderValue, '*'); LOGGER.debug(String.format("Add credentials with key: '%s', value: '%s'", key, new String(placeholderValue))); // read the current persisted credentials OrderedProperties credentials = credentialsPersistenceManager.readCredentials(); // encrypt value and update credentials String encryptedValue = credentialsEncryptor.encrypt(value); credentials.setProperty(key, encryptedValue); // persist the updated credentials credentialsPersistenceManager.storeCredentials(credentials); }
@TaskAction void removeCredentials() throws IOException { // get credentials key from the project properties String key = getCredentialsKey(); LOGGER.debug(String.format("Remove credentials with key: '%s'", key)); // read the current persisted credentials OrderedProperties credentials = credentialsPersistenceManager.readCredentials(); // remove the credentials with the given key credentials.removeProperty(key); // persist the updated credentials credentialsPersistenceManager.storeCredentials(credentials); }
private String getProjectProperty(String key) { return (String) getProject().getProperties().get(key); }
@Override public void apply(Project project) { String passphrase = getProjectProperty(CREDENTIALS_PASSPHRASE_PROPERTY, DEFAULT_PASSPHRASE, project); String credentialsFileName = deriveFileNameFromPassphrase(passphrase); CredentialsEncryptor credentialsEncryptor = CredentialsEncryptor.withPassphrase(passphrase.toCharArray()); CredentialsPersistenceManager credentialsPersistenceManager = new CredentialsPersistenceManager(credentialsFile); CredentialsContainer credentialsContainer = new CredentialsContainer(credentialsEncryptor, credentialsPersistenceManager.readCredentials()); project.getExtensions().getExtraProperties().set(CREDENTIALS_CONTAINER_PROPERTY, credentialsContainer); LOGGER.debug("Registered property '" + CREDENTIALS_CONTAINER_PROPERTY + "'"); addCredentials.setDescription("Adds the credentials specified through the project properties 'credentialsKey' and 'credentialsValue'."); addCredentials.setGroup("Credentials"); addCredentials.setCredentialsEncryptor(credentialsEncryptor); addCredentials.setCredentialsPersistenceManager(credentialsPersistenceManager); addCredentials.getOutputs().upToDateWhen(AlwaysFalseSpec.INSTANCE); LOGGER.debug(String.format("Registered task '%s'", addCredentials.getName())); removeCredentials.setDescription("Removes the credentials specified through the project property 'credentialsKey'."); removeCredentials.setGroup("Credentials"); removeCredentials.setCredentialsPersistenceManager(credentialsPersistenceManager); removeCredentials.getOutputs().upToDateWhen(AlwaysFalseSpec.INSTANCE); LOGGER.debug(String.format("Registered task '%s'", removeCredentials.getName()));
@TaskAction void addCredentials() { // get credentials key and value from the command line or project properties String key = getCredentialsKey(); if (key == null) { throw new IllegalArgumentException("Credentials key must not be null"); } String value = getCredentialsValue(); if (value == null) { throw new IllegalArgumentException("Credentials value must not be null"); } char[] placeholderValue = new char[value.length()]; Arrays.fill(placeholderValue, '*'); LOGGER.debug(String.format("Add credentials with key: '%s', value: '%s'", key, new String(placeholderValue))); // read the current persisted credentials OrderedProperties credentials = credentialsPersistenceManager.readCredentials(); // encrypt value and update credentials String encryptedValue = credentialsEncryptor.encrypt(value); credentials.setProperty(key, encryptedValue); // persist the updated credentials credentialsPersistenceManager.storeCredentials(credentials); }
@TaskAction void removeCredentials() { // get credentials key from the project properties String key = getCredentialsKey(); LOGGER.debug(String.format("Remove credentials with key: '%s'", key)); // read the current persisted credentials OrderedProperties credentials = credentialsPersistenceManager.readCredentials(); // remove the credentials with the given key credentials.removeProperty(key); // persist the updated credentials credentialsPersistenceManager.storeCredentials(credentials); }
public String getCredentialsValue() { return value != null ? value : getProjectProperty(CredentialsPlugin.CREDENTIALS_VALUE_PROPERTY); }
public String getCredentialsKey() { return key != null ? key : getProjectProperty(CredentialsPlugin.CREDENTIALS_KEY_PROPERTY); }
private String getProjectProperty(String key) { return (String) getProject().getProperties().get(key); }
private String getProjectProperty(String key) { return (String) getProject().getProperties().get(key); }
@Internal("Do not annotate as @Input to avoid the value being stored in the task artifact cache") public String getCredentialsValue() { return value != null ? value : getProjectProperty(CredentialsPlugin.CREDENTIALS_VALUE_PROPERTY); }
@Internal("Do not annotate as @Input to avoid the key being stored in the task artifact cache") public String getCredentialsKey() { return key != null ? key : getProjectProperty(CredentialsPlugin.CREDENTIALS_KEY_PROPERTY); }