You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jclouds.apache.org by Вальо <no...@github.com> on 2016/03/29 02:47:51 UTC
[jclouds/jclouds-labs-google] Draft implementation of password
setting for windows (#170)
Draft code for setting passwords on windows.
- No If(Windows) check
- Not clear whether the deployment will be completed at the end of GoogleComputeEngineServiceAdapter.createNodeWithGroupEncodedIntoName
You can view, comment on, or merge this pull request online at:
https://github.com/jclouds/jclouds-labs-google/pull/170
-- Commit Summary --
* Draft implementation of password setting for windows
-- File Changes --
M google-compute-engine/pom.xml (5)
M google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java (48)
A google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/WindowsPasswordGenerator.java (162)
M google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java (2)
-- Patch Links --
https://github.com/jclouds/jclouds-labs-google/pull/170.patch
https://github.com/jclouds/jclouds-labs-google/pull/170.diff
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> + public String call() {
> + String serialPortContents = "";
> + Map<String, String> passwordDict = ImmutableMap.of();
> + while (!serialPortContents.startsWith("{\"ready\":true") || passwordDict.get("encryptedPassword") == null) {
> + try {
> + Thread.sleep(30 * 1000);
> + } catch (InterruptedException e) {
> + Throwables.propagate(e);
> + }
> + serialPortContents = instanceApi.getSerialPortOutput(instance.get().name(), 4).contents();
> + String[] contentEntries = serialPortContents.split("\n");
> + passwordDict = new Gson().fromJson(contentEntries[contentEntries.length - 1], Map.class);
> + }
> + return passwordDict.get("encryptedPassword");
> + }
> + }, 5, TimeUnit.MINUTES, false); // Notice that timeoutDuration should be less than EXPIRE_DURATION
I do not like the semantics of a retryable predicate here.
I want to retrieve a result after some amount of time and if it is not available try again a little later. Google Cloud documentation says exactly that. To try retrieving after 30 seconds.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/5d3a5e2ddeb7bd774eb6640c798939ffd957b5fd#r60588558
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
Testing. Do not merge yet.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-214756140
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> @@ -135,6 +135,17 @@ Operation deleteAccessConfigFromNic(@PathParam("instance") String instance,
> @GET
> @Path("/{instance}/serialPort")
> SerialPortOutput getSerialPortOutput(@PathParam("instance") String instance);
> +
> + /**
> + * Returns the specified instance's serial port output.
> + *
> + * @param instance the instance name.
> + * @return if successful, this method returns a SerialPortOutput containing the instance's serial output.
> + */
> + @Named("Instances:getSerialPortOutput")
> + @GET
> + @Path("/{instance}/serialPort")
> + SerialPortOutput getSerialPortOutput(@PathParam("instance") String instance, @QueryParam("port") int port);
Add the corresponding [mock](https://github.com/jclouds/jclouds-labs-google/blob/1.9.x/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java#L59-L66) and [live](https://github.com/jclouds/jclouds-labs-google/blob/1.9.x/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java#L160-L166) tests, to verify the behaviour when the query parameter is passed.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/5d3a5e2ddeb7bd774eb6640c798939ffd957b5fd#r60573228
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + private final Predicate<AtomicReference<Operation>> operationDone;
> +
> + // FIXME do not use new except for tests
> + @Inject
> + public ResetWindowsPassword(GoogleComputeEngineApi api, Crypto crypto, Predicate<AtomicReference<Operation>> operationDone) {
> + this.api = api;
> + this.crypto = crypto;
> + this.operationDone = operationDone;
> + }
> +
> + @Override
> + public String apply(Map<String, ?> params) {
> + String zone = (String)params.get("zone");
> + final AtomicReference<Instance> instance = (AtomicReference<Instance>)params.get("instance");
> + userName = (String)params.get("userName");
> + email = (String)params.get("email");
Same here. Remove if unused.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/7837ae3707fd231bec09706a44b4e43980a8a90a#r61080514
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> + Throwables.propagate(e);
> + }
> + serialPortContents = instanceApi.getSerialPortOutput(instance.get().name(), 4).contents();
> + String[] contentEntries = serialPortContents.split("\n");
> + passwordDict = new Gson().fromJson(contentEntries[contentEntries.length - 1], Map.class);
> + }
> + return passwordDict.get("encryptedPassword");
> + }
> + }, 5, TimeUnit.MINUTES, false); // Notice that timeoutDuration should be less than EXPIRE_DURATION
> + } catch (Exception e) {
> + throw Throwables.propagate(e);
> + }
> +
> + return decryptPassword(checkNotNull(encryptedPassword, "encryptedPassword shouldn't be null"), keys);
> +
> + } catch (NoSuchAlgorithmException e) {
@andreaturli Language level is Java 6
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r58842776
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
Reopened #170.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#event-661422299
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> @@ -73,7 +76,9 @@ public BaseGoogleComputeEngineApiLiveTest() {
> }
>
> @Override protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
> - Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
> + // BouncyCastleCrypto required for ResetWindowsPassword related tests
> + injector = newBuilder().modules(ImmutableSet.<Module>builder().addAll(modules).add(new BouncyCastleCryptoModule()).build())
@nacx You're right. I think it is better now.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/95945057ade457d2540d484c66fa2b75702fe835#r62459750
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
> + * In brief, the sequence is:
> + * <ol>
> + * <li>Generate a temporary key for encrypting and decrypting the password
> + * <li>Send the RSA public key to the instance, by settings its metadata
> + * <li>Retrieve the result from the {@link SerialPortOutput}
> + * <li>Decode and decrypt the result.
> + * </ol>
> + */
> +public class WindowsPasswordGenerator implements Function<Map<String, ?>, String> {
> +
> + /**
> + * Indicates when the key should expire. Keys are one-time use, so the metadata doesn't need to stay around for long.
> + * 10 minutes chosen to allow for differences between time on the client
> + * and time on the server.
> + */
> + private static final long EXPIRE_DURATION = 10 * 60 * 1000;
wouldn't be better to have a templateOptions for that?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r58841126
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> +import org.jclouds.googlecomputeengine.domain.Instance;
> +import org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
> +import org.jclouds.googlecomputeengine.domain.Metadata;
> +import org.jclouds.googlecomputeengine.domain.Operation;
> +import org.jclouds.googlecomputeengine.features.InstanceApi;
> +import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
> +import org.testng.annotations.Test;
> +
> +import com.google.common.base.Predicate;
> +import com.google.common.base.Predicates;
> +
> +@Test
> +public class ResetWindowsPasswordTest {
> + public void testGeneratePassword() throws Exception {
> + Crypto bcCrypto = new BouncyCastleCrypto();
> + Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
This compiles because the sshj driver has this as a transient dependency, but better declare a dependency on the jclouds bouncycastle driver in test scope in the pom.xml
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/5d3a5e2ddeb7bd774eb6640c798939ffd957b5fd#r60573124
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + logger.debug("Generating windows key for instance %s, by updating metadata", instance.get().name());
> + final InstanceApi instanceApi = api.instancesInZone(zone);
> + Metadata metadata = instance.get().metadata();
> + // If disableHtmlEscaping is not there, == will be escaped from modulus value
> + metadata.put("windows-keys", new GsonBuilder().disableHtmlEscaping().create().toJson(extractKeyMetadata(keys)));
> +
> + AtomicReference<Operation> operation = Atomics.newReference(instanceApi.setMetadata(instance.get().name(), metadata));
> + operationDone.apply(operation);
> +
> + if (operation.get().httpErrorStatusCode() != null) {
> + logger.warn("Generating windows key for %s failed. Http Error Code: %d HttpError: %s",
> + operation.get().targetId(), operation.get().httpErrorStatusCode(),
> + operation.get().httpErrorMessage());
> + }
> +
> + TimeLimiter limiter = new SimpleTimeLimiter();
Andrea's suggestion is still valid (and preferred). The ``Predicates2.retry` method will return as soon as the predicate succeeds.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r59007982
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + * <li>Generate a temporary key for encrypting and decrypting the password
> + * <li>Send the RSA public key to the instance, by settings its metadata
> + * <li>Retrieve the result from the {@link SerialPortOutput}
> + * <li>Decode and decrypt the result.
> + * </ol>
> + */
> +public class ResetWindowsPassword implements Function<Map<String, ?>, String> {
> +
> + /**
> + * Indicates when the key should expire. Keys are one-time use, so the metadata doesn't need to stay around for long.
> + * 10 minutes chosen to allow for differences between time on the client
> + * and time on the server.
> + */
> + private static final long EXPIRE_DURATION = 10 * 60 * 1000;
> + private String userName;
> + private String email;
These variables seem to be unused? Remove them.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/7837ae3707fd231bec09706a44b4e43980a8a90a#r61080489
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
@andreaturli ?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-223508179
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + } catch (InvalidKeySpecException e) {
> + Throwables.propagate(e);
> + }
> +
> + AtomicReference<Operation> operation = Atomics.newReference(instanceApi.setMetadata(instance.get().name(), metadata));
> + operationDone.apply(operation);
> +
> + if (operation.get().httpErrorStatusCode() != null) {
> + logger.warn("Generating windows key for %s failed. Http Error Code: %d HttpError: %s",
> + operation.get().targetId(), operation.get().httpErrorStatusCode(),
> + operation.get().httpErrorMessage());
> + }
> +
> + try {
> + final Map<String, String> passwordDict = new HashMap<String, String>();
> + boolean passwordRetrieved = Predicates2.retry(new Predicate<InstanceApi>() {
It is weird to have a predicate that applies to the api itself. It would make much more sense if it applied to the instance. Can you change it that way?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/3699873ab32a6f2834325b6e8de60d62549c951f#r61444574
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
Thanks @bostko!
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-207374986
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
> @@ -173,6 +181,18 @@
> // Add lookup for InstanceToNodeMetadata
> diskToSourceImage.put(instance.get().disks().get(0).source(), template.getImage().getUri());
>
> + boolean windows = options.autoCreateWindowsPassword() != null
> + ? options.autoCreateWindowsPassword()
> + : (OsFamily.WINDOWS == template.getImage().getOperatingSystem().getFamily());
I think what @nacx means is that maybe you should simply remove this boolean windows and check at line 188 something like
```
if (options.autoCreateWindowsPassword() != null && OsFamily.WINDOWS == template.getImage().getOperatingSystem().getFamily() ) { ... }
```
thoughts?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r61058283
Re: [jclouds/jclouds-labs-google] Draft implementation of password
setting for windows (#170)
Posted by Aled Sage <no...@github.com>.
Thanks @bostko
I'm going through this in more detail, and will contribute some changes that make it conform more to "the jclouds way". Here are a few pointers:
* See jclouds best practices: https://cwiki.apache.org/confluence/display/JCLOUDS/Writing+jclouds+Code
* Include clear TODO/FIXME comments where you think the code is not ready (e.g. where you are using `Thread.sleep(15000)`
* Never use System.exit
* Never use System.out.println - always use the jclouds logger
* Never use `e.printStackTrace` - always log or propagate the exception
* Use Google Guice for dependency injection, to keep things decoupled and to allow users to replace parts of the implementation/config as required
* Use Guice's `@Inject` to get existing jclouds utilities, such as `org.jclouds.crypto.Crypto`.
* Declaring dependencies like `bcprov-jdk15on` version 1.54 is dangerous - other parts of jclouds use bouncycastle 1.49. We can replace this with use of jclouds `Crypto`.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-202755416
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
> + userName = (String)params.get("userName");
> + email = (String)params.get("email");
> +
> + // TODO Check whether VM is up
> + try {
> + // Generate the public/private key pair for encryption and decryption.
> + // TODO do we need to explicitly set 2048 bits? Presumably "RSA" is implicit
> + KeyPair keys = crypto.rsaKeyPairGenerator().genKeyPair();
> +
> + // Update instance's metadata with new "windows-keys" entry, and wait for operation to
> + // complete.
> + logger.debug("Generating windows key for instance %s, by updating metadata", instance.get().name());
> + final InstanceApi instanceApi = api.instancesInZone(zone);
> + Metadata metadata = instance.get().metadata();
> + // If disableHtmlEscaping is not there, == will be escaped from modulus value
> + metadata.put("windows-keys", new GsonBuilder().disableHtmlEscaping().create().toJson(extractKeyMetadata(keys)));
[minor] weird indentation
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r58841075
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
@nacx I think all of your comments have been addressed. good to merge it?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-215113790
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
Thanks @bostko! I've just made some final comments.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-212903740
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + public String call() {
> + String serialPortContents = "";
> + Map<String, String> passwordDict = ImmutableMap.of();
> + while (!serialPortContents.startsWith("{\"ready\":true") || passwordDict.get("encryptedPassword") == null) {
> + try {
> + Thread.sleep(30 * 1000);
> + } catch (InterruptedException e) {
> + Throwables.propagate(e);
> + }
> + serialPortContents = instanceApi.getSerialPortOutput(instance.get().name(), 4).contents();
> + String[] contentEntries = serialPortContents.split("\n");
> + passwordDict = new Gson().fromJson(contentEntries[contentEntries.length - 1], Map.class);
> + }
> + return passwordDict.get("encryptedPassword");
> + }
> + }, 5, TimeUnit.MINUTES, false); // Notice that timeoutDuration should be less than EXPIRE_DURATION
Instead of manually doing this and calling Thread.sleep, use the jclouds `Predicates2.retry`.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/5d3a5e2ddeb7bd774eb6640c798939ffd957b5fd#r60573489
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> @@ -173,6 +181,18 @@
> // Add lookup for InstanceToNodeMetadata
> diskToSourceImage.put(instance.get().disks().get(0).source(), template.getImage().getUri());
>
> + boolean windows = options.autoCreateWindowsPassword() != null
> + ? options.autoCreateWindowsPassword()
> + : (OsFamily.WINDOWS == template.getImage().getOperatingSystem().getFamily());
Isn't here a need to always check the OS family? What happens if the `autoCreteWindowsPassword` is set and the image is, say, an Ubuntu?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008225
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + * and time on the server.
> + */
> + private static final long EXPIRE_DURATION = 10 * 60 * 1000;
> + private String userName;
> + private String email;
> +
> + @Resource
> + @Named(ComputeServiceConstants.COMPUTE_LOGGER)
> + protected Logger logger = Logger.NULL;
> +
> + private final GoogleComputeEngineApi api;
> + private final Crypto crypto;
> + private final Predicate<AtomicReference<Operation>> operationDone;
> +
> + @Inject
> + protected ResetWindowsPassword(GoogleComputeEngineApi api, Crypto crypto, Predicate<AtomicReference<Operation>> operationDone) {
Better remove the `protected` modifier and leave it in the default scope.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008332
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> @@ -73,7 +76,9 @@ public BaseGoogleComputeEngineApiLiveTest() {
> }
>
> @Override protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
> - Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
> + // BouncyCastleCrypto required for ResetWindowsPassword related tests
> + injector = newBuilder().modules(ImmutableSet.<Module>builder().addAll(modules).add(new BouncyCastleCryptoModule()).build())
What about providing a protected `modules` method that subclasses can override to contribute modules? This way each subclass would be able to add custom modules.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/95945057ade457d2540d484c66fa2b75702fe835#r62158760
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
@aledsage @andreaturli @nacx can you review?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-214432611
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> +import com.google.common.io.BaseEncoding;
> +import org.jclouds.crypto.Crypto;
> +import org.jclouds.encryption.bouncycastle.BouncyCastleCrypto;
> +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
> +import org.jclouds.googlecomputeengine.domain.Instance;
> +import org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
> +import org.jclouds.googlecomputeengine.domain.Metadata;
> +import org.jclouds.googlecomputeengine.domain.Operation;
> +import org.jclouds.googlecomputeengine.features.InstanceApi;
> +import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
> +import org.testng.annotations.Test;
> +
> +import com.google.common.base.Predicate;
> +import com.google.common.base.Predicates;
> +
> +@Test
Change to `@Test(groups="unit")`.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/5d3a5e2ddeb7bd774eb6640c798939ffd957b5fd#r60573268
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
@andreaturli thank you! I will make a PR against jclouds master tomorrow.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-223938034
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> + private final Predicate<AtomicReference<Operation>> operationDone;
> +
> + // FIXME do not use new except for tests
> + @Inject
> + public ResetWindowsPassword(GoogleComputeEngineApi api, Crypto crypto, Predicate<AtomicReference<Operation>> operationDone) {
> + this.api = api;
> + this.crypto = crypto;
> + this.operationDone = operationDone;
> + }
> +
> + @Override
> + public String apply(Map<String, ?> params) {
> + String zone = (String)params.get("zone");
> + final AtomicReference<Instance> instance = (AtomicReference<Instance>)params.get("instance");
> + userName = (String)params.get("userName");
> + email = (String)params.get("email");
@nacx They are used at line 217
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/7837ae3707fd231bec09706a44b4e43980a8a90a#r61082749
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + Throwables.propagate(e);
> + }
> + serialPortContents = instanceApi.getSerialPortOutput(instance.get().name(), 4).contents();
> + String[] contentEntries = serialPortContents.split("\n");
> + passwordDict = new Gson().fromJson(contentEntries[contentEntries.length - 1], Map.class);
> + }
> + return passwordDict.get("encryptedPassword");
> + }
> + }, 5, TimeUnit.MINUTES, false); // Notice that timeoutDuration should be less than EXPIRE_DURATION
> + } catch (Exception e) {
> + throw Throwables.propagate(e);
> + }
> +
> + return decryptPassword(checkNotNull(encryptedPassword, "encryptedPassword shouldn't be null"), keys);
> +
> + } catch (NoSuchAlgorithmException e) {
+1 to just catch Exception
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59007887
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
@nacx wdyt?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-214749017
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> @@ -165,6 +212,19 @@ public void testGetSerialPortOutput() {
> assertNotNull(output.contents());
> }
>
> + @Test(groups = "live", dependsOnMethods = "testInsertInstanceWindows")
> + public void testGetSerialPortOutput4() throws NoSuchAlgorithmException, CertificateException {
> + Crypto crypto = new BouncyCastleCrypto();
> + Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
> + Instance instance = api().get(INSTANCE_NAME_WINDOWS);
> +
> + // TODO instantiate better way ResetWindowsPassword
> + // TODO think about not using it at all
Agree, in this test you just need to call the API and verify the call itself works. There is no need to call the reset password logic here.
If you want to do so, however, you'dd better override the `create` method of the parent class so you can get a `ResetWindowsPassword` instance from the injector.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/7837ae3707fd231bec09706a44b4e43980a8a90a#r61080968
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
Closed #170.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#event-682644994
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> @@ -29,6 +29,7 @@
>
> private URI network = null;
> private boolean autoCreateKeyPair = true;
> + private Boolean autoCreateWindowsPassword = null;
Better use a primitive boolean.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008538
Re: [jclouds/jclouds-labs-google] Draft implementation of password
setting for windows (#170)
Posted by Вальо <no...@github.com>.
> + GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
> + InstanceApi instanceApi = createMock(InstanceApi.class);
> + Operation operation = createMock(Operation.class);
> + SerialPortOutput serialPortOutput = createMock(SerialPortOutput.class);
> + Crypto crypto = createMock(Crypto.class);
> + KeyPairGenerator keyPairGenerator = createMock(KeyPairGenerator.class);
> +
> + expect(api.instancesInZone(zone)).andReturn(instanceApi).atLeastOnce();
> + expect(crypto.rsaKeyPairGenerator()).andReturn(keyPairGenerator);
> + expect(keyPairGenerator.genKeyPair()).andReturn(keyPair);
> + // FIXME assert that metadata contained what we expected
> + expect(instanceApi.setMetadata(eq(instance.name()), isA(Metadata.class))).andReturn(operation).atLeastOnce();
> + expect(operation.httpErrorStatusCode()).andReturn(null);
> + expect(instanceApi.getSerialPortOutput(instance.name(), 4)).andReturn(serialPortOutput).atLeastOnce();
> + expect(serialPortOutput.contents()).andReturn("{\"ready\":true,\"version\":\"Microsoft Windows NT 6.2.9200.0\"}\n" +
> + "{\"encryptedPassword\":\""+ "encrypted and base64encoded password with keyPair.getPublic()"+ "\",\"exponent\":\"AQAB\",\"passwordFound\":true,\"userName\":\"Administrator\"}");
Need help with the test.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r58839912
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
Just add the jclouds bouncycastle driver dependency in test scope (and remove the explicit bouncycastle dependency if possible, to get it transitively from the jclouds driver) and add the BouncyCastleCryptoModule to the list of modules being passed to create the context.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-214805812
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> + Throwables.propagate(e);
> + }
> + serialPortContents = instanceApi.getSerialPortOutput(instance.get().name(), 4).contents();
> + String[] contentEntries = serialPortContents.split("\n");
> + passwordDict = new Gson().fromJson(contentEntries[contentEntries.length - 1], Map.class);
> + }
> + return passwordDict.get("encryptedPassword");
> + }
> + }, 5, TimeUnit.MINUTES, false); // Notice that timeoutDuration should be less than EXPIRE_DURATION
> + } catch (Exception e) {
> + throw Throwables.propagate(e);
> + }
> +
> + return decryptPassword(checkNotNull(encryptedPassword, "encryptedPassword shouldn't be null"), keys);
> +
> + } catch (NoSuchAlgorithmException e) {
What others think about making it catch `Exception`?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r58992010
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
ok cool! Merging now!
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-223916136
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + * <li>Generate a temporary key for encrypting and decrypting the password
> + * <li>Send the RSA public key to the instance, by settings its metadata
> + * <li>Retrieve the result from the {@link SerialPortOutput}
> + * <li>Decode and decrypt the result.
> + * </ol>
> + */
> +public class ResetWindowsPassword implements Function<Map<String, ?>, String> {
> +
> + /**
> + * Indicates when the key should expire. Keys are one-time use, so the metadata doesn't need to stay around for long.
> + * 10 minutes chosen to allow for differences between time on the client
> + * and time on the server.
> + */
> + private static final long EXPIRE_DURATION = 10 * 60 * 1000;
> + private String userName;
> + private String email;
I see now. Instead of making it member variables, please, make it local variables in the apply method and pass them to the methods that need them. We should avoid mutable state wherever possible.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/7837ae3707fd231bec09706a44b4e43980a8a90a#r61091845
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
> @@ -0,0 +1 @@
> +org.jclouds.googlecomputeengine.GoogleComputeEngineApiMetadata
do we need to commit this file?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/96991e53462c8db314b277dcd332f66f6d602e3a#r61058487
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + private final Crypto crypto;
> + private final Predicate<AtomicReference<Operation>> operationDone;
> +
> + @Inject
> + ResetWindowsPassword(GoogleComputeEngineApi api, Crypto crypto, Predicate<AtomicReference<Operation>> operationDone) {
> + this.api = api;
> + this.crypto = crypto;
> + this.operationDone = operationDone;
> + }
> +
> + @Override
> + public String apply(Map<String, ?> params) {
> + String zone = (String)params.get("zone");
> + final AtomicReference<Instance> instance = (AtomicReference<Instance>)params.get("instance");
> + userName = (String)params.get("userName");
> + email = (String)params.get("email");
[minor] fix indentation.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/5d3a5e2ddeb7bd774eb6640c798939ffd957b5fd#r60573302
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> @@ -73,7 +76,9 @@ public BaseGoogleComputeEngineApiLiveTest() {
> }
>
> @Override protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
> - Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
> + // BouncyCastleCrypto required for ResetWindowsPassword related tests
> + injector = newBuilder().modules(ImmutableSet.<Module>builder().addAll(modules).add(new BouncyCastleCryptoModule()).build())
@andreaturli what do you think about adding `BouncyCastleCryptoModule` here?
Do you have an idea how I can subclass it directly in the `InstanceApiWindowsLiveTest`
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/95945057ade457d2540d484c66fa2b75702fe835#r61847303
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
Apologies for this late feedback @bostko, I've been really busy this last week.
The code now looks good to me. Good to merge @andreaturli @aledsage?
BTW, with this change, the "auto generate password on windows" takes preference over the "overrideLoginPassword". If both options are configured (why would one want to do that? :)) a password will be auto-generated if it is a windows image. Just wanted to make it clear here, so we can take it into account in the release notes.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-221537972
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
Also, my comment regarding the bouncycastle dependency has not been addressed. We'd better add the driver dependency explicitly (as we're using the driver), and remove the explicit BC dep, to let the driver bring it as a transitive dependency.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-215457523
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> +import com.google.common.collect.FluentIterable;
> +
> +@Test(groups = "live", testName = "InstanceApiLiveTest")
> +public class InstanceApiWindowsLiveTest extends BaseGoogleComputeEngineApiLiveTest {
> +
> + private static final String INSTANCE_NETWORK_NAME = "instance-api-live-test-network";
> + private static final String INSTANCE_NAME = "instance-api-test-instance-1";
> + private static final String DISK_NAME = "instance-live-test-disk";
> + private static final String IPV4_RANGE = "10.0.0.0/8";
> + private static final int DEFAULT_DISK_SIZE_GB = 25;
> +
> + private Function<Map<String, ?>, String> reset_windows_password;
> + private NewInstance instance;
> +
> + @Override
> + protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
Instead of copying the method from the parent class, change it in a way that allows subclasses to cleanly override it. Let's change the parent class to assign the Injector to a local protected variable, so this class does not need to copy all the logic and can just call `super` and add its own after that.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/3699873ab32a6f2834325b6e8de60d62549c951f#r61444816
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
@nacx the live tests do not work now because it is loading the wrong crypto.
It is loading `org.jclouds.encryption.internal.JCECrypto` instead of `org.jclouds.encryption.bouncycastle.BouncyCastleCrypto`
How to tell the injector to use the correct one in tests?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-214799948
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
Thanks @bostko, almost there!
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-214734684
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + * <li>Retrieve the result from the {@link SerialPortOutput}
> + * <li>Decode and decrypt the result.
> + * </ol>
> + */
> +public class ResetWindowsPassword implements Function<Map<String, ?>, String> {
> +
> + /**
> + * Indicates when the key should expire. Keys are one-time use, so the metadata doesn't need to stay around for long.
> + * 10 minutes chosen to allow for differences between time on the client
> + * and time on the server.
> + */
> + private static final long EXPIRE_DURATION = 10 * 60 * 1000;
> + private String userName;
> + private String email;
> +
> + @Resource
[minor] fix indentation.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008346
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
Let's see if Jenkins wants to build it this time now that our PR builders are fixed: rebuild please
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-221538031
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
thanks @bostko
Merged at [1.9.x](http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/276ee07e)
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-223918424
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> + logger.debug("Generating windows key for instance %s, by updating metadata", instance.get().name());
> + final InstanceApi instanceApi = api.instancesInZone(zone);
> + Metadata metadata = instance.get().metadata();
> + // If disableHtmlEscaping is not there, == will be escaped from modulus value
> + metadata.put("windows-keys", new GsonBuilder().disableHtmlEscaping().create().toJson(extractKeyMetadata(keys)));
> +
> + AtomicReference<Operation> operation = Atomics.newReference(instanceApi.setMetadata(instance.get().name(), metadata));
> + operationDone.apply(operation);
> +
> + if (operation.get().httpErrorStatusCode() != null) {
> + logger.warn("Generating windows key for %s failed. Http Error Code: %d HttpError: %s",
> + operation.get().targetId(), operation.get().httpErrorStatusCode(),
> + operation.get().httpErrorMessage());
> + }
> +
> + TimeLimiter limiter = new SimpleTimeLimiter();
The pattern is a little different here.
My aim is not to verify uncertain predicate or or verify reach-ability.
I just want to return on first success.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r58855971
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> @@ -135,6 +135,17 @@ Operation deleteAccessConfigFromNic(@PathParam("instance") String instance,
> @GET
> @Path("/{instance}/serialPort")
> SerialPortOutput getSerialPortOutput(@PathParam("instance") String instance);
> +
> + /**
> + * Returns the specified instance's serial port output.
> + *
> + * @param instance the instance name.
> + * @return if successful, this method returns a SerialPortOutput containing the instance's serial output.
> + */
> + @Named("Instances:getSerialPortOutput") // FIXME What does "Named" really do?!
It is used to allow to configure a specific timeout for this method. Users can set properties to customize timeouts for concrete methods by using the value in this annotation.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008657
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
> + logger.debug("Generating windows key for instance %s, by updating metadata", instance.get().name());
> + final InstanceApi instanceApi = api.instancesInZone(zone);
> + Metadata metadata = instance.get().metadata();
> + // If disableHtmlEscaping is not there, == will be escaped from modulus value
> + metadata.put("windows-keys", new GsonBuilder().disableHtmlEscaping().create().toJson(extractKeyMetadata(keys)));
> +
> + AtomicReference<Operation> operation = Atomics.newReference(instanceApi.setMetadata(instance.get().name(), metadata));
> + operationDone.apply(operation);
> +
> + if (operation.get().httpErrorStatusCode() != null) {
> + logger.warn("Generating windows key for %s failed. Http Error Code: %d HttpError: %s",
> + operation.get().targetId(), operation.get().httpErrorStatusCode(),
> + operation.get().httpErrorMessage());
> + }
> +
> + TimeLimiter limiter = new SimpleTimeLimiter();
use a retry strategy like [this](https://github.com/jclouds/jclouds-labs/blob/master/azurecompute/src/main/java/org/jclouds/azurecompute/compute/AzureComputeServiceAdapter.java#L159-L177)
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r58841424
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
@nacx I saw your comment now.
I did it :)
There was problem cleaning up resources. I decided to move this live test into new class so the windows is not dependent on the centos instances used in the original `InstanceApiLiveTest`
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-214830552
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
> +import org.jclouds.googlecomputeengine.domain.Instance;
> +import org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
> +import org.jclouds.googlecomputeengine.domain.Metadata;
> +import org.jclouds.googlecomputeengine.domain.Operation;
> +import org.jclouds.googlecomputeengine.features.InstanceApi;
> +import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
> +import org.testng.annotations.Test;
> +
> +import com.google.common.base.Predicate;
> +import com.google.common.base.Predicates;
> +
> +@Test(groups = "WIP")
> +public class ResetWindowsPasswordTest {
> + public void testGeneratePassword() throws Exception {
> + Crypto bcCrypto = new BouncyCastleCrypto();
Should the bouncycastle driver dependency be added to the pom.xml in test scope?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008799
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> + }
> +
> + /**
> + * Decrypts the given password - the encrypted text is base64-encoded.
> + * As per the GCE docs, assumes it was encrypted with algorithm "RSA/NONE/OAEPPadding", and UTF-8.
> + * @throws NoSuchPaddingException
> + * @throws NoSuchAlgorithmException
> + * @throws InvalidKeyException
> + * @throws BadPaddingException
> + * @throws IllegalBlockSizeException
> + */
> + protected String decryptPassword(String message, KeyPair keys) throws NoSuchAlgorithmException,
> + NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
> + // FIXME how to ensure crypto supports OAEPPadding?
> + // FIXME Valentin's code was also passing provider "BC"
> + // Assumes user has configured appropriate crypto guice module.
It is OK to assume that. We could try/catch the exception here and print a log message suggesting the addition of the bouncycastle driver dependency.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008471
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
@nacx @andreaturli can you review it again?
Is it ok?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#issuecomment-212320778
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> @@ -173,6 +181,18 @@
> // Add lookup for InstanceToNodeMetadata
> diskToSourceImage.put(instance.get().disks().get(0).source(), template.getImage().getUri());
>
> + boolean windows = options.autoCreateWindowsPassword() != null
> + ? options.autoCreateWindowsPassword()
> + : (OsFamily.WINDOWS == template.getImage().getOperatingSystem().getFamily());
@nacx does it make sence to have `autoCreteWindowsPassword` for a windows image.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59354283
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
> + * <li>Generate a temporary key for encrypting and decrypting the password
> + * <li>Send the RSA public key to the instance, by settings its metadata
> + * <li>Retrieve the result from the {@link SerialPortOutput}
> + * <li>Decode and decrypt the result.
> + * </ol>
> + */
> +public class ResetWindowsPassword implements Function<Map<String, ?>, String> {
> +
> + /**
> + * Indicates when the key should expire. Keys are one-time use, so the metadata doesn't need to stay around for long.
> + * 10 minutes chosen to allow for differences between time on the client
> + * and time on the server.
> + */
> + private static final long EXPIRE_DURATION = 10 * 60 * 1000;
> + private String userName;
> + private String email;
@nacx They are used at line 217
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/7837ae3707fd231bec09706a44b4e43980a8a90a#r61082657
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Ignasi Barrera <no...@github.com>.
> +import com.google.common.collect.ImmutableMap;
> +import org.jclouds.crypto.Crypto;
> +import org.jclouds.encryption.bouncycastle.BouncyCastleCrypto;
> +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
> +import org.jclouds.googlecomputeengine.domain.Instance;
> +import org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
> +import org.jclouds.googlecomputeengine.domain.Metadata;
> +import org.jclouds.googlecomputeengine.domain.Operation;
> +import org.jclouds.googlecomputeengine.features.InstanceApi;
> +import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
> +import org.testng.annotations.Test;
> +
> +import com.google.common.base.Predicate;
> +import com.google.common.base.Predicates;
> +
> +@Test(groups = "WIP")
Move it to the unit group
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/ae6a31bb0190a334fd4fa75a51e7b48ebbc15669#r59008682
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Вальо <no...@github.com>.
Closed #170.
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170#event-661422284
Re: [jclouds/jclouds-labs-google] Implementation of password setting
for windows (#170)
Posted by Andrea Turli <no...@github.com>.
> + Throwables.propagate(e);
> + }
> + serialPortContents = instanceApi.getSerialPortOutput(instance.get().name(), 4).contents();
> + String[] contentEntries = serialPortContents.split("\n");
> + passwordDict = new Gson().fromJson(contentEntries[contentEntries.length - 1], Map.class);
> + }
> + return passwordDict.get("encryptedPassword");
> + }
> + }, 5, TimeUnit.MINUTES, false); // Notice that timeoutDuration should be less than EXPIRE_DURATION
> + } catch (Exception e) {
> + throw Throwables.propagate(e);
> + }
> +
> + return decryptPassword(checkNotNull(encryptedPassword, "encryptedPassword shouldn't be null"), keys);
> +
> + } catch (NoSuchAlgorithmException e) {
what's the benefit of multiple catches?
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-google/pull/170/files/172e50d1a163c5ba80ed638cf9c7b25982ca204c#r58841675