diff --git a/sdk/imds/azure-imds-imds/CHANGELOG.md b/sdk/imds/azure-imds-imds/CHANGELOG.md new file mode 100644 index 000000000000..b3f9d62cdc1c --- /dev/null +++ b/sdk/imds/azure-imds-imds/CHANGELOG.md @@ -0,0 +1,13 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + +- Azure InstanceMetadataClient client library for Java. This package contains Microsoft Azure InstanceMetadataClient client library. + +### Features Added + +### Breaking Changes + +### Bugs Fixed + +### Other Changes diff --git a/sdk/imds/azure-imds-imds/README.md b/sdk/imds/azure-imds-imds/README.md new file mode 100644 index 000000000000..586078957872 --- /dev/null +++ b/sdk/imds/azure-imds-imds/README.md @@ -0,0 +1,63 @@ +# Azure InstanceMetadataClient client library for Java + +Azure InstanceMetadataClient client library for Java. + +This package contains Microsoft Azure InstanceMetadataClient client library. + +## Documentation + +Various documentation is available to help you get started + +- [API reference documentation][docs] +- [Product documentation][product_documentation] + +## Getting started + +### Prerequisites + +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] + +### Adding the package to your product + +[//]: # ({x-version-update-start;com.azure:azure-imds-imds;current}) +```xml + + com.azure + azure-imds-imds + 1.0.0-beta.1 + +``` +[//]: # ({x-version-update-end}) + +### Authentication + +[Azure Identity][azure_identity] package provides the default implementation for authenticating the client. + +## Key concepts + +## Examples + +```java com.azure.imds.imds.readme +``` + +## Troubleshooting + +## Next steps + +## Contributing + +For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md). + +1. Fork it +1. Create your feature branch (`git checkout -b my-new-feature`) +1. Commit your changes (`git commit -am 'Add some feature'`) +1. Push to the branch (`git push origin my-new-feature`) +1. Create new Pull Request + + +[product_documentation]: https://azure.microsoft.com/services/ +[docs]: https://azure.github.io/azure-sdk-for-java/ +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity diff --git a/sdk/imds/azure-imds-imds/pom.xml b/sdk/imds/azure-imds-imds/pom.xml new file mode 100644 index 000000000000..db003ac95ec4 --- /dev/null +++ b/sdk/imds/azure-imds-imds/pom.xml @@ -0,0 +1,73 @@ + + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure + azure-imds-imds + 1.0.0-beta.1 + jar + + Microsoft Azure SDK for InstanceMetadataClient Management + This package contains Microsoft Azure InstanceMetadataClient client library. + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + microsoft + Microsoft + + + + UTF-8 + true + + + + com.azure + azure-core + 1.25.0 + + + com.azure + azure-core-http-netty + 1.11.7 + + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + test + + + com.azure + azure-core-test + 1.7.8 + test + + + com.azure + azure-identity + 1.4.4 + test + + + diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedAsyncClient.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedAsyncClient.java new file mode 100644 index 000000000000..0497c394b7da --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedAsyncClient.java @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.implementation.AttestedsImpl; +import reactor.core.publisher.Mono; + +/** Initializes a new instance of the asynchronous InstanceMetadataClient type. */ +@ServiceClient(builder = AttestedClientBuilder.class, isAsync = true) +public final class AttestedAsyncClient { + @Generated private final AttestedsImpl serviceClient; + + /** + * Initializes an instance of Attesteds client. + * + * @param serviceClient the service client implementation. + */ + @Generated + AttestedAsyncClient(AttestedsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Get Attested Data for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
nonceStringNoThis is a string of up to 32 random alphanumeric characters.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     signature: String
+     *     encoding: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return attested Data for the Virtual Machine along with {@link Response} on successful completion of {@link + * Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getDocumentWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getDocumentWithResponseAsync(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedClient.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedClient.java new file mode 100644 index 000000000000..74da783945e5 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedClient.java @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.implementation.AttestedsImpl; + +/** Initializes a new instance of the synchronous InstanceMetadataClient type. */ +@ServiceClient(builder = AttestedClientBuilder.class) +public final class AttestedClient { + @Generated private final AttestedsImpl serviceClient; + + /** + * Initializes an instance of Attesteds client. + * + * @param serviceClient the service client implementation. + */ + @Generated + AttestedClient(AttestedsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Get Attested Data for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
nonceStringNoThis is a string of up to 32 random alphanumeric characters.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     signature: String
+     *     encoding: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return attested Data for the Virtual Machine along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getDocumentWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getDocumentWithResponse(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedClientBuilder.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedClientBuilder.java new file mode 100644 index 000000000000..f6dca2a9a564 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/AttestedClientBuilder.java @@ -0,0 +1,287 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.imds.imds.implementation.InstanceMetadataClientImpl; +import com.azure.imds.imds.models.HostOptions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** A builder for creating a new instance of the AttestedClient type. */ +@ServiceClientBuilder(serviceClients = {AttestedClient.class, AttestedAsyncClient.class}) +public final class AttestedClientBuilder { + @Generated private static final String SDK_NAME = "name"; + + @Generated private static final String SDK_VERSION = "version"; + + @Generated private final Map properties = CoreUtils.getProperties("azure-imds-imds.properties"); + + /** Create an instance of the AttestedClientBuilder. */ + @Generated + public AttestedClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * server parameter + */ + @Generated private HostOptions host; + + /** + * Sets server parameter. + * + * @param host the host value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder host(HostOptions host) { + this.host = host; + return this; + } + + /* + * Service version + */ + @Generated private InstanceMetadataServiceVersion serviceVersion; + + /** + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder serviceVersion(InstanceMetadataServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + @Generated private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The HTTP client used to send the request. + */ + @Generated private HttpClient httpClient; + + /** + * Sets The HTTP client used to send the request. + * + * @param httpClient the httpClient value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The configuration store that is used during construction of the service + * client. + */ + @Generated private Configuration configuration; + + /** + * Sets The configuration store that is used during construction of the service client. + * + * @param configuration the configuration value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated private HttpLogOptions httpLogOptions; + + /** + * Sets The logging configuration for HTTP requests and responses. + * + * @param httpLogOptions the httpLogOptions value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if + * applicable. + */ + @Generated private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /* + * The list of Http pipeline policies to add. + */ + @Generated private final List pipelinePolicies; + + /* + * The client options such as application ID and custom headers to set on a + * request. + */ + @Generated private ClientOptions clientOptions; + + /** + * Sets The client options such as application ID and custom headers to set on a request. + * + * @param clientOptions the clientOptions value. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /** + * Adds a custom Http pipeline policy. + * + * @param customPolicy The custom Http pipeline policy to add. + * @return the AttestedClientBuilder. + */ + @Generated + public AttestedClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + pipelinePolicies.add(customPolicy); + return this; + } + + /** + * Builds an instance of InstanceMetadataClientImpl with the provided parameters. + * + * @return an instance of InstanceMetadataClientImpl. + */ + @Generated + private InstanceMetadataClientImpl buildInnerClient() { + if (host == null) { + this.host = HostOptions.HTTP169_254_169_254_METADATA; + } + if (serviceVersion == null) { + this.serviceVersion = InstanceMetadataServiceVersion.getLatest(); + } + if (pipeline == null) { + this.pipeline = createHttpPipeline(); + } + InstanceMetadataClientImpl client = + new InstanceMetadataClientImpl( + pipeline, JacksonAdapter.createDefaultSerializerAdapter(), host, serviceVersion); + return client; + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration = + (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + if (httpLogOptions == null) { + httpLogOptions = new HttpLogOptions(); + } + if (clientOptions == null) { + clientOptions = new ClientOptions(); + } + List policies = new ArrayList<>(); + String clientName = properties.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + HttpHeaders headers = new HttpHeaders(); + clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); + if (headers.getSize() > 0) { + policies.add(new AddHeadersPolicy(headers)); + } + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); + policies.add(new CookiePolicy()); + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = + new HttpPipelineBuilder() + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(clientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of AttestedAsyncClient async client. + * + * @return an instance of AttestedAsyncClient. + */ + @Generated + public AttestedAsyncClient buildAsyncClient() { + return new AttestedAsyncClient(buildInnerClient().getAttesteds()); + } + + /** + * Builds an instance of AttestedClient sync client. + * + * @return an instance of AttestedClient. + */ + @Generated + public AttestedClient buildClient() { + return new AttestedClient(buildInnerClient().getAttesteds()); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityAsyncClient.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityAsyncClient.java new file mode 100644 index 000000000000..b3fc44f415bd --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityAsyncClient.java @@ -0,0 +1,121 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.implementation.IdentitiesImpl; +import reactor.core.publisher.Mono; + +/** Initializes a new instance of the asynchronous InstanceMetadataClient type. */ +@ServiceClient(builder = IdentityClientBuilder.class, isAsync = true) +public final class IdentityAsyncClient { + @Generated private final IdentitiesImpl serviceClient; + + /** + * Initializes an instance of Identities client. + * + * @param serviceClient the service client implementation. + */ + @Generated + IdentityAsyncClient(IdentitiesImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Get a Token from Azure AD. + * + *

Query Parameters + * + * + * + * + * + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
resourceStringYesThis is the urlencoded identifier URI of the sink resource for the requested Azure AD token. The resulting token contains the corresponding aud for this resource.
api-versionStringYesApi Version
client_idStringNoThis identifies, by Azure AD client id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with object_id and msi_res_id.
object_idStringNoThis identifies, by Azure AD object id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and msi_res_id.
msi_res_idStringNoThis identifies, by urlencoded ARM resource id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and object_id.
authorityStringNoThis indicates the authority to request AAD tokens from. Defaults to the known authority of the identity to be used.
bypass_cacheStringNoIf provided, the value must be 'true'. This indicates to the server that the token must be retrieved from Azure AD and cannot be retrieved from an internal cache.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     accessToken: String
+     *     expiresIn: String
+     *     expiresOn: String
+     *     extExpiresIn: String
+     *     notBefore: String
+     *     resource: String
+     *     tokenType: String
+     *     clientId: String
+     *     objectId: String
+     *     msiResId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return a Token from Azure AD along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getTokenWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getTokenWithResponseAsync(requestOptions); + } + + /** + * Get information about AAD Metadata. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     tenantId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return information about AAD Metadata along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getInfoWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getInfoWithResponseAsync(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityClient.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityClient.java new file mode 100644 index 000000000000..be778af30500 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityClient.java @@ -0,0 +1,120 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.implementation.IdentitiesImpl; + +/** Initializes a new instance of the synchronous InstanceMetadataClient type. */ +@ServiceClient(builder = IdentityClientBuilder.class) +public final class IdentityClient { + @Generated private final IdentitiesImpl serviceClient; + + /** + * Initializes an instance of Identities client. + * + * @param serviceClient the service client implementation. + */ + @Generated + IdentityClient(IdentitiesImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Get a Token from Azure AD. + * + *

Query Parameters + * + * + * + * + * + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
resourceStringYesThis is the urlencoded identifier URI of the sink resource for the requested Azure AD token. The resulting token contains the corresponding aud for this resource.
api-versionStringYesApi Version
client_idStringNoThis identifies, by Azure AD client id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with object_id and msi_res_id.
object_idStringNoThis identifies, by Azure AD object id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and msi_res_id.
msi_res_idStringNoThis identifies, by urlencoded ARM resource id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and object_id.
authorityStringNoThis indicates the authority to request AAD tokens from. Defaults to the known authority of the identity to be used.
bypass_cacheStringNoIf provided, the value must be 'true'. This indicates to the server that the token must be retrieved from Azure AD and cannot be retrieved from an internal cache.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     accessToken: String
+     *     expiresIn: String
+     *     expiresOn: String
+     *     extExpiresIn: String
+     *     notBefore: String
+     *     resource: String
+     *     tokenType: String
+     *     clientId: String
+     *     objectId: String
+     *     msiResId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return a Token from Azure AD along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getTokenWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getTokenWithResponse(requestOptions); + } + + /** + * Get information about AAD Metadata. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     tenantId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return information about AAD Metadata along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getInfoWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getInfoWithResponse(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityClientBuilder.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityClientBuilder.java new file mode 100644 index 000000000000..b98f56889605 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/IdentityClientBuilder.java @@ -0,0 +1,287 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.imds.imds.implementation.InstanceMetadataClientImpl; +import com.azure.imds.imds.models.HostOptions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** A builder for creating a new instance of the IdentityClient type. */ +@ServiceClientBuilder(serviceClients = {IdentityClient.class, IdentityAsyncClient.class}) +public final class IdentityClientBuilder { + @Generated private static final String SDK_NAME = "name"; + + @Generated private static final String SDK_VERSION = "version"; + + @Generated private final Map properties = CoreUtils.getProperties("azure-imds-imds.properties"); + + /** Create an instance of the IdentityClientBuilder. */ + @Generated + public IdentityClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * server parameter + */ + @Generated private HostOptions host; + + /** + * Sets server parameter. + * + * @param host the host value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder host(HostOptions host) { + this.host = host; + return this; + } + + /* + * Service version + */ + @Generated private InstanceMetadataServiceVersion serviceVersion; + + /** + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder serviceVersion(InstanceMetadataServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + @Generated private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The HTTP client used to send the request. + */ + @Generated private HttpClient httpClient; + + /** + * Sets The HTTP client used to send the request. + * + * @param httpClient the httpClient value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The configuration store that is used during construction of the service + * client. + */ + @Generated private Configuration configuration; + + /** + * Sets The configuration store that is used during construction of the service client. + * + * @param configuration the configuration value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated private HttpLogOptions httpLogOptions; + + /** + * Sets The logging configuration for HTTP requests and responses. + * + * @param httpLogOptions the httpLogOptions value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if + * applicable. + */ + @Generated private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /* + * The list of Http pipeline policies to add. + */ + @Generated private final List pipelinePolicies; + + /* + * The client options such as application ID and custom headers to set on a + * request. + */ + @Generated private ClientOptions clientOptions; + + /** + * Sets The client options such as application ID and custom headers to set on a request. + * + * @param clientOptions the clientOptions value. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /** + * Adds a custom Http pipeline policy. + * + * @param customPolicy The custom Http pipeline policy to add. + * @return the IdentityClientBuilder. + */ + @Generated + public IdentityClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + pipelinePolicies.add(customPolicy); + return this; + } + + /** + * Builds an instance of InstanceMetadataClientImpl with the provided parameters. + * + * @return an instance of InstanceMetadataClientImpl. + */ + @Generated + private InstanceMetadataClientImpl buildInnerClient() { + if (host == null) { + this.host = HostOptions.HTTP169_254_169_254_METADATA; + } + if (serviceVersion == null) { + this.serviceVersion = InstanceMetadataServiceVersion.getLatest(); + } + if (pipeline == null) { + this.pipeline = createHttpPipeline(); + } + InstanceMetadataClientImpl client = + new InstanceMetadataClientImpl( + pipeline, JacksonAdapter.createDefaultSerializerAdapter(), host, serviceVersion); + return client; + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration = + (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + if (httpLogOptions == null) { + httpLogOptions = new HttpLogOptions(); + } + if (clientOptions == null) { + clientOptions = new ClientOptions(); + } + List policies = new ArrayList<>(); + String clientName = properties.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + HttpHeaders headers = new HttpHeaders(); + clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); + if (headers.getSize() > 0) { + policies.add(new AddHeadersPolicy(headers)); + } + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); + policies.add(new CookiePolicy()); + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = + new HttpPipelineBuilder() + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(clientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of IdentityAsyncClient async client. + * + * @return an instance of IdentityAsyncClient. + */ + @Generated + public IdentityAsyncClient buildAsyncClient() { + return new IdentityAsyncClient(buildInnerClient().getIdentities()); + } + + /** + * Builds an instance of IdentityClient sync client. + * + * @return an instance of IdentityClient. + */ + @Generated + public IdentityClient buildClient() { + return new IdentityClient(buildInnerClient().getIdentities()); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstanceMetadataServiceVersion.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstanceMetadataServiceVersion.java new file mode 100644 index 000000000000..57d2a8dece15 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstanceMetadataServiceVersion.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.util.ServiceVersion; + +/** Service version of InstanceMetadataClient. */ +public enum InstanceMetadataServiceVersion implements ServiceVersion { + /** Enum value 2021-10-01. */ + V2021_10_01("2021-10-01"); + + private final String version; + + InstanceMetadataServiceVersion(String version) { + this.version = version; + } + + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link InstanceMetadataServiceVersion}. + */ + public static InstanceMetadataServiceVersion getLatest() { + return V2021_10_01; + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesAsyncClient.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesAsyncClient.java new file mode 100644 index 000000000000..c20a06bd4a2a --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesAsyncClient.java @@ -0,0 +1,212 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.implementation.InstancesImpl; +import reactor.core.publisher.Mono; + +/** Initializes a new instance of the asynchronous InstanceMetadataClient type. */ +@ServiceClient(builder = InstancesClientBuilder.class, isAsync = true) +public final class InstancesAsyncClient { + @Generated private final InstancesImpl serviceClient; + + /** + * Initializes an instance of Instances client. + * + * @param serviceClient the service client implementation. + */ + @Generated + InstancesAsyncClient(InstancesImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Get Instance Metadata for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     compute: {
+     *         azEnvironment: String
+     *         evictionPolicy: String
+     *         extendedLocation: {
+     *             type: String
+     *             name: String
+     *         }
+     *         isHostCompatibilityLayerVm: String
+     *         licenseType: String
+     *         location: String
+     *         name: String
+     *         offer: String
+     *         osProfile: {
+     *             adminUsername: String
+     *             computerName: String
+     *             disablePasswordAuthentication: String
+     *         }
+     *         osType: String
+     *         placementGroupId: String
+     *         plan: {
+     *             name: String
+     *             publisher: String
+     *             product: String
+     *         }
+     *         publicKeys: [
+     *             {
+     *                 path: String
+     *                 keyData: String
+     *             }
+     *         ]
+     *         platformFaultDomain: String
+     *         platformSubFaultDomain: String
+     *         platformUpdateDomain: String
+     *         priority: String
+     *         provider: String
+     *         publisher: String
+     *         resourceGroupName: String
+     *         resourceId: String
+     *         securityProfile: {
+     *             secureBootEnabled: String
+     *             virtualTpmEnabled: String
+     *         }
+     *         sku: String
+     *         storageProfile: {
+     *             imageReference: {
+     *                 id: String
+     *                 offer: String
+     *                 publisher: String
+     *                 sku: String
+     *                 version: String
+     *             }
+     *             osDisk: {
+     *                 caching: String
+     *                 createOption: String
+     *                 diffDiskSettings: {
+     *                     option: String
+     *                 }
+     *                 diskSizeGB: String
+     *                 encryptionSettings: {
+     *                     enabled: String
+     *                 }
+     *                 image: {
+     *                     uri: String
+     *                 }
+     *                 managedDisk: {
+     *                     id: String
+     *                     storageAccountType: String
+     *                 }
+     *                 name: String
+     *                 osType: String
+     *                 vhd: {
+     *                     uri: String
+     *                 }
+     *                 writeAcceleratorEnabled: String
+     *             }
+     *             dataDisks: [
+     *                 {
+     *                     bytesPerSecondThrottle: String
+     *                     caching: String
+     *                     createOption: String
+     *                     diskCapacityBytes: String
+     *                     diskSizeGB: String
+     *                     image: (recursive schema, see image above)
+     *                     isSharedDisk: String
+     *                     isUltraDisk: String
+     *                     lun: String
+     *                     managedDisk: (recursive schema, see managedDisk above)
+     *                     name: String
+     *                     opsPerSecondThrottle: String
+     *                     vhd: (recursive schema, see vhd above)
+     *                     writeAcceleratorEnabled: String
+     *                 }
+     *             ]
+     *             resourceDisk: {
+     *                 size: String
+     *             }
+     *         }
+     *         subscriptionId: String
+     *         tags: String
+     *         tagsList: [
+     *             {
+     *                 name: String
+     *                 value: String
+     *             }
+     *         ]
+     *         userData: String
+     *         version: String
+     *         virtualMachineScaleSet: {
+     *             id: String
+     *         }
+     *         vmId: String
+     *         vmScaleSetName: String
+     *         vmSize: String
+     *         zone: String
+     *     }
+     *     network: {
+     *         interfaceProperty: [
+     *             {
+     *                 ipv4: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                             publicIpAddress: String
+     *                         }
+     *                     ]
+     *                     subnet: [
+     *                         {
+     *                             address: String
+     *                             prefix: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 ipv6: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 macAddress: String
+     *             }
+     *         ]
+     *     }
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return instance Metadata for the Virtual Machine along with {@link Response} on successful completion of {@link + * Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMetadataWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getMetadataWithResponseAsync(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesClient.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesClient.java new file mode 100644 index 000000000000..22c5137ae533 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesClient.java @@ -0,0 +1,210 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.implementation.InstancesImpl; + +/** Initializes a new instance of the synchronous InstanceMetadataClient type. */ +@ServiceClient(builder = InstancesClientBuilder.class) +public final class InstancesClient { + @Generated private final InstancesImpl serviceClient; + + /** + * Initializes an instance of Instances client. + * + * @param serviceClient the service client implementation. + */ + @Generated + InstancesClient(InstancesImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Get Instance Metadata for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     compute: {
+     *         azEnvironment: String
+     *         evictionPolicy: String
+     *         extendedLocation: {
+     *             type: String
+     *             name: String
+     *         }
+     *         isHostCompatibilityLayerVm: String
+     *         licenseType: String
+     *         location: String
+     *         name: String
+     *         offer: String
+     *         osProfile: {
+     *             adminUsername: String
+     *             computerName: String
+     *             disablePasswordAuthentication: String
+     *         }
+     *         osType: String
+     *         placementGroupId: String
+     *         plan: {
+     *             name: String
+     *             publisher: String
+     *             product: String
+     *         }
+     *         publicKeys: [
+     *             {
+     *                 path: String
+     *                 keyData: String
+     *             }
+     *         ]
+     *         platformFaultDomain: String
+     *         platformSubFaultDomain: String
+     *         platformUpdateDomain: String
+     *         priority: String
+     *         provider: String
+     *         publisher: String
+     *         resourceGroupName: String
+     *         resourceId: String
+     *         securityProfile: {
+     *             secureBootEnabled: String
+     *             virtualTpmEnabled: String
+     *         }
+     *         sku: String
+     *         storageProfile: {
+     *             imageReference: {
+     *                 id: String
+     *                 offer: String
+     *                 publisher: String
+     *                 sku: String
+     *                 version: String
+     *             }
+     *             osDisk: {
+     *                 caching: String
+     *                 createOption: String
+     *                 diffDiskSettings: {
+     *                     option: String
+     *                 }
+     *                 diskSizeGB: String
+     *                 encryptionSettings: {
+     *                     enabled: String
+     *                 }
+     *                 image: {
+     *                     uri: String
+     *                 }
+     *                 managedDisk: {
+     *                     id: String
+     *                     storageAccountType: String
+     *                 }
+     *                 name: String
+     *                 osType: String
+     *                 vhd: {
+     *                     uri: String
+     *                 }
+     *                 writeAcceleratorEnabled: String
+     *             }
+     *             dataDisks: [
+     *                 {
+     *                     bytesPerSecondThrottle: String
+     *                     caching: String
+     *                     createOption: String
+     *                     diskCapacityBytes: String
+     *                     diskSizeGB: String
+     *                     image: (recursive schema, see image above)
+     *                     isSharedDisk: String
+     *                     isUltraDisk: String
+     *                     lun: String
+     *                     managedDisk: (recursive schema, see managedDisk above)
+     *                     name: String
+     *                     opsPerSecondThrottle: String
+     *                     vhd: (recursive schema, see vhd above)
+     *                     writeAcceleratorEnabled: String
+     *                 }
+     *             ]
+     *             resourceDisk: {
+     *                 size: String
+     *             }
+     *         }
+     *         subscriptionId: String
+     *         tags: String
+     *         tagsList: [
+     *             {
+     *                 name: String
+     *                 value: String
+     *             }
+     *         ]
+     *         userData: String
+     *         version: String
+     *         virtualMachineScaleSet: {
+     *             id: String
+     *         }
+     *         vmId: String
+     *         vmScaleSetName: String
+     *         vmSize: String
+     *         zone: String
+     *     }
+     *     network: {
+     *         interfaceProperty: [
+     *             {
+     *                 ipv4: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                             publicIpAddress: String
+     *                         }
+     *                     ]
+     *                     subnet: [
+     *                         {
+     *                             address: String
+     *                             prefix: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 ipv6: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 macAddress: String
+     *             }
+     *         ]
+     *     }
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return instance Metadata for the Virtual Machine along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getMetadataWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getMetadataWithResponse(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesClientBuilder.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesClientBuilder.java new file mode 100644 index 000000000000..778494fbe2f5 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/InstancesClientBuilder.java @@ -0,0 +1,287 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.imds.imds.implementation.InstanceMetadataClientImpl; +import com.azure.imds.imds.models.HostOptions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** A builder for creating a new instance of the InstancesClient type. */ +@ServiceClientBuilder(serviceClients = {InstancesClient.class, InstancesAsyncClient.class}) +public final class InstancesClientBuilder { + @Generated private static final String SDK_NAME = "name"; + + @Generated private static final String SDK_VERSION = "version"; + + @Generated private final Map properties = CoreUtils.getProperties("azure-imds-imds.properties"); + + /** Create an instance of the InstancesClientBuilder. */ + @Generated + public InstancesClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * server parameter + */ + @Generated private HostOptions host; + + /** + * Sets server parameter. + * + * @param host the host value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder host(HostOptions host) { + this.host = host; + return this; + } + + /* + * Service version + */ + @Generated private InstanceMetadataServiceVersion serviceVersion; + + /** + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder serviceVersion(InstanceMetadataServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + @Generated private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The HTTP client used to send the request. + */ + @Generated private HttpClient httpClient; + + /** + * Sets The HTTP client used to send the request. + * + * @param httpClient the httpClient value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The configuration store that is used during construction of the service + * client. + */ + @Generated private Configuration configuration; + + /** + * Sets The configuration store that is used during construction of the service client. + * + * @param configuration the configuration value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated private HttpLogOptions httpLogOptions; + + /** + * Sets The logging configuration for HTTP requests and responses. + * + * @param httpLogOptions the httpLogOptions value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if + * applicable. + */ + @Generated private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /* + * The list of Http pipeline policies to add. + */ + @Generated private final List pipelinePolicies; + + /* + * The client options such as application ID and custom headers to set on a + * request. + */ + @Generated private ClientOptions clientOptions; + + /** + * Sets The client options such as application ID and custom headers to set on a request. + * + * @param clientOptions the clientOptions value. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /** + * Adds a custom Http pipeline policy. + * + * @param customPolicy The custom Http pipeline policy to add. + * @return the InstancesClientBuilder. + */ + @Generated + public InstancesClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + pipelinePolicies.add(customPolicy); + return this; + } + + /** + * Builds an instance of InstanceMetadataClientImpl with the provided parameters. + * + * @return an instance of InstanceMetadataClientImpl. + */ + @Generated + private InstanceMetadataClientImpl buildInnerClient() { + if (host == null) { + this.host = HostOptions.HTTP169_254_169_254_METADATA; + } + if (serviceVersion == null) { + this.serviceVersion = InstanceMetadataServiceVersion.getLatest(); + } + if (pipeline == null) { + this.pipeline = createHttpPipeline(); + } + InstanceMetadataClientImpl client = + new InstanceMetadataClientImpl( + pipeline, JacksonAdapter.createDefaultSerializerAdapter(), host, serviceVersion); + return client; + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration = + (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + if (httpLogOptions == null) { + httpLogOptions = new HttpLogOptions(); + } + if (clientOptions == null) { + clientOptions = new ClientOptions(); + } + List policies = new ArrayList<>(); + String clientName = properties.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + HttpHeaders headers = new HttpHeaders(); + clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); + if (headers.getSize() > 0) { + policies.add(new AddHeadersPolicy(headers)); + } + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy); + policies.add(new CookiePolicy()); + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = + new HttpPipelineBuilder() + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(clientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of InstancesAsyncClient async client. + * + * @return an instance of InstancesAsyncClient. + */ + @Generated + public InstancesAsyncClient buildAsyncClient() { + return new InstancesAsyncClient(buildInnerClient().getInstances()); + } + + /** + * Builds an instance of InstancesClient sync client. + * + * @return an instance of InstancesClient. + */ + @Generated + public InstancesClient buildClient() { + return new InstancesClient(buildInnerClient().getInstances()); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/AttestedsImpl.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/AttestedsImpl.java new file mode 100644 index 000000000000..307a15ceecfe --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/AttestedsImpl.java @@ -0,0 +1,182 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** An instance of this class provides access to all the operations defined in Attesteds. */ +public final class AttestedsImpl { + /** The proxy service used to perform REST calls. */ + private final AttestedsService service; + + /** The service client containing this operation class. */ + private final InstanceMetadataClientImpl client; + + /** + * Initializes an instance of AttestedsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + AttestedsImpl(InstanceMetadataClientImpl client) { + this.service = + RestProxy.create(AttestedsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for InstanceMetadataClientAttesteds to be used by the proxy service to + * perform REST calls. + */ + @Host("{$host}") + @ServiceInterface(name = "InstanceMetadataClie") + private interface AttestedsService { + @Get("/attested/document") + @ExpectedResponses({200}) + Mono> getDocument( + @HostParam("$host") String host, + @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, + Context context); + } + + /** + * Get Attested Data for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
nonceStringNoThis is a string of up to 32 random alphanumeric characters.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     signature: String
+     *     encoding: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return attested Data for the Virtual Machine along with {@link Response} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getDocumentWithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext( + context -> + service.getDocument( + this.client.getHost(), + this.client.getServiceVersion().getVersion(), + requestOptions, + context)); + } + + /** + * Get Attested Data for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
nonceStringNoThis is a string of up to 32 random alphanumeric characters.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     signature: String
+     *     encoding: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return attested Data for the Virtual Machine along with {@link Response} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getDocumentWithResponseAsync(RequestOptions requestOptions, Context context) { + return service.getDocument( + this.client.getHost(), this.client.getServiceVersion().getVersion(), requestOptions, context); + } + + /** + * Get Attested Data for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
nonceStringNoThis is a string of up to 32 random alphanumeric characters.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     signature: String
+     *     encoding: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return attested Data for the Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getDocumentWithResponse(RequestOptions requestOptions) { + return getDocumentWithResponseAsync(requestOptions).block(); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/IdentitiesImpl.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/IdentitiesImpl.java new file mode 100644 index 000000000000..6e21e5a51009 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/IdentitiesImpl.java @@ -0,0 +1,343 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** An instance of this class provides access to all the operations defined in Identities. */ +public final class IdentitiesImpl { + /** The proxy service used to perform REST calls. */ + private final IdentitiesService service; + + /** The service client containing this operation class. */ + private final InstanceMetadataClientImpl client; + + /** + * Initializes an instance of IdentitiesImpl. + * + * @param client the instance of the service client containing this operation class. + */ + IdentitiesImpl(InstanceMetadataClientImpl client) { + this.service = + RestProxy.create(IdentitiesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for InstanceMetadataClientIdentities to be used by the proxy service to + * perform REST calls. + */ + @Host("{$host}") + @ServiceInterface(name = "InstanceMetadataClie") + private interface IdentitiesService { + @Get("/identity/oauth2/token") + @ExpectedResponses({200}) + Mono> getToken( + @HostParam("$host") String host, + @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, + Context context); + + @Get("/identity/info") + @ExpectedResponses({200}) + Mono> getInfo( + @HostParam("$host") String host, + @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, + Context context); + } + + /** + * Get a Token from Azure AD. + * + *

Query Parameters + * + * + * + * + * + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
resourceStringYesThis is the urlencoded identifier URI of the sink resource for the requested Azure AD token. The resulting token contains the corresponding aud for this resource.
api-versionStringYesApi Version
client_idStringNoThis identifies, by Azure AD client id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with object_id and msi_res_id.
object_idStringNoThis identifies, by Azure AD object id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and msi_res_id.
msi_res_idStringNoThis identifies, by urlencoded ARM resource id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and object_id.
authorityStringNoThis indicates the authority to request AAD tokens from. Defaults to the known authority of the identity to be used.
bypass_cacheStringNoIf provided, the value must be 'true'. This indicates to the server that the token must be retrieved from Azure AD and cannot be retrieved from an internal cache.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     accessToken: String
+     *     expiresIn: String
+     *     expiresOn: String
+     *     extExpiresIn: String
+     *     notBefore: String
+     *     resource: String
+     *     tokenType: String
+     *     clientId: String
+     *     objectId: String
+     *     msiResId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return a Token from Azure AD along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getTokenWithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext( + context -> + service.getToken( + this.client.getHost(), + this.client.getServiceVersion().getVersion(), + requestOptions, + context)); + } + + /** + * Get a Token from Azure AD. + * + *

Query Parameters + * + * + * + * + * + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
resourceStringYesThis is the urlencoded identifier URI of the sink resource for the requested Azure AD token. The resulting token contains the corresponding aud for this resource.
api-versionStringYesApi Version
client_idStringNoThis identifies, by Azure AD client id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with object_id and msi_res_id.
object_idStringNoThis identifies, by Azure AD object id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and msi_res_id.
msi_res_idStringNoThis identifies, by urlencoded ARM resource id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and object_id.
authorityStringNoThis indicates the authority to request AAD tokens from. Defaults to the known authority of the identity to be used.
bypass_cacheStringNoIf provided, the value must be 'true'. This indicates to the server that the token must be retrieved from Azure AD and cannot be retrieved from an internal cache.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     accessToken: String
+     *     expiresIn: String
+     *     expiresOn: String
+     *     extExpiresIn: String
+     *     notBefore: String
+     *     resource: String
+     *     tokenType: String
+     *     clientId: String
+     *     objectId: String
+     *     msiResId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return a Token from Azure AD along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getTokenWithResponseAsync(RequestOptions requestOptions, Context context) { + return service.getToken( + this.client.getHost(), this.client.getServiceVersion().getVersion(), requestOptions, context); + } + + /** + * Get a Token from Azure AD. + * + *

Query Parameters + * + * + * + * + * + * + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
resourceStringYesThis is the urlencoded identifier URI of the sink resource for the requested Azure AD token. The resulting token contains the corresponding aud for this resource.
api-versionStringYesApi Version
client_idStringNoThis identifies, by Azure AD client id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with object_id and msi_res_id.
object_idStringNoThis identifies, by Azure AD object id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and msi_res_id.
msi_res_idStringNoThis identifies, by urlencoded ARM resource id, a specific explicit identity to use when authenticating to Azure AD. Mutually exclusive with client_id and object_id.
authorityStringNoThis indicates the authority to request AAD tokens from. Defaults to the known authority of the identity to be used.
bypass_cacheStringNoIf provided, the value must be 'true'. This indicates to the server that the token must be retrieved from Azure AD and cannot be retrieved from an internal cache.
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     accessToken: String
+     *     expiresIn: String
+     *     expiresOn: String
+     *     extExpiresIn: String
+     *     notBefore: String
+     *     resource: String
+     *     tokenType: String
+     *     clientId: String
+     *     objectId: String
+     *     msiResId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return a Token from Azure AD along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getTokenWithResponse(RequestOptions requestOptions) { + return getTokenWithResponseAsync(requestOptions).block(); + } + + /** + * Get information about AAD Metadata. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     tenantId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return information about AAD Metadata along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getInfoWithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext( + context -> + service.getInfo( + this.client.getHost(), + this.client.getServiceVersion().getVersion(), + requestOptions, + context)); + } + + /** + * Get information about AAD Metadata. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     tenantId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return information about AAD Metadata along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getInfoWithResponseAsync(RequestOptions requestOptions, Context context) { + return service.getInfo( + this.client.getHost(), this.client.getServiceVersion().getVersion(), requestOptions, context); + } + + /** + * Get information about AAD Metadata. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     tenantId: String
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return information about AAD Metadata along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getInfoWithResponse(RequestOptions requestOptions) { + return getInfoWithResponseAsync(requestOptions).block(); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/InstanceMetadataClientImpl.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/InstanceMetadataClientImpl.java new file mode 100644 index 000000000000..78b50acd9609 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/InstanceMetadataClientImpl.java @@ -0,0 +1,152 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.implementation; + +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.imds.imds.InstanceMetadataServiceVersion; +import com.azure.imds.imds.models.HostOptions; + +/** Initializes a new instance of the InstanceMetadataClient type. */ +public final class InstanceMetadataClientImpl { + /** server parameter. */ + private final HostOptions host; + + /** + * Gets server parameter. + * + * @return the host value. + */ + public HostOptions getHost() { + return this.host; + } + + /** Service version. */ + private final InstanceMetadataServiceVersion serviceVersion; + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public InstanceMetadataServiceVersion getServiceVersion() { + return this.serviceVersion; + } + + /** The HTTP pipeline to send requests through. */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** The serializer to serialize an object into a string. */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** The InstancesImpl object to access its operations. */ + private final InstancesImpl instances; + + /** + * Gets the InstancesImpl object to access its operations. + * + * @return the InstancesImpl object. + */ + public InstancesImpl getInstances() { + return this.instances; + } + + /** The AttestedsImpl object to access its operations. */ + private final AttestedsImpl attesteds; + + /** + * Gets the AttestedsImpl object to access its operations. + * + * @return the AttestedsImpl object. + */ + public AttestedsImpl getAttesteds() { + return this.attesteds; + } + + /** The IdentitiesImpl object to access its operations. */ + private final IdentitiesImpl identities; + + /** + * Gets the IdentitiesImpl object to access its operations. + * + * @return the IdentitiesImpl object. + */ + public IdentitiesImpl getIdentities() { + return this.identities; + } + + /** + * Initializes an instance of InstanceMetadataClient client. + * + * @param host server parameter. + * @param serviceVersion Service version. + */ + public InstanceMetadataClientImpl(HostOptions host, InstanceMetadataServiceVersion serviceVersion) { + this( + new HttpPipelineBuilder() + .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()) + .build(), + JacksonAdapter.createDefaultSerializerAdapter(), + host, + serviceVersion); + } + + /** + * Initializes an instance of InstanceMetadataClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param host server parameter. + * @param serviceVersion Service version. + */ + public InstanceMetadataClientImpl( + HttpPipeline httpPipeline, HostOptions host, InstanceMetadataServiceVersion serviceVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), host, serviceVersion); + } + + /** + * Initializes an instance of InstanceMetadataClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param host server parameter. + * @param serviceVersion Service version. + */ + public InstanceMetadataClientImpl( + HttpPipeline httpPipeline, + SerializerAdapter serializerAdapter, + HostOptions host, + InstanceMetadataServiceVersion serviceVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.host = host; + this.serviceVersion = serviceVersion; + this.instances = new InstancesImpl(this); + this.attesteds = new AttestedsImpl(this); + this.identities = new IdentitiesImpl(this); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/InstancesImpl.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/InstancesImpl.java new file mode 100644 index 000000000000..4b6c4baa234e --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/implementation/InstancesImpl.java @@ -0,0 +1,602 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** An instance of this class provides access to all the operations defined in Instances. */ +public final class InstancesImpl { + /** The proxy service used to perform REST calls. */ + private final InstancesService service; + + /** The service client containing this operation class. */ + private final InstanceMetadataClientImpl client; + + /** + * Initializes an instance of InstancesImpl. + * + * @param client the instance of the service client containing this operation class. + */ + InstancesImpl(InstanceMetadataClientImpl client) { + this.service = + RestProxy.create(InstancesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for InstanceMetadataClientInstances to be used by the proxy service to + * perform REST calls. + */ + @Host("{$host}") + @ServiceInterface(name = "InstanceMetadataClie") + private interface InstancesService { + @Get("/instance") + @ExpectedResponses({200}) + Mono> getMetadata( + @HostParam("$host") String host, + @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, + Context context); + } + + /** + * Get Instance Metadata for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     compute: {
+     *         azEnvironment: String
+     *         evictionPolicy: String
+     *         extendedLocation: {
+     *             type: String
+     *             name: String
+     *         }
+     *         isHostCompatibilityLayerVm: String
+     *         licenseType: String
+     *         location: String
+     *         name: String
+     *         offer: String
+     *         osProfile: {
+     *             adminUsername: String
+     *             computerName: String
+     *             disablePasswordAuthentication: String
+     *         }
+     *         osType: String
+     *         placementGroupId: String
+     *         plan: {
+     *             name: String
+     *             publisher: String
+     *             product: String
+     *         }
+     *         publicKeys: [
+     *             {
+     *                 path: String
+     *                 keyData: String
+     *             }
+     *         ]
+     *         platformFaultDomain: String
+     *         platformSubFaultDomain: String
+     *         platformUpdateDomain: String
+     *         priority: String
+     *         provider: String
+     *         publisher: String
+     *         resourceGroupName: String
+     *         resourceId: String
+     *         securityProfile: {
+     *             secureBootEnabled: String
+     *             virtualTpmEnabled: String
+     *         }
+     *         sku: String
+     *         storageProfile: {
+     *             imageReference: {
+     *                 id: String
+     *                 offer: String
+     *                 publisher: String
+     *                 sku: String
+     *                 version: String
+     *             }
+     *             osDisk: {
+     *                 caching: String
+     *                 createOption: String
+     *                 diffDiskSettings: {
+     *                     option: String
+     *                 }
+     *                 diskSizeGB: String
+     *                 encryptionSettings: {
+     *                     enabled: String
+     *                 }
+     *                 image: {
+     *                     uri: String
+     *                 }
+     *                 managedDisk: {
+     *                     id: String
+     *                     storageAccountType: String
+     *                 }
+     *                 name: String
+     *                 osType: String
+     *                 vhd: {
+     *                     uri: String
+     *                 }
+     *                 writeAcceleratorEnabled: String
+     *             }
+     *             dataDisks: [
+     *                 {
+     *                     bytesPerSecondThrottle: String
+     *                     caching: String
+     *                     createOption: String
+     *                     diskCapacityBytes: String
+     *                     diskSizeGB: String
+     *                     image: (recursive schema, see image above)
+     *                     isSharedDisk: String
+     *                     isUltraDisk: String
+     *                     lun: String
+     *                     managedDisk: (recursive schema, see managedDisk above)
+     *                     name: String
+     *                     opsPerSecondThrottle: String
+     *                     vhd: (recursive schema, see vhd above)
+     *                     writeAcceleratorEnabled: String
+     *                 }
+     *             ]
+     *             resourceDisk: {
+     *                 size: String
+     *             }
+     *         }
+     *         subscriptionId: String
+     *         tags: String
+     *         tagsList: [
+     *             {
+     *                 name: String
+     *                 value: String
+     *             }
+     *         ]
+     *         userData: String
+     *         version: String
+     *         virtualMachineScaleSet: {
+     *             id: String
+     *         }
+     *         vmId: String
+     *         vmScaleSetName: String
+     *         vmSize: String
+     *         zone: String
+     *     }
+     *     network: {
+     *         interfaceProperty: [
+     *             {
+     *                 ipv4: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                             publicIpAddress: String
+     *                         }
+     *                     ]
+     *                     subnet: [
+     *                         {
+     *                             address: String
+     *                             prefix: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 ipv6: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 macAddress: String
+     *             }
+     *         ]
+     *     }
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return instance Metadata for the Virtual Machine along with {@link Response} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMetadataWithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext( + context -> + service.getMetadata( + this.client.getHost(), + this.client.getServiceVersion().getVersion(), + requestOptions, + context)); + } + + /** + * Get Instance Metadata for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     compute: {
+     *         azEnvironment: String
+     *         evictionPolicy: String
+     *         extendedLocation: {
+     *             type: String
+     *             name: String
+     *         }
+     *         isHostCompatibilityLayerVm: String
+     *         licenseType: String
+     *         location: String
+     *         name: String
+     *         offer: String
+     *         osProfile: {
+     *             adminUsername: String
+     *             computerName: String
+     *             disablePasswordAuthentication: String
+     *         }
+     *         osType: String
+     *         placementGroupId: String
+     *         plan: {
+     *             name: String
+     *             publisher: String
+     *             product: String
+     *         }
+     *         publicKeys: [
+     *             {
+     *                 path: String
+     *                 keyData: String
+     *             }
+     *         ]
+     *         platformFaultDomain: String
+     *         platformSubFaultDomain: String
+     *         platformUpdateDomain: String
+     *         priority: String
+     *         provider: String
+     *         publisher: String
+     *         resourceGroupName: String
+     *         resourceId: String
+     *         securityProfile: {
+     *             secureBootEnabled: String
+     *             virtualTpmEnabled: String
+     *         }
+     *         sku: String
+     *         storageProfile: {
+     *             imageReference: {
+     *                 id: String
+     *                 offer: String
+     *                 publisher: String
+     *                 sku: String
+     *                 version: String
+     *             }
+     *             osDisk: {
+     *                 caching: String
+     *                 createOption: String
+     *                 diffDiskSettings: {
+     *                     option: String
+     *                 }
+     *                 diskSizeGB: String
+     *                 encryptionSettings: {
+     *                     enabled: String
+     *                 }
+     *                 image: {
+     *                     uri: String
+     *                 }
+     *                 managedDisk: {
+     *                     id: String
+     *                     storageAccountType: String
+     *                 }
+     *                 name: String
+     *                 osType: String
+     *                 vhd: {
+     *                     uri: String
+     *                 }
+     *                 writeAcceleratorEnabled: String
+     *             }
+     *             dataDisks: [
+     *                 {
+     *                     bytesPerSecondThrottle: String
+     *                     caching: String
+     *                     createOption: String
+     *                     diskCapacityBytes: String
+     *                     diskSizeGB: String
+     *                     image: (recursive schema, see image above)
+     *                     isSharedDisk: String
+     *                     isUltraDisk: String
+     *                     lun: String
+     *                     managedDisk: (recursive schema, see managedDisk above)
+     *                     name: String
+     *                     opsPerSecondThrottle: String
+     *                     vhd: (recursive schema, see vhd above)
+     *                     writeAcceleratorEnabled: String
+     *                 }
+     *             ]
+     *             resourceDisk: {
+     *                 size: String
+     *             }
+     *         }
+     *         subscriptionId: String
+     *         tags: String
+     *         tagsList: [
+     *             {
+     *                 name: String
+     *                 value: String
+     *             }
+     *         ]
+     *         userData: String
+     *         version: String
+     *         virtualMachineScaleSet: {
+     *             id: String
+     *         }
+     *         vmId: String
+     *         vmScaleSetName: String
+     *         vmSize: String
+     *         zone: String
+     *     }
+     *     network: {
+     *         interfaceProperty: [
+     *             {
+     *                 ipv4: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                             publicIpAddress: String
+     *                         }
+     *                     ]
+     *                     subnet: [
+     *                         {
+     *                             address: String
+     *                             prefix: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 ipv6: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 macAddress: String
+     *             }
+     *         ]
+     *     }
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return instance Metadata for the Virtual Machine along with {@link Response} on successful completion of {@link + * Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getMetadataWithResponseAsync(RequestOptions requestOptions, Context context) { + return service.getMetadata( + this.client.getHost(), this.client.getServiceVersion().getVersion(), requestOptions, context); + } + + /** + * Get Instance Metadata for the Virtual Machine. + * + *

Query Parameters + * + * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
api-versionStringYesApi Version
+ * + *

Header Parameters + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
MetadataStringYesThis must be set to 'true'.
+ * + *

Response Body Schema + * + *

{@code
+     * {
+     *     compute: {
+     *         azEnvironment: String
+     *         evictionPolicy: String
+     *         extendedLocation: {
+     *             type: String
+     *             name: String
+     *         }
+     *         isHostCompatibilityLayerVm: String
+     *         licenseType: String
+     *         location: String
+     *         name: String
+     *         offer: String
+     *         osProfile: {
+     *             adminUsername: String
+     *             computerName: String
+     *             disablePasswordAuthentication: String
+     *         }
+     *         osType: String
+     *         placementGroupId: String
+     *         plan: {
+     *             name: String
+     *             publisher: String
+     *             product: String
+     *         }
+     *         publicKeys: [
+     *             {
+     *                 path: String
+     *                 keyData: String
+     *             }
+     *         ]
+     *         platformFaultDomain: String
+     *         platformSubFaultDomain: String
+     *         platformUpdateDomain: String
+     *         priority: String
+     *         provider: String
+     *         publisher: String
+     *         resourceGroupName: String
+     *         resourceId: String
+     *         securityProfile: {
+     *             secureBootEnabled: String
+     *             virtualTpmEnabled: String
+     *         }
+     *         sku: String
+     *         storageProfile: {
+     *             imageReference: {
+     *                 id: String
+     *                 offer: String
+     *                 publisher: String
+     *                 sku: String
+     *                 version: String
+     *             }
+     *             osDisk: {
+     *                 caching: String
+     *                 createOption: String
+     *                 diffDiskSettings: {
+     *                     option: String
+     *                 }
+     *                 diskSizeGB: String
+     *                 encryptionSettings: {
+     *                     enabled: String
+     *                 }
+     *                 image: {
+     *                     uri: String
+     *                 }
+     *                 managedDisk: {
+     *                     id: String
+     *                     storageAccountType: String
+     *                 }
+     *                 name: String
+     *                 osType: String
+     *                 vhd: {
+     *                     uri: String
+     *                 }
+     *                 writeAcceleratorEnabled: String
+     *             }
+     *             dataDisks: [
+     *                 {
+     *                     bytesPerSecondThrottle: String
+     *                     caching: String
+     *                     createOption: String
+     *                     diskCapacityBytes: String
+     *                     diskSizeGB: String
+     *                     image: (recursive schema, see image above)
+     *                     isSharedDisk: String
+     *                     isUltraDisk: String
+     *                     lun: String
+     *                     managedDisk: (recursive schema, see managedDisk above)
+     *                     name: String
+     *                     opsPerSecondThrottle: String
+     *                     vhd: (recursive schema, see vhd above)
+     *                     writeAcceleratorEnabled: String
+     *                 }
+     *             ]
+     *             resourceDisk: {
+     *                 size: String
+     *             }
+     *         }
+     *         subscriptionId: String
+     *         tags: String
+     *         tagsList: [
+     *             {
+     *                 name: String
+     *                 value: String
+     *             }
+     *         ]
+     *         userData: String
+     *         version: String
+     *         virtualMachineScaleSet: {
+     *             id: String
+     *         }
+     *         vmId: String
+     *         vmScaleSetName: String
+     *         vmSize: String
+     *         zone: String
+     *     }
+     *     network: {
+     *         interfaceProperty: [
+     *             {
+     *                 ipv4: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                             publicIpAddress: String
+     *                         }
+     *                     ]
+     *                     subnet: [
+     *                         {
+     *                             address: String
+     *                             prefix: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 ipv6: {
+     *                     ipAddress: [
+     *                         {
+     *                             privateIpAddress: String
+     *                         }
+     *                     ]
+     *                 }
+     *                 macAddress: String
+     *             }
+     *         ]
+     *     }
+     * }
+     * }
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @return instance Metadata for the Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getMetadataWithResponse(RequestOptions requestOptions) { + return getMetadataWithResponseAsync(requestOptions).block(); + } +} diff --git a/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/package-info.java b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/package-info.java new file mode 100644 index 000000000000..eeb6e9d1cbe8 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/com/azure/imds/imds/package-info.java @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** Package containing the classes for InstanceMetadataClient. The Azure Instance Metadata Client. */ +package com.azure.imds.imds; diff --git a/sdk/imds/azure-imds-imds/src/main/java/module-info.java b/sdk/imds/azure-imds-imds/src/main/java/module-info.java new file mode 100644 index 000000000000..0d671f82035f --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/java/module-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +module com.azure.imds.imds { + requires transitive com.azure.core; + + exports com.azure.imds.imds; +} diff --git a/sdk/imds/azure-imds-imds/src/main/resources/azure-imds-imds.properties b/sdk/imds/azure-imds-imds/src/main/resources/azure-imds-imds.properties new file mode 100644 index 000000000000..ca812989b4f2 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/main/resources/azure-imds-imds.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/ReadmeSamples.java b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/ReadmeSamples.java new file mode 100644 index 000000000000..6e6a0d095393 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/ReadmeSamples.java @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +public final class ReadmeSamples { + public void readmeSamples() { + // BEGIN: com.azure.imds.imds.readme + // END: com.azure.imds.imds.readme + } +} diff --git a/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetAttestedDataForTheVM.java b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetAttestedDataForTheVM.java new file mode 100644 index 000000000000..29c48fb8b1f2 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetAttestedDataForTheVM.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.generated; + +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.AttestedClient; +import com.azure.imds.imds.AttestedClientBuilder; + +public class GetAttestedDataForTheVM { + public static void main(String[] args) { + AttestedClient client = + new AttestedClientBuilder().host(HostOptions.HTTP169_254_169_254_METADATA).buildClient(); + RequestOptions requestOptions = new RequestOptions(); + requestOptions.addHeader("Metadata", "true"); + requestOptions.addQueryParam("nonce", "abcde12345"); + Response response = client.getDocumentWithResponse(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetIdentityInfoForTheVM.java b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetIdentityInfoForTheVM.java new file mode 100644 index 000000000000..feee799e0ebc --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetIdentityInfoForTheVM.java @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.generated; + +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.IdentityClient; +import com.azure.imds.imds.IdentityClientBuilder; + +public class GetIdentityInfoForTheVM { + public static void main(String[] args) { + IdentityClient client = + new IdentityClientBuilder().host(HostOptions.HTTP169_254_169_254_METADATA).buildClient(); + RequestOptions requestOptions = new RequestOptions(); + requestOptions.addHeader("Metadata", "true"); + Response response = client.getInfoWithResponse(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetIdentityTokenForTheVM.java b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetIdentityTokenForTheVM.java new file mode 100644 index 000000000000..716dbe93a2a9 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetIdentityTokenForTheVM.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.generated; + +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.IdentityClient; +import com.azure.imds.imds.IdentityClientBuilder; + +public class GetIdentityTokenForTheVM { + public static void main(String[] args) { + IdentityClient client = + new IdentityClientBuilder().host(HostOptions.HTTP169_254_169_254_METADATA).buildClient(); + RequestOptions requestOptions = new RequestOptions(); + requestOptions.addHeader("Metadata", "true"); + requestOptions.addQueryParam("resource", "https://vault.azure.net"); + Response response = client.getTokenWithResponse(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetInstanceMetadataForTheVM.java b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetInstanceMetadataForTheVM.java new file mode 100644 index 000000000000..329c7b0d02e4 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/samples/java/com/azure/imds/imds/generated/GetInstanceMetadataForTheVM.java @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds.generated; + +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.imds.imds.InstancesClient; +import com.azure.imds.imds.InstancesClientBuilder; + +public class GetInstanceMetadataForTheVM { + public static void main(String[] args) { + InstancesClient client = + new InstancesClientBuilder().host(HostOptions.HTTP169_254_169_254_METADATA).buildClient(); + RequestOptions requestOptions = new RequestOptions(); + requestOptions.addHeader("Metadata", "true"); + Response response = client.getMetadataWithResponse(requestOptions); + } +} diff --git a/sdk/imds/azure-imds-imds/src/test/java/com/azure/imds/imds/ClientTests.java b/sdk/imds/azure-imds-imds/src/test/java/com/azure/imds/imds/ClientTests.java new file mode 100644 index 000000000000..14fdd2bc7d84 --- /dev/null +++ b/sdk/imds/azure-imds-imds/src/test/java/com/azure/imds/imds/ClientTests.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.imds.imds; + +import com.azure.core.http.HttpClient; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestBase; +import com.azure.core.test.TestMode; +import com.azure.core.test.annotation.DoNotRecord; +import com.azure.core.util.Configuration; +import com.azure.imds.imds.models.HostOptions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public final class ClientTests extends TestBase { + private InstancesClient instancesClient; + + private AttestedClient attestedClient; + + private IdentityClient identityClient; + + @BeforeEach + public void setup() { + InstancesClientBuilder instancesClientbuilder = + new InstancesClientBuilder() + .host( + Configuration.getGlobalConfiguration() + .get("HOST", HostOptions.HTTP169_254_169_254_METADATA)) + .httpClient(HttpClient.createDefault()) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.PLAYBACK) { + instancesClientbuilder.httpClient(interceptorManager.getPlaybackClient()); + } else if (getTestMode() == TestMode.RECORD) { + instancesClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + instancesClient = instancesClientbuilder.buildClient(); + + AttestedClientBuilder attestedClientbuilder = + new AttestedClientBuilder() + .host( + Configuration.getGlobalConfiguration() + .get("HOST", HostOptions.HTTP169_254_169_254_METADATA)) + .httpClient(HttpClient.createDefault()) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.PLAYBACK) { + attestedClientbuilder.httpClient(interceptorManager.getPlaybackClient()); + } else if (getTestMode() == TestMode.RECORD) { + attestedClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + attestedClient = attestedClientbuilder.buildClient(); + + IdentityClientBuilder identityClientbuilder = + new IdentityClientBuilder() + .host( + Configuration.getGlobalConfiguration() + .get("HOST", HostOptions.HTTP169_254_169_254_METADATA)) + .httpClient(HttpClient.createDefault()) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.PLAYBACK) { + identityClientbuilder.httpClient(interceptorManager.getPlaybackClient()); + } else if (getTestMode() == TestMode.RECORD) { + identityClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + identityClient = identityClientbuilder.buildClient(); + } + + @Test + @DoNotRecord(skipInPlayback = true) + public void testClient() { + // use the builder to create client + } +} diff --git a/sdk/imds/azure-imds-imds/swagger/README_SPEC.md b/sdk/imds/azure-imds-imds/swagger/README_SPEC.md new file mode 100644 index 000000000000..95c12e4bd5ff --- /dev/null +++ b/sdk/imds/azure-imds-imds/swagger/README_SPEC.md @@ -0,0 +1,25 @@ +## Generate autorest code + +```yaml +input-files: +- /home/vsts/work/1/s/azure-rest-api-specs/specification/imds/data-plane/Microsoft.InstanceMetadataService/stable/2021-10-01/imds.json +output-folder: ../ +java: true +regenerate-pom: false +partial-update: true +generate-sync-async-clients: true +generate-client-as-impl: true +generate-client-interfaces: false +generate-builder-per-client: true +add-context-parameter: true +artifact-id: azure-imds-imds +low-level-client: true +sync-methods: all +generate-samples: true +license-header: MICROSOFT_MIT_SMALL +namespace: com.azure.imds.imds +context-client-method-parameter: true +azure-arm: false +service-versions: +- '2021-10-01' +```