Repository: jclouds-labs
Updated Branches:
  refs/heads/master caf91f88e -> c9af1b248


Re-use the just added Passwords from jclouds-core


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/c9af1b24
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/c9af1b24
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/c9af1b24

Branch: refs/heads/master
Commit: c9af1b248e3cfd0ce312823436e986726e826ccd
Parents: caf91f8
Author: Svetoslav Neykov <[email protected]>
Authored: Fri Jul 21 09:28:06 2017 +0300
Committer: Svetoslav Neykov <[email protected]>
Committed: Tue Aug 1 14:41:06 2017 +0300

----------------------------------------------------------------------
 .../CreateResourcesThenCreateNodes.java         |  2 +-
 .../azurecompute/arm/util/Passwords.java        | 32 ----------
 .../compute/OneandoneComputeServiceAdapter.java |  2 +-
 .../jclouds/oneandone/rest/util/Passwords.java  | 64 --------------------
 .../ProfitBricksComputeServiceAdapter.java      |  2 +-
 .../profitbricks/rest/domain/Volume.java        |  2 +-
 .../profitbricks/rest/util/Passwords.java       | 64 --------------------
 .../profitbricks/rest/util/PasswordsTest.java   | 53 ----------------
 8 files changed, 4 insertions(+), 217 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/CreateResourcesThenCreateNodes.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/CreateResourcesThenCreateNodes.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/CreateResourcesThenCreateNodes.java
index e1d346c..4c712d0 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/CreateResourcesThenCreateNodes.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/CreateResourcesThenCreateNodes.java
@@ -50,7 +50,7 @@ import org.jclouds.azurecompute.arm.domain.Subnet;
 import org.jclouds.azurecompute.arm.domain.Subnet.SubnetProperties;
 import org.jclouds.azurecompute.arm.domain.VirtualNetwork.AddressSpace;
 import 
