http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java deleted file mode 100644 index 28cc443..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java +++ /dev/null @@ -1,65 +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.googlecomputeengine.functions.internal; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Inject; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.domain.ListPage; -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.Json; - -import com.google.common.base.Function; -import com.google.inject.TypeLiteral; - -public class ParseZoneOperations extends ParseJson<ListPage<Operation>> { - - @Inject - public ParseZoneOperations(Json json) { - super(json, new TypeLiteral<ListPage<Operation>>() { - }); - } - - public static class ToPagedIterable extends BaseWithZoneToPagedIterable<Operation, ToPagedIterable> { - - private final GoogleComputeEngineApi api; - - @Inject - protected ToPagedIterable(GoogleComputeEngineApi api) { - this.api = checkNotNull(api, "api"); - } - - @Override - protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName, - final String zoneName, - final ListOptions options) { - return new Function<Object, IterableWithMarker<Operation>>() { - - @Override - public IterableWithMarker<Operation> apply(Object input) { - return api.getZoneOperationApiForProject(projectName) - .listAtMarkerInZone(zoneName, input.toString(), options); - } - }; - } - } -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java deleted file mode 100644 index f3e54ea..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java +++ /dev/null @@ -1,63 +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.googlecomputeengine.functions.internal; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Inject; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.domain.ListPage; -import org.jclouds.googlecomputeengine.domain.Zone; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.Json; - -import com.google.common.base.Function; -import com.google.inject.TypeLiteral; - -public class ParseZones extends ParseJson<ListPage<Zone>> { - - @Inject - public ParseZones(Json json) { - super(json, new TypeLiteral<ListPage<Zone>>() { - }); - } - - public static class ToPagedIterable extends BaseToPagedIterable<Zone, ToPagedIterable> { - - private final GoogleComputeEngineApi api; - - @Inject - protected ToPagedIterable(GoogleComputeEngineApi api) { - this.api = checkNotNull(api, "api"); - } - - @Override - protected Function<Object, IterableWithMarker<Zone>> fetchNextPage(final String projectName, - final ListOptions options) { - return new Function<Object, IterableWithMarker<Zone>>() { - - @Override - public IterableWithMarker<Zone> apply(Object input) { - return api.getZoneApiForProject(projectName).listAtMarker(input.toString(), options); - } - }; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/FirewallBinder.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/FirewallBinder.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/FirewallBinder.java deleted file mode 100644 index b5ce22e..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/FirewallBinder.java +++ /dev/null @@ -1,56 +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.googlecomputeengine.handlers; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.googlecomputeengine.options.FirewallOptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.MapBinder; -import org.jclouds.rest.binders.BindToJsonPayload; - -public class FirewallBinder implements MapBinder { - - @Inject - private BindToJsonPayload jsonBinder; - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { - FirewallOptions options = (FirewallOptions) checkNotNull(postParams.get("options"), "firewallOptions"); - String name = (String) checkNotNull(postParams.get("name"), "name"); - URI network = (URI) checkNotNull(postParams.get("network"), "network"); - options.name(name); - options.network(network); - return bindToRequest(request, options); - } - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - return jsonBinder.bindToRequest(request, input); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandler.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandler.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandler.java deleted file mode 100644 index 109b050..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandler.java +++ /dev/null @@ -1,62 +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.googlecomputeengine.handlers; - -import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; - -import javax.inject.Singleton; - -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.ResourceNotFoundException; - -/** - * This will parse and set an appropriate exception on the command object. - */ -@Singleton -public class GoogleComputeEngineErrorHandler implements HttpErrorHandler { - public void handleError(HttpCommand command, HttpResponse response) { - // it is important to always read fully and close streams - byte[] data = closeClientButKeepContentStream(response); - String message = data != null ? new String(data) : null; - - Exception exception = message != null ? new HttpResponseException(command, response, message) - : new HttpResponseException(command, response); - message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), - response.getStatusLine()); - switch (response.getStatusCode()) { - case 400: - break; - case 401: - case 403: - exception = new AuthorizationException(message, exception); - break; - case 404: - if (!command.getCurrentRequest().getMethod().equals("DELETE")) { - exception = new ResourceNotFoundException(message, exception); - } - break; - case 409: - exception = new IllegalStateException(message, exception); - break; - } - command.setException(exception); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/InstanceBinder.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/InstanceBinder.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/InstanceBinder.java deleted file mode 100644 index 2559ede..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/InstanceBinder.java +++ /dev/null @@ -1,65 +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.googlecomputeengine.handlers; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.jclouds.googlecomputeengine.domain.InstanceTemplate; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.MapBinder; -import org.jclouds.rest.binders.BindToJsonPayload; - -import com.google.common.base.Function; - -public class InstanceBinder implements MapBinder { - - @Inject - private BindToJsonPayload jsonBinder; - - @Inject - @Named("machineTypeToURI") - Function<String, URI> machineTypesToURI; - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { - InstanceTemplate template = (InstanceTemplate) checkNotNull(postParams.get("template"), "template"); - template.name(checkNotNull(postParams.get("name"), "name").toString()); - - if (template.getMachineTypeName() != null) { - template.machineType(machineTypesToURI.apply(template.getMachineTypeName())); - } - template.machineType((String) null); - return bindToRequest(request, template); - } - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - return jsonBinder.bindToRequest(request, input); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/MetadataBinder.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/MetadataBinder.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/MetadataBinder.java deleted file mode 100644 index b96afb4..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/MetadataBinder.java +++ /dev/null @@ -1,60 +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.googlecomputeengine.handlers; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.googlecomputeengine.domain.Metadata; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.MapBinder; -import org.jclouds.rest.binders.BindToJsonPayload; - -import com.google.common.collect.ImmutableMap; - -public class MetadataBinder implements MapBinder { - - @Inject - private BindToJsonPayload jsonBinder; - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { - Map<String, String> items = - ImmutableMap.copyOf((Map<String, String>) checkNotNull(postParams.get("items"), "item")); - String fingerprint = (String) checkNotNull(postParams.get("fingerprint"), "fingerprint"); - Metadata metadata = Metadata.builder() - .fingerprint(fingerprint) - .items(items) - .build(); - return bindToRequest(request, metadata); - } - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - return jsonBinder.bindToRequest(request, input); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java deleted file mode 100644 index 2863b44..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java +++ /dev/null @@ -1,56 +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.googlecomputeengine.handlers; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.googlecomputeengine.options.RouteOptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.MapBinder; -import org.jclouds.rest.binders.BindToJsonPayload; - -public class RouteBinder implements MapBinder { - - @Inject - private BindToJsonPayload jsonBinder; - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { - RouteOptions options = (RouteOptions) checkNotNull(postParams.get("options"), "routeOptions"); - String name = (String) checkNotNull(postParams.get("name"), "name"); - URI network = (URI) checkNotNull(postParams.get("network"), "network"); - options.name(name); - options.network(network); - return bindToRequest(request, options); - } - - /** - * {@inheritDoc} - */ - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object input) { - return jsonBinder.bindToRequest(request, input); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java deleted file mode 100644 index 5ad2846..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java +++ /dev/null @@ -1,128 +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.googlecomputeengine.options; - -import java.net.URI; - -/** - * Options for attaching disks to instances. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/instances/attachDisk"/> - */ -public class AttachDiskOptions { - - public enum DiskType { - SCRATCH, - PERSISTENT - } - - public enum DiskMode { - READ_WRITE, - READ_ONLY - } - - private DiskType type; - private DiskMode mode; - private URI source; - private String deviceName; - private boolean boot; - - /** - * The disk type - * - * @return the disk type. - */ - public DiskType getType() { - return type; - } - - /** - * The disk mode - * - * @return the disk mode - */ - public DiskMode getMode() { - return mode; - } - - /** - * The URI of the source disk - optional, if DiskType.SCRATCH is used. - * - * @return the URI - */ - public URI getSource() { - return source; - } - - /** - * The device name on the instance - optional. - * - * @return the device name - */ - public String getDeviceName() { - return deviceName; - } - - /** - * Indicates that this is a boot disk. VM will use the first partition of the disk for its root filesystem. - * - * @return true if this is a boot disk, false otherwise - */ - public boolean getBoot() { - return boot; - } - - /** - * @see AttachDiskOptions#getType() - */ - public AttachDiskOptions type(DiskType type) { - this.type = type; - return this; - } - - /** - * @see AttachDiskOptions#getMode() - */ - public AttachDiskOptions mode(DiskMode mode) { - this.mode = mode; - return this; - } - - /** - * @see AttachDiskOptions#getSource() - */ - public AttachDiskOptions source(URI source) { - this.source = source; - return this; - } - - /** - * @see AttachDiskOptions#getDeviceName() - */ - public AttachDiskOptions deviceName(String deviceName) { - this.deviceName = deviceName; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.options.AttachDiskOptions#getBoot() - */ - public AttachDiskOptions boot(boolean boot) { - this.boot = boot; - return this; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java deleted file mode 100644 index 382bf71..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java +++ /dev/null @@ -1,126 +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.googlecomputeengine.options; - -import java.net.URI; -import java.util.Date; - -/** - * Options to set the deprecation status of a resource. Currently only for images. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/images/deprecate" /> - */ -public class DeprecateOptions { - - public enum State { - DEPRECATED, - OBSOLETE, - DELETED - } - - private State state; - private URI replacement; - private Date deprecated; - private Date obsolete; - private Date deleted; - - /** - * The new deprecation state. - * - * @return the new deprecation state. - */ - public State getState() { - return state; - } - - /** - * Optional URL for replacement of deprecated resource. - * - * @return the URL - */ - public URI getReplacement() { - return replacement; - } - - /** - * Optional RFC3339 timestamp for when the deprecation state was changed to DEPRECATED. - * - * @return the timestamp - */ - public Date getDeprecated() { - return deprecated; - } - - /** - * Optional RFC3339 timestamp for when the deprecation state was changed to OBSOLETE. - * - * @return the timestamp - */ - public Date getObsolete() { - return obsolete; - } - - /** - * Optional RFC3339 timestamp for when the deprecation state was changed to DELETED. - * - * @return the timestamp - */ - public Date getDeleted() { - return deleted; - } - - /** - * @see DeprecateOptions#getState() - */ - public DeprecateOptions state(State state) { - this.state = state; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.options.DeprecateOptions#getReplacement() - */ - public DeprecateOptions replacement(URI replacement) { - this.replacement = replacement; - return this; - } - - /** - * @see DeprecateOptions#getDeprecated() - */ - public DeprecateOptions deprecated(Date deprecated) { - this.deprecated = deprecated; - return this; - } - - /** - * @see DeprecateOptions#getObsolete() - */ - public DeprecateOptions obsolete(Date obsolete) { - this.obsolete = obsolete; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.options.DeprecateOptions#getDeleted() - */ - public DeprecateOptions deleted(Date deleted) { - this.deleted = deleted; - return this; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java deleted file mode 100644 index d70d4d0..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java +++ /dev/null @@ -1,166 +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.googlecomputeengine.options; - -import java.net.URI; -import java.util.Set; - -import org.jclouds.googlecomputeengine.domain.Firewall; - -import com.google.common.collect.ImmutableSet; - -/** - * Options to create a firewall. - * - * @see Firewall - */ -public class FirewallOptions { - - private String name; - private URI network; - private ImmutableSet.Builder<String> sourceRanges = ImmutableSet.builder(); - private ImmutableSet.Builder<String> sourceTags = ImmutableSet.builder(); - private ImmutableSet.Builder<String> targetTags = ImmutableSet.builder(); - private ImmutableSet.Builder<Firewall.Rule> allowed = ImmutableSet.builder(); - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getAllowed() - */ - public Set<Firewall.Rule> getAllowed() { - return allowed.build(); - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getAllowed() - */ - public FirewallOptions addAllowedRule(Firewall.Rule allowedRule) { - this.allowed.add(allowedRule); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getAllowed() - */ - public FirewallOptions allowedRules(Set<Firewall.Rule> allowedRules) { - this.allowed = ImmutableSet.builder(); - this.allowed.addAll(allowedRules); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getName() - */ - public FirewallOptions name(String name) { - this.name = name; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getName() - */ - public String getName() { - return name; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getNetwork() - */ - public FirewallOptions network(URI network) { - this.network = network; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getNetwork() - */ - public URI getNetwork() { - return network; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceRanges() - */ - public Set<String> getSourceRanges() { - return sourceRanges.build(); - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceRanges() - */ - public FirewallOptions addSourceRange(String sourceRange) { - this.sourceRanges.add(sourceRange); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceRanges() - */ - public FirewallOptions sourceRanges(Set<String> sourceRanges) { - this.sourceRanges = ImmutableSet.builder(); - this.sourceRanges.addAll(sourceRanges); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceTags() - */ - public Set<String> getSourceTags() { - return sourceTags.build(); - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceTags() - */ - public FirewallOptions addSourceTag(String sourceTag) { - this.sourceTags.add(sourceTag); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceTags() - */ - public FirewallOptions sourceTags(Set<String> sourceTags) { - this.sourceTags = ImmutableSet.builder(); - this.sourceTags.addAll(sourceTags); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getTargetTags() - */ - public Set<String> getTargetTags() { - return targetTags.build(); - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getTargetTags() - */ - public FirewallOptions addTargetTag(String targetTag) { - this.targetTags.add(targetTag); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Firewall#getTargetTags() - */ - public FirewallOptions targetTags(Set<String> targetTags) { - this.targetTags = ImmutableSet.builder(); - this.targetTags.addAll(targetTags); - return this; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java deleted file mode 100644 index 9a3e88e..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java +++ /dev/null @@ -1,91 +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.googlecomputeengine.options; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.http.options.BaseHttpRequestOptions; - -/** - * Allows to optionally specify a filter, max results and a page token for <code>listFirstPage()</code> REST methods. - * - * @see <a href="https://developers.google.com/compute/docs/reference/v1/operations/listFirstPage"/> - */ -public class ListOptions extends BaseHttpRequestOptions { - - /** - * Optional. Filter expression for filtering listed resources, in the form filter={expression}. Your {expression} - * must contain the following: - * <p/> - * {@code <field_name> <comparison_string> <literal_string>} - * <ul> - * <li>{@code <field_name>}: The name of the field you want to compare. The field name must be valid for the - * type of resource being filtered. Only atomic field types are supported (string, number, - * boolean). Array and object fields are not currently supported.</li> - * <li>{@code <comparison_string>}: The comparison string, either eq (equals) or ne (not equals).</li> - * <li>{@code <literal_string>}: The literal string value to filter to. The literal value must be valid - * for the type of field (string, number, boolean). For string fields, the literal value is interpreted as a - * regular expression using RE2 syntax. The literal value must match the entire field. For example, - * when filtering instances, name eq my_instance won't work, but name eq .*my_instance will work.</li> - * </ul> - * <p/> - * For example: - * <p/> - * {@code filter=status ne RUNNING} - * <p/> - * The above filter returns only results whose status field does not equal RUNNING. You can also enclose your - * literal string in single, double, or no quotes. For example, all three of the following would be valid - * expressions: - * <p/> - * {@code filter=status ne "RUNNING"}<br/> - * {@code filter=status ne 'RUNNING'}<br/> - * {@code filter=status ne RUNNING}<br/> - * <p/> - * Complex regular expressions can also be used, like the following: - * {@code name eq '."my_instance_[0-9]+'} - */ - public ListOptions filter(String filter) { - this.queryParameters.put("filter", checkNotNull(filter, "filter")); - return this; - } - - /** - * Sets Maximum count of results to be returned. Maximum and default value is 100. Acceptable items are 0 to - * 100, inclusive. (Default: 100) - */ - public ListOptions maxResults(Integer maxResults) { - this.queryParameters.put("maxResults", checkNotNull(maxResults, "maxResults") + ""); - return this; - } - - public static class Builder { - - /** - * @see ListOptions#filter(String) - */ - public ListOptions filter(String filter) { - return new ListOptions().filter(filter); - } - - /** - * @see ListOptions#maxResults(Integer) - */ - public ListOptions maxResults(Integer maxResults) { - return new ListOptions().maxResults(maxResults); - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java deleted file mode 100644 index ec891ce..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java +++ /dev/null @@ -1,202 +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.googlecomputeengine.options; - -import java.net.URI; -import java.util.Set; - -import com.google.common.collect.ImmutableSet; - -/** - * Options to create a route. - * - * @see org.jclouds.googlecomputeengine.domain.Route - */ -public class RouteOptions { - - private String name; - private URI network; - private String destRange; - private URI nextHopInstance; - private String nextHopIp; - private URI nextHopNetwork; - private URI nextHopGateway; - private String description; - private Integer priority; - - private ImmutableSet.Builder<String> tags = ImmutableSet.builder(); - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getName() - */ - public String getName() { - return name; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getName() - */ - public RouteOptions name(String name) { - this.name = name; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getDescription() - */ - public String getDescription() { - return description; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getDescription() - */ - public RouteOptions description(String description) { - this.description = description; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getDestRange() - */ - public String getDestRange() { - return destRange; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getDestRange() - */ - public RouteOptions destRange(String destRange) { - this.destRange = destRange; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopIp() - */ - public String getNextHopIp() { - return nextHopIp; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopIp() - */ - public RouteOptions nextHopIp(String nextHopIp) { - this.nextHopIp = nextHopIp; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getPriority() - */ - public Integer getPriority() { - return priority; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getPriority() - */ - public RouteOptions priority(Integer priority) { - this.priority = priority; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNetwork() - */ - public RouteOptions network(URI network) { - this.network = network; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNetwork() - */ - public URI getNetwork() { - return network; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopInstance() - */ - public RouteOptions nextHopInstance(URI nextHopInstance) { - this.nextHopInstance = nextHopInstance; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopInstance() - */ - public URI getNextHopInstance() { - return nextHopInstance; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopNetwork() - */ - public RouteOptions nextHopNetwork(URI nextHopNetwork) { - this.nextHopNetwork = nextHopNetwork; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopNetwork() - */ - public URI getNextHopNetwork() { - return nextHopNetwork; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopGateway() - */ - public RouteOptions nextHopGateway(URI nextHopGateway) { - this.nextHopGateway = nextHopGateway; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopGateway() - */ - public URI getNextHopGateway() { - return nextHopGateway; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getTags() - */ - public Set<String> getTags() { - return tags.build(); - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getTags() - */ - public RouteOptions addTag(String tag) { - this.tags.add(tag); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.Route#getTags() - */ - public RouteOptions tags(Set<String> tags) { - this.tags = ImmutableSet.builder(); - this.tags.addAll(tags); - return this; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java deleted file mode 100644 index ac34bcc..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java +++ /dev/null @@ -1,59 +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.googlecomputeengine.predicates; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.concurrent.atomic.AtomicReference; - -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.config.UserProject; -import org.jclouds.googlecomputeengine.domain.Operation; - -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.inject.Inject; - -/** - * Tests that a Global Operation is done, returning the completed Operation when it is. - */ -public class GlobalOperationDonePredicate implements Predicate<AtomicReference<Operation>> { - - private final GoogleComputeEngineApi api; - private final Supplier<String> project; - - @Inject - public GlobalOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project) { - this.api = api; - this.project = project; - } - - @Override - public boolean apply(AtomicReference<Operation> input) { - checkNotNull(input, "input"); - Operation current = api.getGlobalOperationApiForProject(project.get()).get(input.get().getName()); - switch (current.getStatus()) { - case DONE: - input.set(current); - return true; - case PENDING: - case RUNNING: - default: - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java deleted file mode 100644 index 8cde680..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java +++ /dev/null @@ -1,33 +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.googlecomputeengine.predicates; - -import org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk; - -import com.google.common.base.Predicate; - -public class InstancePredicates { - - public static Predicate<PersistentDisk> isBootDisk() { - return new Predicate<PersistentDisk>() { - @Override - public boolean apply(PersistentDisk input) { - return input.isBoot(); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java deleted file mode 100644 index 63d2767..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java +++ /dev/null @@ -1,121 +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.googlecomputeengine.predicates; - -import org.jclouds.googlecomputeengine.domain.Firewall; -import org.jclouds.googlecomputeengine.domain.Firewall.Rule; -import org.jclouds.net.domain.IpPermission; -import org.jclouds.net.domain.IpProtocol; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Range; -import com.google.common.collect.Sets; - -public class NetworkFirewallPredicates { - - public static Predicate<Firewall> hasProtocol(final IpProtocol protocol) { - return new Predicate<Firewall>() { - - @Override - public boolean apply(Firewall fw) { - for (Rule rule : fw.getAllowed()) { - if (rule.getIpProtocol().equals(protocol)) { - return true; - } - } - - return false; - } - }; - } - - public static Predicate<Firewall> hasPortRange(final Range<Integer> portRange) { - return new Predicate<Firewall>() { - - @Override - public boolean apply(Firewall fw) { - return Iterables.any(fw.getAllowed(), new Predicate<Rule>() { - @Override - public boolean apply(Rule input) { - return input.getPorts().encloses(portRange); - } - }); - } - }; - } - - public static Predicate<Firewall> hasSourceTag(final String sourceTag) { - return new Predicate<Firewall>() { - @Override - public boolean apply(Firewall input) { - return input.getSourceTags() != null && input.getSourceTags().contains(sourceTag); - } - }; - } - - public static Predicate<Firewall> hasSourceRange(final String sourceRange) { - return new Predicate<Firewall>() { - @Override - public boolean apply(Firewall input) { - return input.getSourceRanges() != null && input.getSourceRanges().contains(sourceRange); - } - }; - } - - public static Predicate<Firewall> equalsIpPermission(final IpPermission permission) { - return new Predicate<Firewall>() { - @Override - public boolean apply(Firewall input) { - return Iterables.elementsEqual(permission.getGroupIds(), input.getSourceTags()) - && Iterables.elementsEqual(permission.getCidrBlocks(), input.getSourceRanges()) - && (input.getAllowed().size() == 1 - && ruleEqualsIpPermission(permission).apply(Iterables.getOnlyElement(input.getAllowed()))); - } - }; - } - - public static Predicate<Firewall> providesIpPermission(final IpPermission permission) { - return new Predicate<Firewall>() { - @Override - public boolean apply(Firewall input) { - boolean groupsMatchTags = (permission.getGroupIds().isEmpty() && input.getSourceTags().isEmpty()) - || !Sets.intersection(permission.getGroupIds(), input.getSourceTags()).isEmpty(); - boolean cidrsMatchRanges = (permission.getCidrBlocks().isEmpty() && input.getSourceRanges().isEmpty()) - || !Sets.intersection(permission.getCidrBlocks(), input.getSourceRanges()).isEmpty(); - boolean firewallHasPorts = hasProtocol(permission.getIpProtocol()).apply(input) - && ((permission.getFromPort() == 0 && permission.getToPort() == 0) - || hasPortRange(Range.closed(permission.getFromPort(), permission.getToPort())).apply(input)); - - return groupsMatchTags && cidrsMatchRanges && firewallHasPorts; - } - }; - } - - private static Predicate<Firewall.Rule> ruleEqualsIpPermission(final IpPermission permission) { - return new Predicate<Rule>() { - @Override - public boolean apply(Firewall.Rule input) { - return permission.getIpProtocol().equals(input.getIpProtocol()) - && ((input.getPorts().isEmpty() && permission.getFromPort() == 0 && permission.getToPort() == 0) - || (input.getPorts().asRanges().size() == 1 - && permission.getFromPort() == Iterables.getOnlyElement(input.getPorts().asRanges()).lowerEndpoint() - && permission.getToPort() == Iterables.getOnlyElement(input.getPorts().asRanges()).upperEndpoint())); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java deleted file mode 100644 index 1f3dee6..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java +++ /dev/null @@ -1,69 +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.googlecomputeengine.predicates; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; - -import org.jclouds.collect.Memoized; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.config.UserProject; -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.domain.Region; - -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.inject.Inject; - -/** - * Tests that a Global Operation is done, returning the completed Operation when it is. - */ -public class RegionOperationDonePredicate implements Predicate<AtomicReference<Operation>> { - - private final GoogleComputeEngineApi api; - private final Supplier<String> project; - private final Supplier<Map<URI, Region>> regions; - - @Inject - RegionOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project, - @Memoized Supplier<Map<URI, Region>> regions) { - this.api = api; - this.project = project; - this.regions = regions; - } - - @Override - public boolean apply(AtomicReference<Operation> input) { - checkNotNull(input, "input"); - - Operation current = api.getRegionOperationApiForProject(project.get()) - .getInRegion(regions.get().get(input.get().getRegion().get()).getName(), - input.get().getName()); - switch (current.getStatus()) { - case DONE: - input.set(current); - return true; - case PENDING: - case RUNNING: - default: - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java deleted file mode 100644 index c63c6f3..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java +++ /dev/null @@ -1,68 +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.googlecomputeengine.predicates; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; - -import org.jclouds.collect.Memoized; -import org.jclouds.domain.Location; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.config.UserProject; -import org.jclouds.googlecomputeengine.domain.Operation; - -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.inject.Inject; - -/** - * Tests that a Zone Operation is done, returning the completed Operation when it is. - */ -public class ZoneOperationDonePredicate implements Predicate<AtomicReference<Operation>> { - - private final GoogleComputeEngineApi api; - private final Supplier<String> project; - private final Supplier<Map<URI, ? extends Location>> zones; - - @Inject - ZoneOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project, - @Memoized Supplier<Map<URI, ? extends Location>> zones) { - this.api = api; - this.project = project; - this.zones = zones; - } - - @Override - public boolean apply(AtomicReference<Operation> input) { - checkNotNull(input, "input"); - Operation current = api.getZoneOperationApiForProject(project.get()) - .getInZone(zones.get().get(input.get().getZone().get()).getId(), - input.get().getName()); - switch (current.getStatus()) { - case DONE: - input.set(current); - return true; - case PENDING: - case RUNNING: - default: - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApi.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApi.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApi.java deleted file mode 100644 index 1b20734..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApi.java +++ /dev/null @@ -1,61 +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.oauth.v2; - -import java.io.Closeable; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.core.MediaType; - -import org.jclouds.oauth.v2.config.Authentication; -import org.jclouds.oauth.v2.domain.Token; -import org.jclouds.oauth.v2.domain.TokenRequest; -import org.jclouds.oauth.v2.handlers.OAuthTokenBinder; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Endpoint; - -/** - * Provides access to OAuth via REST api. - * <p/> - * Usually this is not directly used by a client, which instead specifies - * OAuthAuthenticator as a request filter, which in turn uses this class to - * perform token requests. - */ -@Endpoint(Authentication.class) -public interface OAuthApi extends Closeable { - - /** - * Authenticates/Authorizes access to a resource defined in TokenRequest - * against an OAuth v2 authentication/authorization server. - * - * @param tokenRequest - * specified the principal and the required permissions - * @return a Token object with the token required to access the resource - * along with its expiration time - * @throws AuthorizationException - * if the principal cannot be authenticated or has no permissions - * for the specifed resources. - */ - @Named("authenticate") - @POST - @Consumes(MediaType.APPLICATION_JSON) - Token authenticate(@BinderParam(OAuthTokenBinder.class) TokenRequest tokenRequest) throws AuthorizationException; - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApiMetadata.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApiMetadata.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApiMetadata.java deleted file mode 100644 index 3ef26e6..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthApiMetadata.java +++ /dev/null @@ -1,80 +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.oauth.v2; - -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.oauth.v2.config.OAuthProperties.SIGNATURE_OR_MAC_ALGORITHM; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.oauth.v2.config.OAuthHttpApiModule; -import org.jclouds.oauth.v2.config.OAuthModule; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Implementation of {@link ApiMetadata} for OAuth 2 API - */ -public class OAuthApiMetadata extends BaseHttpApiMetadata<OAuthApi> { - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public OAuthApiMetadata() { - this(new Builder()); - } - - protected OAuthApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = BaseHttpApiMetadata.defaultProperties(); - properties.put(SIGNATURE_OR_MAC_ALGORITHM, "RS256"); - properties.put(PROPERTY_SESSION_INTERVAL, 3600); - return properties; - } - - public static class Builder extends BaseHttpApiMetadata.Builder<OAuthApi, Builder> { - - protected Builder() { - id("oauth") - .name("OAuth API") - .identityName("service_account") - .credentialName("service_key") - .documentation(URI.create("TODO")) - .version("2") - .defaultProperties(OAuthApiMetadata.defaultProperties()) - .defaultModules(ImmutableSet.<Class<? extends Module>>of(OAuthModule.class, OAuthHttpApiModule.class)); - } - - @Override - public OAuthApiMetadata build() { - return new OAuthApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthConstants.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthConstants.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthConstants.java deleted file mode 100644 index 9b140d4..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/OAuthConstants.java +++ /dev/null @@ -1,78 +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.oauth.v2; - -import com.google.common.collect.ImmutableMap; - -import java.util.Map; - -/** - * The constants for OAuth \ - */ -public final class OAuthConstants { - - /** - * Selected algorithm when a signature or mac isn't required. - */ - public static final String NO_ALGORITHM = "none"; - - /** - * Static mapping between the oauth algorithm name and the Crypto provider signature algorithm name. - * - * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-06#section-3.1">doc</a> - * @see org.jclouds.oauth.v2.json.JWTTokenRequestFormat - */ - public static final Map<String, String> OAUTH_ALGORITHM_NAMES_TO_SIGNATURE_ALGORITHM_NAMES = ImmutableMap - .<String, String>builder() - .put("RS256", "SHA256withRSA") - .put("RS384", "SHA384withRSA") - .put("RS512", "SHA512withRSA") - .put("HS256", "HmacSHA256") - .put("HS384", "HmacSHA384") - .put("HS512", "HmacSHA512") - .put("ES256", "SHA256withECDSA") - .put("ES384", "SHA384withECDSA") - .put("ES512", "SHA512withECDSA") - .put(NO_ALGORITHM, NO_ALGORITHM).build(); - - /** - * Static mapping between the oauth algorithm name and the Crypto provider KeyFactory algorithm name. - * - * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-06#section-3.1">doc</a> - */ - public static final Map<String, String> OAUTH_ALGORITHM_NAMES_TO_KEYFACTORY_ALGORITHM_NAMES = ImmutableMap - .<String, String>builder() - .put("RS256", "RSA") - .put("RS384", "RSA") - .put("RS512", "RSA") - .put("HS256", "DiffieHellman") - .put("HS384", "DiffieHellman") - .put("HS512", "DiffieHellman") - .put("ES256", "EC") - .put("ES384", "EC") - .put("ES512", "EC") - .put(NO_ALGORITHM, NO_ALGORITHM).build(); - - /** - * The (optional) set of additional claims to use, provided in Map<String,String> form - */ - public static final String ADDITIONAL_CLAIMS = "jclouds.oauth.additional-claims"; - - private OAuthConstants() { - throw new AssertionError("intentionally unimplemented"); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/Authentication.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/Authentication.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/Authentication.java deleted file mode 100644 index 24f6851..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/Authentication.java +++ /dev/null @@ -1,35 +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.oauth.v2.config; - - -import javax.inject.Qualifier; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Qualifies OAuth related resources, such as Endpoint. - * - * @see org.jclouds.oauth.v2.OAuthApi - */ -@Retention(value = RetentionPolicy.RUNTIME) -@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) -@Qualifier -public @interface Authentication { -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/CredentialType.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/CredentialType.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/CredentialType.java deleted file mode 100644 index 24a658b..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/CredentialType.java +++ /dev/null @@ -1,42 +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.oauth.v2.config; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.CaseFormat; - -/** - * Decides what type of credentials createContext is supplied with. - */ -public enum CredentialType { - - BEARER_TOKEN_CREDENTIALS, - - SERVICE_ACCOUNT_CREDENTIALS; - - @Override - public String toString() { - return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()); - } - - public static CredentialType fromValue(String credentialType) { - return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(credentialType, - "credentialType"))); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthAuthenticationModule.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthAuthenticationModule.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthAuthenticationModule.java deleted file mode 100644 index fb2d413..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthAuthenticationModule.java +++ /dev/null @@ -1,52 +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.oauth.v2.config; - -import static org.jclouds.rest.config.BinderUtils.bindHttpApi; - -import java.net.URI; - -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.oauth.v2.OAuthApi; - -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; - -/** - * An OAuth module to be used form other providers. - */ -public class OAuthAuthenticationModule extends AbstractModule { - - @Override - protected void configure() { - bindHttpApi(binder(), OAuthApi.class); - } - - /** - * When oauth is used as a module the oauth endpoint is a normal property - */ - @Provides - @Singleton - @Authentication - protected Supplier<URI> provideAuthenticationEndpoint(@Named("oauth.endpoint") String endpoint) { - return Suppliers.ofInstance(URI.create(endpoint)); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthHttpApiModule.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthHttpApiModule.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthHttpApiModule.java deleted file mode 100644 index 6b4fdf9..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthHttpApiModule.java +++ /dev/null @@ -1,45 +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.oauth.v2.config; - -import java.net.URI; - -import javax.inject.Singleton; - -import org.jclouds.oauth.v2.OAuthApi; -import org.jclouds.providers.ProviderMetadata; -import org.jclouds.rest.ConfiguresHttpApi; -import org.jclouds.rest.config.HttpApiModule; - -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.inject.Provides; - -/** - * OAuth module to when accessing OAuth stand-alone. - */ -@ConfiguresHttpApi -public class OAuthHttpApiModule extends HttpApiModule<OAuthApi> { - - @Provides - @Singleton - @Authentication - protected Supplier<URI> provideAuthenticationEndpoint(ProviderMetadata providerMetadata) { - return Suppliers.ofInstance(URI.create(providerMetadata.getEndpoint())); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/295c545c/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java deleted file mode 100644 index 1041c07..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java +++ /dev/null @@ -1,119 +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.oauth.v2.config; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableMap; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Named; -import org.jclouds.oauth.v2.domain.ClaimSet; -import org.jclouds.oauth.v2.domain.Header; -import org.jclouds.oauth.v2.domain.OAuthCredentials; -import org.jclouds.oauth.v2.domain.Token; -import org.jclouds.oauth.v2.domain.TokenRequest; -import org.jclouds.oauth.v2.filters.BearerTokenAuthenticator; -import org.jclouds.oauth.v2.filters.OAuthAuthenticationFilter; -import org.jclouds.oauth.v2.filters.OAuthAuthenticator; -import org.jclouds.oauth.v2.functions.BuildTokenRequest; -import org.jclouds.oauth.v2.functions.FetchToken; -import org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier; -import org.jclouds.oauth.v2.functions.SignOrProduceMacForToken; -import org.jclouds.oauth.v2.json.ClaimSetTypeAdapter; -import org.jclouds.oauth.v2.json.HeaderTypeAdapter; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import java.lang.reflect.Type; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; - -/** - * Base OAuth module - */ -public class OAuthModule extends AbstractModule { - - - @Override - protected void configure() { - bind(new TypeLiteral<Function<byte[], byte[]>>() {}).to(SignOrProduceMacForToken.class); - bind(new TypeLiteral<Map<Type, Object>>() {}).toInstance(ImmutableMap.<Type, Object>of( - Header.class, new HeaderTypeAdapter(), - ClaimSet.class, new ClaimSetTypeAdapter())); - bind(CredentialType.class).toProvider(CredentialTypeFromPropertyOrDefault.class); - bind(new TypeLiteral<Supplier<OAuthCredentials>>() {}).to(OAuthCredentialsSupplier.class); - bind(new TypeLiteral<Function<GeneratedHttpRequest, TokenRequest>>() {}).to(BuildTokenRequest.class); - bind(new TypeLiteral<Function<TokenRequest, Token>>() {}).to(FetchToken.class); - } - - /** - * Provides a cache for tokens. Cache is time based and by default expires after 59 minutes - * (the maximum time a token is valid is 60 minutes). - * This cache and expiry period is system-wide and does not attend to per-instance expiry time - * (e.g. "expires_in" from Google Compute -- which is set to the standard 3600 seconds). - */ - // NB: If per-instance expiry time is required, significant refactoring will be needed. - @Provides - @Singleton - public LoadingCache<TokenRequest, Token> provideAccessCache(Function<TokenRequest, Token> getAccess, - @Named(PROPERTY_SESSION_INTERVAL) long - sessionIntervalInSeconds) { - // since the session interval is also the token expiration time requested to the server make the token expire a - // bit before the deadline to make sure there aren't session expiration exceptions - sessionIntervalInSeconds = sessionIntervalInSeconds > 30 ? sessionIntervalInSeconds - 30 : - sessionIntervalInSeconds; - return CacheBuilder.newBuilder().expireAfterWrite(sessionIntervalInSeconds, TimeUnit.SECONDS).build(CacheLoader - .from(getAccess)); - } - - @Singleton - public static class CredentialTypeFromPropertyOrDefault implements Provider<CredentialType> { - @Inject(optional = true) - @Named(OAuthProperties.CREDENTIAL_TYPE) - String credentialType = CredentialType.SERVICE_ACCOUNT_CREDENTIALS.toString(); - - @Override - public CredentialType get() { - return CredentialType.fromValue(credentialType); - } - } - - @Provides - @Singleton - protected OAuthAuthenticationFilter authenticationFilterForCredentialType(CredentialType credentialType, - OAuthAuthenticator serviceAccountAuth, - BearerTokenAuthenticator bearerTokenAuth) { - switch (credentialType) { - case SERVICE_ACCOUNT_CREDENTIALS: - return serviceAccountAuth; - case BEARER_TOKEN_CREDENTIALS: - return bearerTokenAuth; - default: - throw new IllegalArgumentException("Unsupported credential type: " + credentialType); - } - } - -}