org.jclouds.azurecompute.arm.domain.VirtualNetwork.VirtualNetworkProperties;
-import org.jclouds.azurecompute.arm.util.Passwords;
+import org.jclouds.util.Passwords;
 import org.jclouds.compute.config.CustomizationResponse;
 import org.jclouds.compute.domain.NodeMetadata;
 import org.jclouds.compute.domain.Template;

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/Passwords.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/Passwords.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/Passwords.java
deleted file mode 100644
index 9bc189e..0000000
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/Passwords.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.azurecompute.arm.util;
-
-import com.google.common.io.BaseEncoding;
-
-import java.util.Random;
-
-// Seems to be a common theme between providers, perhaps should be provided by 
core (see other 'Passwords' classes)
-public class Passwords {
-    private static final Random random = new Random();
-
-    public static String generate() {
-        final byte[] buffer = new byte[15];
-        random.nextBytes(buffer);
-        return BaseEncoding.base64Url().omitPadding().encode(buffer);
-    }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/compute/OneandoneComputeServiceAdapter.java
----------------------------------------------------------------------
diff --git 
a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/compute/OneandoneComputeServiceAdapter.java
 
b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/compute/OneandoneComputeServiceAdapter.java
index fe6d521..031970a 100644
--- 
a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/compute/OneandoneComputeServiceAdapter.java
+++ 
b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/compute/OneandoneComputeServiceAdapter.java
@@ -41,7 +41,6 @@ import 
org.apache.jclouds.oneandone.rest.domain.ServerAppliance;
 import org.apache.jclouds.oneandone.rest.domain.SingleServerAppliance;
 import org.apache.jclouds.oneandone.rest.domain.Types;
 import org.apache.jclouds.oneandone.rest.domain.options.GenericQueryOptions;
-import org.apache.jclouds.oneandone.rest.util.Passwords;
 import org.jclouds.compute.ComputeServiceAdapter;
 import org.jclouds.compute.domain.Hardware;
 import org.jclouds.compute.domain.Processor;
@@ -54,6 +53,7 @@ import static 
org.jclouds.compute.util.ComputeServiceUtils.getPortRangesFromList
 import org.jclouds.domain.LoginCredentials;
 import org.jclouds.logging.Logger;
 import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.util.Passwords;
 
 @Singleton
 public class OneandoneComputeServiceAdapter implements 
ComputeServiceAdapter<Server, HardwareFlavour, SingleServerAppliance, 
DataCenter> {

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/util/Passwords.java
----------------------------------------------------------------------
diff --git 
a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/util/Passwords.java 
b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/util/Passwords.java
deleted file mode 100644
index 18da47c..0000000
--- 
a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/util/Passwords.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jclouds.oneandone.rest.util;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.Random;
-import java.util.regex.Pattern;
-
-public class Passwords {
-
-   private static final Random random = new Random();
-
-   private static final int MIN_CHAR = 8;
-   private static final int MAX_CHAR = 50;
-   private static final String PASSWORD_FORMAT = String.format(
-           "[a-zA-Z0-9][^iIloOwWyYzZ10]{%d,%d}", MIN_CHAR - 1, MAX_CHAR);
-   private static final Pattern PASSWORD_PATTERN = 
Pattern.compile(PASSWORD_FORMAT);
-
-   private static final ImmutableSet<Character> INVALID_CHARS = 
ImmutableSet.<Character>of(
-           'i', 'I', 'l', 'o', 'O', 'w', 'W', 'y', 'Y', 'z', 'Z', '1', '0');
-
-   public static boolean isValidPassword(String password) {
-      return PASSWORD_PATTERN.matcher(password).matches();
-   }
-
-   public static String generate() {
-      int count = random.nextInt(MAX_CHAR - MIN_CHAR) + MIN_CHAR;
-
-      final char[] buffer = new char[count];
-
-      final int start = 'A';
-      final int end = 'z';
-      final int gap = end - start + 1;
-
-      while (count-- != 0) {
-         char ch = (char) (random.nextInt(gap) + start);
-         if ((isBetween(ch, start, 'Z') || isBetween(ch, 'a', end))
-                 && !INVALID_CHARS.contains(ch)) {
-            buffer[count] = ch;
-         } else {
-            count++;
-         }
-      }
-      return new String(buffer);
-   }
-
-   private static boolean isBetween(char ch, int start, int end) {
-      return ch >= start && ch <= end;
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/compute/ProfitBricksComputeServiceAdapter.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/compute/ProfitBricksComputeServiceAdapter.java
 
b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/compute/ProfitBricksComputeServiceAdapter.java
index 4c79640..ca1d741 100644
--- 
a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/compute/ProfitBricksComputeServiceAdapter.java
+++ 
b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/compute/ProfitBricksComputeServiceAdapter.java
@@ -64,7 +64,6 @@ import 
org.apache.jclouds.profitbricks.rest.features.ServerApi;
 import org.apache.jclouds.profitbricks.rest.ids.NicRef;
 import org.apache.jclouds.profitbricks.rest.ids.ServerRef;
 import org.apache.jclouds.profitbricks.rest.ids.VolumeRef;
-import org.apache.jclouds.profitbricks.rest.util.Passwords;
 import org.apache.jclouds.profitbricks.rest.util.Trackables;
 import static org.jclouds.Constants.PROPERTY_USER_THREADS;
 import org.jclouds.compute.ComputeServiceAdapter;
@@ -85,6 +84,7 @@ import org.jclouds.domain.LocationScope;
 import org.jclouds.domain.LoginCredentials;
 import org.jclouds.logging.Logger;
 import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.util.Passwords;
 
 @Singleton
 public class ProfitBricksComputeServiceAdapter implements 
ComputeServiceAdapter<ServerInDataCenter, Hardware, Provisionable, Location> {

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Volume.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Volume.java
 
b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Volume.java
index 4e23ab7..50831d7 100644
--- 
a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Volume.java
+++ 
b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/domain/Volume.java
@@ -20,9 +20,9 @@ import com.google.auto.value.AutoValue;
 import com.google.common.base.Enums;
 import static com.google.common.base.Preconditions.checkArgument;
 import java.util.Set;
-import org.apache.jclouds.profitbricks.rest.util.Passwords;
 import org.jclouds.javax.annotation.Nullable;
 import org.jclouds.json.SerializedNames;
+import org.jclouds.util.Passwords;
 
 @AutoValue
 public abstract class Volume extends Trackable {

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/util/Passwords.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/util/Passwords.java
 
b/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/util/Passwords.java
deleted file mode 100644
index b6e5a85..0000000
--- 
a/profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/util/Passwords.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jclouds.profitbricks.rest.util;
-
-import java.util.Random;
-import java.util.regex.Pattern;
-
-import com.google.common.collect.ImmutableSet;
-
-public class Passwords {
-
-   private static final Random random = new Random();
-
-   private static final int MIN_CHAR = 8;
-   private static final int MAX_CHAR = 50;
-   private static final String PASSWORD_FORMAT = String.format(
-           "[a-zA-Z0-9][^iIloOwWyYzZ10]{%d,%d}", MIN_CHAR - 1, MAX_CHAR);
-   private static final Pattern PASSWORD_PATTERN = 
Pattern.compile(PASSWORD_FORMAT);
-
-   private static final ImmutableSet<Character> INVALID_CHARS = 
ImmutableSet.<Character>of(
-           'i', 'I', 'l', 'o', 'O', 'w', 'W', 'y', 'Y', 'z', 'Z', '1', '0');
-
-   public static boolean isValidPassword(String password) {
-      return PASSWORD_PATTERN.matcher(password).matches();
-   }
-
-   public static String generate() {
-      int count = random.nextInt(MAX_CHAR - MIN_CHAR) + MIN_CHAR;
-
-      final char[] buffer = new char[count];
-
-      final int start = 'A';
-      final int end = 'z';
-      final int gap = end - start + 1;
-
-      while (count-- != 0) {
-         char ch = (char) (random.nextInt(gap) + start);
-         if ((isBetween(ch, start, 'Z') || isBetween(ch, 'a', end))
-                 && !INVALID_CHARS.contains(ch))
-            buffer[count] = ch;
-         else
-            count++;
-      }
-      return new String(buffer);
-   }
-
-   private static boolean isBetween(char ch, int start, int end) {
-      return ch >= start && ch <= end;
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/c9af1b24/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.java
----------------------------------------------------------------------
diff --git 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.java
 
b/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.java
deleted file mode 100644
index 7b470ce..0000000
--- 
a/profitbricks-rest/src/test/java/org/apache/jclouds/profitbricks/rest/util/PasswordsTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jclouds.profitbricks.rest.util;
-
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-import static 
org.apache.jclouds.profitbricks.rest.util.Passwords.isValidPassword;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "PasswordsTest")
-public class PasswordsTest {
-
-   private final List<String> validPasswords = ImmutableList.of(
-           "fKVasTnNm", "84625894", "QQQQQQQQ", "qqqqqqqq", "asdfghjk"
-   );
-   private final List<String> invalidPasswords = ImmutableList.of(
-           "", "apachejclouds", "s0merand0mpassw0rd"
-   );
-
-   @Test
-   public void testPasswordValidation() {
-      for (String pwd : validPasswords)
-         assertTrue(isValidPassword(pwd), "Should've been valid: " + pwd);
-
-      for (String pwd : invalidPasswords)
-         assertFalse(isValidPassword(pwd), "Should've been invalid: " + pwd);
-   }
-
-   @Test
-   public void testGeneratorGeneratesValidPassword() {
-      final int times = 50;
-      for (int i = 0; i < times; i++) {
-         String pwd = Passwords.generate();
-         assertTrue(isValidPassword(pwd), "Failed with: " + pwd);
-      }
-   }
-}

Reply via email to