diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 12c1345b83f3..53577558f9a6 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -257,6 +257,7 @@ com.azure.spring:spring-cloud-azure-stream-binder-servicebus-core;5.22.0;5.23.0- com.azure.spring:spring-cloud-azure-stream-binder-servicebus;5.22.0;5.23.0-beta.1 com.azure.spring:spring-cloud-azure-testcontainers;5.22.0;5.23.0-beta.1 com.azure:azure-spring-data-cosmos;5.22.0;5.23.0-beta.1 +com.azure:azure-developer-trustedsigning;1.0.0-beta.1;1.0.0-beta.1 com.azure.resourcemanager:azure-resourcemanager;2.49.0;2.50.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-appplatform;2.49.0;2.50.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-appservice;2.49.0;2.50.0-beta.1 diff --git a/pom.xml b/pom.xml index e985a85808f9..cba37bf699b6 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,7 @@ sdk/deploymentmanager sdk/desktopvirtualization sdk/devcenter + sdk/developer sdk/devhub sdk/deviceprovisioningservices sdk/deviceregistry diff --git a/sdk/developer/azure-developer-trustedsigning/CHANGELOG.md b/sdk/developer/azure-developer-trustedsigning/CHANGELOG.md new file mode 100644 index 000000000000..9d8d32abb877 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/CHANGELOG.md @@ -0,0 +1,16 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + +- Azure TrustedSigning client library for Java. This package contains Microsoft Azure TrustedSigning client library. + +### Features Added + +### Breaking Changes + +### Bugs Fixed + +### Other Changes +### Features Added + +- Initial release for the azure-developer-trustedsigning Java SDK. diff --git a/sdk/developer/azure-developer-trustedsigning/README.md b/sdk/developer/azure-developer-trustedsigning/README.md new file mode 100644 index 000000000000..00064fb7656f --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/README.md @@ -0,0 +1,78 @@ +# Azure TrustedSigning client library for Java + +Azure TrustedSigning client library for Java. + +This package contains Microsoft Azure TrustedSigning 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-developer-trustedsigning;current}) +```xml + + com.azure + azure-developer-trustedsigning + 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.developer.trustedsigning.readme +``` + +### Service API versions + +The client library targets the latest service API version by default. +The service client builder accepts an optional service API version parameter to specify which API version to communicate. + +#### Select a service API version + +You have the flexibility to explicitly select a supported service API version when initializing a service client via the service client builder. +This ensures that the client can communicate with services using the specified API version. + +When selecting an API version, it is important to verify that there are no breaking changes compared to the latest API version. +If there are significant differences, API calls may fail due to incompatibility. + +Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy. + +## 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://learn.microsoft.com/azure/developer/java/fundamentals/ +[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/developer/azure-developer-trustedsigning/assets.json b/sdk/developer/azure-developer-trustedsigning/assets.json new file mode 100644 index 000000000000..7742cbe8d095 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/assets.json @@ -0,0 +1 @@ +{"AssetsRepo":"Azure/azure-sdk-assets","AssetsRepoPrefixPath":"java","TagPrefix":"java/developer/azure-developer-trustedsigning","Tag":""} \ No newline at end of file diff --git a/sdk/developer/azure-developer-trustedsigning/pom.xml b/sdk/developer/azure-developer-trustedsigning/pom.xml new file mode 100644 index 000000000000..3afc6bc1ae6c --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure + azure-developer-trustedsigning + 1.0.0-beta.1 + jar + + Microsoft Azure SDK for TrustedSigning + This package contains Microsoft Azure TrustedSigning 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 + + + + com.azure + azure-core + 1.55.3 + + + com.azure + azure-core-http-netty + 1.15.11 + + + com.azure + azure-core-test + 1.27.0-beta.8 + test + + + com.azure + azure-identity + 1.15.4 + test + + + diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningAsyncClient.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningAsyncClient.java new file mode 100644 index 000000000000..4d6c9083ad4e --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningAsyncClient.java @@ -0,0 +1,406 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning; + +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.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.PollerFlux; +import com.azure.developer.trustedsigning.implementation.CertificateProfileOperationsImpl; +import com.azure.developer.trustedsigning.models.ExtendedKeyUsage; +import com.azure.developer.trustedsigning.models.OperationStatusSignResultError; +import com.azure.developer.trustedsigning.models.SignResult; +import com.azure.developer.trustedsigning.models.SigningPayloadOptions; +import java.util.stream.Collectors; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the asynchronous TrustedSigningClient type. + */ +@ServiceClient(builder = TrustedSigningClientBuilder.class, isAsync = true) +public final class TrustedSigningAsyncClient { + @Generated + private final CertificateProfileOperationsImpl serviceClient; + + /** + * Initializes an instance of TrustedSigningAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + TrustedSigningAsyncClient(CertificateProfileOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Gets the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param operationId The unique ID of the operation. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known along with + * {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSigningStatusWithResponse(String accountName, String certificateProfile, + String operationId, RequestOptions requestOptions) { + return this.serviceClient.getSigningStatusWithResponseAsync(accountName, certificateProfile, operationId, + requestOptions); + } + + /** + * Gets the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSignRootCertificateWithResponse(String accountName, String certificateProfile, + RequestOptions requestOptions) { + return this.serviceClient.getSignRootCertificateWithResponseAsync(accountName, certificateProfile, + requestOptions); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listExtendedKeyUsages(String accountName, String certificateProfile, + RequestOptions requestOptions) { + return this.serviceClient.listExtendedKeyUsagesAsync(accountName, certificateProfile, requestOptions); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link PollerFlux} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginSign(String accountName, String certificateProfile, BinaryData body, + RequestOptions requestOptions) { + return this.serviceClient.beginSignAsync(accountName, certificateProfile, body, requestOptions); + } + + /** + * Gets the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known. + * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param operationId The unique ID of the operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known on successful + * completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSigningStatus(String accountName, String certificateProfile, + String operationId) { + // Generated convenience method for getSigningStatusWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSigningStatusWithResponse(accountName, certificateProfile, operationId, requestOptions) + .flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(OperationStatusSignResultError.class)); + } + + /** + * Gets the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided. + * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSignRootCertificate(String accountName, String certificateProfile) { + // Generated convenience method for getSignRootCertificateWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSignRootCertificateWithResponse(accountName, certificateProfile, requestOptions) + .flatMap(FluxUtil::toMono); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listExtendedKeyUsages(String accountName, String certificateProfile) { + // Generated convenience method for listExtendedKeyUsages + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse + = listExtendedKeyUsages(accountName, certificateProfile, requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(ExtendedKeyUsage.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param clientVersion An optional client version. + * @param xCorrelationId An identifier used to batch multiple requests. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginSign(String accountName, String certificateProfile, + SigningPayloadOptions body, String clientVersion, String xCorrelationId) { + // Generated convenience method for beginSignWithModel + RequestOptions requestOptions = new RequestOptions(); + if (clientVersion != null) { + requestOptions.setHeader(HttpHeaderName.fromString("client-version"), clientVersion); + } + if (xCorrelationId != null) { + requestOptions.setHeader(HttpHeaderName.fromString("x-correlation-id"), xCorrelationId); + } + return serviceClient.beginSignWithModelAsync(accountName, certificateProfile, BinaryData.fromObject(body), + requestOptions); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginSign(String accountName, String certificateProfile, + SigningPayloadOptions body) { + // Generated convenience method for beginSignWithModel + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.beginSignWithModelAsync(accountName, certificateProfile, BinaryData.fromObject(body), + requestOptions); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningClient.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningClient.java new file mode 100644 index 000000000000..6613d72de8bb --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningClient.java @@ -0,0 +1,384 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning; + +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.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; +import com.azure.developer.trustedsigning.implementation.CertificateProfileOperationsImpl; +import com.azure.developer.trustedsigning.models.ExtendedKeyUsage; +import com.azure.developer.trustedsigning.models.OperationStatusSignResultError; +import com.azure.developer.trustedsigning.models.SignResult; +import com.azure.developer.trustedsigning.models.SigningPayloadOptions; + +/** + * Initializes a new instance of the synchronous TrustedSigningClient type. + */ +@ServiceClient(builder = TrustedSigningClientBuilder.class) +public final class TrustedSigningClient { + @Generated + private final CertificateProfileOperationsImpl serviceClient; + + /** + * Initializes an instance of TrustedSigningClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + TrustedSigningClient(CertificateProfileOperationsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Gets the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param operationId The unique ID of the operation. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known along with + * {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSigningStatusWithResponse(String accountName, String certificateProfile, + String operationId, RequestOptions requestOptions) { + return this.serviceClient.getSigningStatusWithResponse(accountName, certificateProfile, operationId, + requestOptions); + } + + /** + * Gets the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSignRootCertificateWithResponse(String accountName, String certificateProfile, + RequestOptions requestOptions) { + return this.serviceClient.getSignRootCertificateWithResponse(accountName, certificateProfile, requestOptions); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listExtendedKeyUsages(String accountName, String certificateProfile, + RequestOptions requestOptions) { + return this.serviceClient.listExtendedKeyUsages(accountName, certificateProfile, requestOptions); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link SyncPoller} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginSign(String accountName, String certificateProfile, BinaryData body, + RequestOptions requestOptions) { + return this.serviceClient.beginSign(accountName, certificateProfile, body, requestOptions); + } + + /** + * Gets the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known. + * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param operationId The unique ID of the operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public OperationStatusSignResultError getSigningStatus(String accountName, String certificateProfile, + String operationId) { + // Generated convenience method for getSigningStatusWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSigningStatusWithResponse(accountName, certificateProfile, operationId, requestOptions).getValue() + .toObject(OperationStatusSignResultError.class); + } + + /** + * Gets the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided. + * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public BinaryData getSignRootCertificate(String accountName, String certificateProfile) { + // Generated convenience method for getSignRootCertificateWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSignRootCertificateWithResponse(accountName, certificateProfile, requestOptions).getValue(); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listExtendedKeyUsages(String accountName, String certificateProfile) { + // Generated convenience method for listExtendedKeyUsages + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listExtendedKeyUsages(accountName, certificateProfile, requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(ExtendedKeyUsage.class)); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param clientVersion An optional client version. + * @param xCorrelationId An identifier used to batch multiple requests. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginSign(String accountName, String certificateProfile, + SigningPayloadOptions body, String clientVersion, String xCorrelationId) { + // Generated convenience method for beginSignWithModel + RequestOptions requestOptions = new RequestOptions(); + if (clientVersion != null) { + requestOptions.setHeader(HttpHeaderName.fromString("client-version"), clientVersion); + } + if (xCorrelationId != null) { + requestOptions.setHeader(HttpHeaderName.fromString("x-correlation-id"), xCorrelationId); + } + return serviceClient.beginSignWithModel(accountName, certificateProfile, BinaryData.fromObject(body), + requestOptions); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginSign(String accountName, String certificateProfile, + SigningPayloadOptions body) { + // Generated convenience method for beginSignWithModel + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.beginSignWithModel(accountName, certificateProfile, BinaryData.fromObject(body), + requestOptions); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningClientBuilder.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningClientBuilder.java new file mode 100644 index 000000000000..42b4fc138fad --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningClientBuilder.java @@ -0,0 +1,334 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.client.traits.TokenCredentialTrait; +import com.azure.core.credential.TokenCredential; +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.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +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.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +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.builder.ClientBuilderUtil; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.developer.trustedsigning.implementation.TrustedSigningClientImpl; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * A builder for creating a new instance of the TrustedSigningClient type. + */ +@ServiceClientBuilder(serviceClients = { TrustedSigningClient.class, TrustedSigningAsyncClient.class }) +public final class TrustedSigningClientBuilder + implements HttpTrait, ConfigurationTrait, + TokenCredentialTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final String[] DEFAULT_SCOPES = new String[] { "https://codesigning.azure.net/.default" }; + + @Generated + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-developer-trustedsigning.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the TrustedSigningClientBuilder. + */ + @Generated + public TrustedSigningClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The TokenCredential used for authentication. + */ + @Generated + private TokenCredential tokenCredential; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder credential(TokenCredential tokenCredential) { + this.tokenCredential = tokenCredential; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public TrustedSigningClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * Service version + */ + @Generated + private TrustedSigningServiceVersion serviceVersion; + + /** + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the TrustedSigningClientBuilder. + */ + @Generated + public TrustedSigningClientBuilder serviceVersion(TrustedSigningServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + 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 TrustedSigningClientBuilder. + */ + @Generated + public TrustedSigningClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of TrustedSigningClientImpl with the provided parameters. + * + * @return an instance of TrustedSigningClientImpl. + */ + @Generated + private TrustedSigningClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + TrustedSigningServiceVersion localServiceVersion + = (serviceVersion != null) ? serviceVersion : TrustedSigningServiceVersion.getLatest(); + TrustedSigningClientImpl client = new TrustedSigningClientImpl(localPipeline, + JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint, localServiceVersion); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + if (tokenCredential != null) { + policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of TrustedSigningAsyncClient class. + * + * @return an instance of TrustedSigningAsyncClient. + */ + @Generated + public TrustedSigningAsyncClient buildAsyncClient() { + return new TrustedSigningAsyncClient(buildInnerClient().getCertificateProfileOperations()); + } + + /** + * Builds an instance of TrustedSigningClient class. + * + * @return an instance of TrustedSigningClient. + */ + @Generated + public TrustedSigningClient buildClient() { + return new TrustedSigningClient(buildInnerClient().getCertificateProfileOperations()); + } + + private static final ClientLogger LOGGER = new ClientLogger(TrustedSigningClientBuilder.class); +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningServiceVersion.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningServiceVersion.java new file mode 100644 index 000000000000..aa6d5416cef5 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/TrustedSigningServiceVersion.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning; + +import com.azure.core.util.ServiceVersion; + +/** + * Service version of TrustedSigningClient. + */ +public enum TrustedSigningServiceVersion implements ServiceVersion { + /** + * Enum value 2023-06-15-preview. + */ + V2023_06_15_PREVIEW("2023-06-15-preview"); + + private final String version; + + TrustedSigningServiceVersion(String version) { + this.version = version; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link TrustedSigningServiceVersion}. + */ + public static TrustedSigningServiceVersion getLatest() { + return V2023_06_15_PREVIEW; + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/CertificateProfileOperationsImpl.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/CertificateProfileOperationsImpl.java new file mode 100644 index 000000000000..e3dc50cb481f --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/CertificateProfileOperationsImpl.java @@ -0,0 +1,1111 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +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.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +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 com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.PollingStrategyOptions; +import com.azure.core.util.polling.SyncPoller; +import com.azure.core.util.serializer.TypeReference; +import com.azure.developer.trustedsigning.TrustedSigningServiceVersion; +import com.azure.developer.trustedsigning.models.SignResult; +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in CertificateProfileOperations. + */ +public final class CertificateProfileOperationsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final CertificateProfileOperationsService service; + + /** + * The service client containing this operation class. + */ + private final TrustedSigningClientImpl client; + + /** + * Initializes an instance of CertificateProfileOperationsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + CertificateProfileOperationsImpl(TrustedSigningClientImpl client) { + this.service = RestProxy.create(CertificateProfileOperationsService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public TrustedSigningServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for TrustedSigningClientCertificateProfileOperations to be used by the + * proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "TrustedSigningClient") + public interface CertificateProfileOperationsService { + @Get("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}/sign/{operationId}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSigningStatus(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @PathParam("operationId") String operationId, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}/sign/{operationId}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getSigningStatusSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @PathParam("operationId") String operationId, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}/sign/rootcert") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSignRootCertificate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}/sign/rootcert") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getSignRootCertificateSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}/sign/eku") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listExtendedKeyUsages(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}/sign/eku") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listExtendedKeyUsagesSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Post("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}:sign") + @ExpectedResponses({ 202 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> sign(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + + @Post("/codesigningaccounts/{accountName}/certificateprofiles/{certificateProfile}:sign") + @ExpectedResponses({ 202 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response signSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("accountName") String accountName, + @PathParam("certificateProfile") String certificateProfile, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData body, + RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listExtendedKeyUsagesNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listExtendedKeyUsagesNextSync( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + } + + /** + * Gets the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param operationId The unique ID of the operation. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known along with + * {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSigningStatusWithResponseAsync(String accountName, String certificateProfile, + String operationId, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.getSigningStatus(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + accountName, certificateProfile, operationId, accept, requestOptions, context)); + } + + /** + * Gets the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param operationId The unique ID of the operation. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the status of a signing operation. + * + * This status operation requires that a Sign request has been submitted and the operationId is known along with + * {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSigningStatusWithResponse(String accountName, String certificateProfile, + String operationId, RequestOptions requestOptions) { + final String accept = "application/json"; + return service.getSigningStatusSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + accountName, certificateProfile, operationId, accept, requestOptions, Context.NONE); + } + + /** + * Gets the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSignRootCertificateWithResponseAsync(String accountName, + String certificateProfile, RequestOptions requestOptions) { + final String accept = "application/x-x509-ca-cert"; + return FluxUtil.withContext(context -> service.getSignRootCertificate(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), accountName, certificateProfile, accept, requestOptions, + context)); + } + + /** + * Gets the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided. + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param accountName Signing account name. + * @param certificateProfile Signing Certificate profile name. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the signing root certificate on the certificate chain for that account and profile name. + * + * The root certificate is generated as part of the initial account creation and it is used to sign the bits for the + * profile provided along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSignRootCertificateWithResponse(String accountName, String certificateProfile, + RequestOptions requestOptions) { + final String accept = "application/x-x509-ca-cert"; + return service.getSignRootCertificateSync(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), accountName, certificateProfile, accept, requestOptions, + Context.NONE); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listExtendedKeyUsagesSinglePageAsync(String accountName, + String certificateProfile, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listExtendedKeyUsages(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), accountName, certificateProfile, accept, requestOptions, + context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null)); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listExtendedKeyUsagesAsync(String accountName, String certificateProfile, + RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>( + () -> listExtendedKeyUsagesSinglePageAsync(accountName, certificateProfile, requestOptions), + nextLink -> listExtendedKeyUsagesNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listExtendedKeyUsagesSinglePage(String accountName, String certificateProfile, + RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.listExtendedKeyUsagesSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + accountName, certificateProfile, accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return a list of extended key usage object identifiers that are allowed for this account and profile + * combination. + * + * The list of extended key usages are used to determine the purpose of the certificate usage as part of the signing + * operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listExtendedKeyUsages(String accountName, String certificateProfile, + RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>( + () -> listExtendedKeyUsagesSinglePage(accountName, certificateProfile, requestOptions), + nextLink -> listExtendedKeyUsagesNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return provides status details for long running operations along with {@link Response} on successful completion + * of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> signWithResponseAsync(String accountName, String certificateProfile, + BinaryData body, RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.sign(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + accountName, certificateProfile, contentType, accept, body, requestOptions, context)); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return provides status details for long running operations along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response signWithResponse(String accountName, String certificateProfile, BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.signSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), accountName, + certificateProfile, contentType, accept, body, requestOptions, Context.NONE); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link PollerFlux} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginSignAsync(String accountName, String certificateProfile, + BinaryData body, RequestOptions requestOptions) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.signWithResponseAsync(accountName, certificateProfile, body, requestOptions), + new com.azure.developer.trustedsigning.implementation.OperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(BinaryData.class)); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link SyncPoller} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginSign(String accountName, String certificateProfile, BinaryData body, + RequestOptions requestOptions) { + return SyncPoller.createPoller(Duration.ofSeconds(1), + () -> this.signWithResponse(accountName, certificateProfile, body, requestOptions), + new com.azure.developer.trustedsigning.implementation.SyncOperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(BinaryData.class)); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link PollerFlux} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginSignWithModelAsync(String accountName, + String certificateProfile, BinaryData body, RequestOptions requestOptions) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.signWithResponseAsync(accountName, certificateProfile, body, requestOptions), + new com.azure.developer.trustedsigning.implementation.OperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(PollOperationDetails.class), TypeReference.createInstance(SignResult.class)); + } + + /** + * Submit a sign operation. + * + * Submit a sign operation under the created account and profile name provided. + *

Header Parameters

+ * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
client-versionStringNoAn optional client version.
x-correlation-idStringNoAn identifier used to batch multiple + * requests.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     signatureAlgorithm: String(RS256/RS384/RS512/PS256/PS384/PS512/ES256/ES384/ES512/ES256K) (Required)
+     *     digest: byte[] (Required)
+     *     fileHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     *     authenticodeHashList (Optional): [
+     *         byte[] (Optional)
+     *     ]
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         error (Required): {
+     *             code: String (Required)
+     *             message: String (Required)
+     *             target: String (Optional)
+     *             details (Optional): [
+     *                 (recursive schema, see above)
+     *             ]
+     *             innererror (Optional): {
+     *                 code: String (Optional)
+     *                 innererror (Optional): (recursive schema, see innererror above)
+     *             }
+     *         }
+     *     }
+     *     result (Optional): {
+     *         signature: byte[] (Optional)
+     *         signingCertificate: byte[] (Optional)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param accountName Azure Trusted Signing account name. + * @param certificateProfile Azure Trusted Signing certificate profile name under an account. + * @param body Body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link SyncPoller} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginSignWithModel(String accountName, + String certificateProfile, BinaryData body, RequestOptions requestOptions) { + return SyncPoller.createPoller(Duration.ofSeconds(1), + () -> this.signWithResponse(accountName, certificateProfile, body, requestOptions), + new com.azure.developer.trustedsigning.implementation.SyncOperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(PollOperationDetails.class), TypeReference.createInstance(SignResult.class)); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return paged collection of ExtendedKeyUsage items along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listExtendedKeyUsagesNextSinglePageAsync(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listExtendedKeyUsagesNext(nextLink, this.client.getEndpoint(), accept, + requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null)); + } + + /** + * Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + * + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     eku: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return paged collection of ExtendedKeyUsage items along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listExtendedKeyUsagesNextSinglePage(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.listExtendedKeyUsagesNextSync(nextLink, this.client.getEndpoint(), accept, + requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); + } + + private List getValues(BinaryData binaryData, String path) { + try { + Map obj = binaryData.toObject(Map.class); + List values = (List) obj.get(path); + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String path) { + try { + Map obj = binaryData.toObject(Map.class); + return (String) obj.get(path); + } catch (RuntimeException e) { + return null; + } + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/OperationLocationPollingStrategy.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/OperationLocationPollingStrategy.java new file mode 100644 index 000000000000..aa70806c24e2 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/OperationLocationPollingStrategy.java @@ -0,0 +1,140 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.implementation; + +import com.azure.core.exception.AzureException; +import com.azure.core.http.HttpHeader; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.OperationResourcePollingStrategy; +import com.azure.core.util.polling.PollResponse; +import com.azure.core.util.polling.PollingContext; +import com.azure.core.util.polling.PollingStrategyOptions; +import com.azure.core.util.serializer.JsonSerializerProviders; +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.core.util.serializer.TypeReference; +import java.time.Duration; +import java.time.OffsetDateTime; +import reactor.core.publisher.Mono; + +// DO NOT modify this helper class + +/** + * Implements an operation location polling strategy, from Operation-Location. + * + * @param the type of the response type from a polling call, or BinaryData if raw response body should be kept + * @param the type of the final result object to deserialize into, or BinaryData if raw response body should be + * kept + */ +public final class OperationLocationPollingStrategy extends OperationResourcePollingStrategy { + + private static final ClientLogger LOGGER = new ClientLogger(OperationLocationPollingStrategy.class); + + private final ObjectSerializer serializer; + private final String endpoint; + private final String propertyName; + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public OperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions) { + this(pollingStrategyOptions, null); + } + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @param propertyName the name of the property to extract final result. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public OperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions, String propertyName) { + super(PollingUtils.OPERATION_LOCATION_HEADER, pollingStrategyOptions); + this.propertyName = propertyName; + this.endpoint = pollingStrategyOptions.getEndpoint(); + this.serializer = pollingStrategyOptions.getSerializer() != null + ? pollingStrategyOptions.getSerializer() + : JsonSerializerProviders.createInstance(true); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> onInitialResponse(Response response, PollingContext pollingContext, + TypeReference pollResponseType) { + // Response is Response + + HttpHeader operationLocationHeader = response.getHeaders().get(PollingUtils.OPERATION_LOCATION_HEADER); + if (operationLocationHeader != null) { + pollingContext.setData(PollingUtils.OPERATION_LOCATION_HEADER.getCaseSensitiveName(), + PollingUtils.getAbsolutePath(operationLocationHeader.getValue(), endpoint, LOGGER)); + } + final String httpMethod = response.getRequest().getHttpMethod().name(); + pollingContext.setData(PollingUtils.HTTP_METHOD, httpMethod); + pollingContext.setData(PollingUtils.REQUEST_URL, response.getRequest().getUrl().toString()); + + if (response.getStatusCode() == 200 + || response.getStatusCode() == 201 + || response.getStatusCode() == 202 + || response.getStatusCode() == 204) { + final Duration retryAfter + = PollingUtils.getRetryAfterFromHeaders(response.getHeaders(), OffsetDateTime::now); + final Mono> pollResponseMono + = PollingUtils.deserializeResponse((BinaryData) response.getValue(), serializer, pollResponseType) + .onErrorResume(exception -> { + LOGGER.info("Failed to parse initial response."); + return Mono.empty(); + }) + .map(value -> new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS, value, retryAfter)); + return pollResponseMono.switchIfEmpty( + Mono.fromSupplier(() -> new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS, null, retryAfter))); + } else { + return Mono + .error( + new AzureException(String.format( + "Operation failed or cancelled with status code %d," + + ", '%s' header: %s, and response body: %s", + response.getStatusCode(), PollingUtils.OPERATION_LOCATION_HEADER, operationLocationHeader, + response.getValue()))); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono getResult(PollingContext pollingContext, TypeReference resultType) { + if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.FAILED) { + return Mono.error(new AzureException("Long running operation failed.")); + } else if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.USER_CANCELLED) { + return Mono.error(new AzureException("Long running operation cancelled.")); + } + if (propertyName != null) { + // take the last poll response body from PollingContext, + // and de-serialize the property as final result + BinaryData latestResponseBody + = BinaryData.fromString(pollingContext.getData(PollingUtils.POLL_RESPONSE_BODY)); + return PollingUtils + .deserializeResponse(latestResponseBody, serializer, PollingUtils.POST_POLL_RESULT_TYPE_REFERENCE) + .flatMap(value -> { + if (value.get(propertyName) != null) { + return BinaryData.fromObjectAsync(value.get(propertyName)) + .flatMap(result -> PollingUtils.deserializeResponse(result, serializer, resultType)); + } else { + return Mono.error(new AzureException("Cannot get final result")); + } + }) + .switchIfEmpty(Mono.error(new AzureException("Cannot get final result"))); + } else { + return super.getResult(pollingContext, resultType); + } + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/PollingUtils.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/PollingUtils.java new file mode 100644 index 000000000000..4500d3989b1f --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/PollingUtils.java @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.implementation; + +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.util.BinaryData; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.DateTimeRfc1123; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.core.util.serializer.TypeReference; +import java.net.URI; +import java.net.URISyntaxException; +import java.time.DateTimeException; +import java.time.Duration; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; +import reactor.core.publisher.Mono; + +// DO NOT modify this helper class + +final class PollingUtils { + + public static final TypeReference> POST_POLL_RESULT_TYPE_REFERENCE + = new TypeReference>() { + }; + + public static final HttpHeaderName OPERATION_LOCATION_HEADER = HttpHeaderName.fromString("Operation-Location"); + + public static final String HTTP_METHOD = "httpMethod"; + public static final String REQUEST_URL = "requestURL"; + public static final String POLL_RESPONSE_BODY = "pollResponseBody"; + + private static final String FORWARD_SLASH = "/"; + + public static String getAbsolutePath(String path, String endpoint, ClientLogger logger) { + try { + URI uri = new URI(path); + if (!uri.isAbsolute()) { + if (CoreUtils.isNullOrEmpty(endpoint)) { + throw logger.logExceptionAsError(new IllegalArgumentException( + "Relative path requires endpoint to be non-null and non-empty to create an absolute path.")); + } + + if (endpoint.endsWith(FORWARD_SLASH) && path.startsWith(FORWARD_SLASH)) { + return endpoint + path.substring(1); + } else if (!endpoint.endsWith(FORWARD_SLASH) && !path.startsWith(FORWARD_SLASH)) { + return endpoint + FORWARD_SLASH + path; + } else { + return endpoint + path; + } + } + } catch (URISyntaxException ex) { + throw logger.logExceptionAsWarning(new IllegalArgumentException("'path' must be a valid URI.", ex)); + } + return path; + } + + public static T deserializeResponseSync(BinaryData binaryData, ObjectSerializer serializer, + TypeReference typeReference) { + T value; + if (binaryData == null) { + value = null; + } else if (typeReference.getJavaClass().isAssignableFrom(BinaryData.class)) { + // T is BinaryData + value = typeReference.getJavaClass().cast(binaryData.toReplayableBinaryData()); + } else { + value = binaryData.toObject(typeReference, serializer); + } + return value; + } + + @SuppressWarnings("unchecked") + public static Mono deserializeResponse(BinaryData binaryData, ObjectSerializer serializer, + TypeReference typeReference) { + Mono value; + if (binaryData == null) { + value = Mono.empty(); + } else if (typeReference.getJavaClass().isAssignableFrom(BinaryData.class)) { + // T is BinaryData + value = (Mono) binaryData.toReplayableBinaryDataAsync(); + } else { + value = binaryData.toObjectAsync(typeReference, serializer); + } + return value; + } + + private static final HttpHeaderName RETRY_AFTER_MS_HEADER = HttpHeaderName.fromString("retry-after-ms"); + private static final HttpHeaderName X_MS_RETRY_AFTER_MS_HEADER = HttpHeaderName.fromString("x-ms-retry-after-ms"); + + public static Duration getRetryAfterFromHeaders(HttpHeaders headers, Supplier nowSupplier) { + // Found 'x-ms-retry-after-ms' header, use a Duration of milliseconds based on the value. + Duration retryDelay = tryGetRetryDelay(headers, X_MS_RETRY_AFTER_MS_HEADER, s -> tryGetDelayMillis(s)); + if (retryDelay != null) { + return retryDelay; + } + + // Found 'retry-after-ms' header, use a Duration of milliseconds based on the value. + retryDelay = tryGetRetryDelay(headers, RETRY_AFTER_MS_HEADER, s -> tryGetDelayMillis(s)); + if (retryDelay != null) { + return retryDelay; + } + + // Found 'Retry-After' header. First, attempt to resolve it as a Duration of seconds. If that fails, then + // attempt to resolve it as an HTTP date (RFC1123). + retryDelay = tryGetRetryDelay(headers, HttpHeaderName.RETRY_AFTER, + headerValue -> tryParseLongOrDateTime(headerValue, nowSupplier)); + + // Either the retry delay will have been found or it'll be null, null indicates no retry after. + return retryDelay; + } + + private static Duration tryGetRetryDelay(HttpHeaders headers, HttpHeaderName headerName, + Function delayParser) { + String headerValue = headers.getValue(headerName); + + return CoreUtils.isNullOrEmpty(headerValue) ? null : delayParser.apply(headerValue); + } + + private static Duration tryParseLongOrDateTime(String value, Supplier nowSupplier) { + long delaySeconds; + try { + OffsetDateTime retryAfter = new DateTimeRfc1123(value).getDateTime(); + + delaySeconds = nowSupplier.get().until(retryAfter, ChronoUnit.SECONDS); + } catch (DateTimeException ex) { + delaySeconds = tryParseLong(value); + } + + return (delaySeconds >= 0) ? Duration.ofSeconds(delaySeconds) : null; + } + + private static long tryParseLong(String value) { + try { + return Long.parseLong(value); + } catch (NumberFormatException ex) { + return -1; + } + } + + private static Duration tryGetDelayMillis(String value) { + long delayMillis = tryParseLong(value); + return (delayMillis >= 0) ? Duration.ofMillis(delayMillis) : null; + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/SyncOperationLocationPollingStrategy.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/SyncOperationLocationPollingStrategy.java new file mode 100644 index 000000000000..7936058d260e --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/SyncOperationLocationPollingStrategy.java @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.implementation; + +import com.azure.core.exception.AzureException; +import com.azure.core.http.HttpHeader; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollResponse; +import com.azure.core.util.polling.PollingContext; +import com.azure.core.util.polling.PollingStrategyOptions; +import com.azure.core.util.polling.SyncOperationResourcePollingStrategy; +import com.azure.core.util.serializer.JsonSerializerProviders; +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.core.util.serializer.TypeReference; +import java.io.UncheckedIOException; +import java.time.Duration; +import java.time.OffsetDateTime; +import java.util.Map; + +// DO NOT modify this helper class + +/** + * Implements a synchronous operation location polling strategy, from Operation-Location. + * + * @param the type of the response type from a polling call, or BinaryData if raw response body should be kept + * @param the type of the final result object to deserialize into, or BinaryData if raw response body should be + * kept + */ +public final class SyncOperationLocationPollingStrategy extends SyncOperationResourcePollingStrategy { + + private static final ClientLogger LOGGER = new ClientLogger(SyncOperationLocationPollingStrategy.class); + + private final ObjectSerializer serializer; + private final String endpoint; + private final String propertyName; + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public SyncOperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions) { + this(pollingStrategyOptions, null); + } + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @param propertyName the name of the property to extract final result. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public SyncOperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions, String propertyName) { + super(PollingUtils.OPERATION_LOCATION_HEADER, pollingStrategyOptions); + this.propertyName = propertyName; + this.endpoint = pollingStrategyOptions.getEndpoint(); + this.serializer = pollingStrategyOptions.getSerializer() != null + ? pollingStrategyOptions.getSerializer() + : JsonSerializerProviders.createInstance(true); + } + + /** + * {@inheritDoc} + */ + @Override + public PollResponse onInitialResponse(Response response, PollingContext pollingContext, + TypeReference pollResponseType) { + // Response is Response + + HttpHeader operationLocationHeader = response.getHeaders().get(PollingUtils.OPERATION_LOCATION_HEADER); + if (operationLocationHeader != null) { + pollingContext.setData(PollingUtils.OPERATION_LOCATION_HEADER.getCaseSensitiveName(), + PollingUtils.getAbsolutePath(operationLocationHeader.getValue(), endpoint, LOGGER)); + } + final String httpMethod = response.getRequest().getHttpMethod().name(); + pollingContext.setData(PollingUtils.HTTP_METHOD, httpMethod); + pollingContext.setData(PollingUtils.REQUEST_URL, response.getRequest().getUrl().toString()); + + if (response.getStatusCode() == 200 + || response.getStatusCode() == 201 + || response.getStatusCode() == 202 + || response.getStatusCode() == 204) { + final Duration retryAfter + = PollingUtils.getRetryAfterFromHeaders(response.getHeaders(), OffsetDateTime::now); + T initialResponseType = null; + try { + initialResponseType = PollingUtils.deserializeResponseSync((BinaryData) response.getValue(), serializer, + pollResponseType); + } catch (UncheckedIOException e) { + LOGGER.info("Failed to parse initial response."); + } + return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS, initialResponseType, retryAfter); + } + + throw LOGGER.logExceptionAsError(new AzureException( + String.format("Operation failed or cancelled with status code %d, '%s' header: %s, and response body: %s", + response.getStatusCode(), PollingUtils.OPERATION_LOCATION_HEADER, operationLocationHeader, + response.getValue()))); + } + + /** + * {@inheritDoc} + */ + public U getResult(PollingContext pollingContext, TypeReference resultType) { + if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.FAILED) { + throw LOGGER.logExceptionAsError(new AzureException("Long running operation failed.")); + } else if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.USER_CANCELLED) { + throw LOGGER.logExceptionAsError(new AzureException("Long running operation cancelled.")); + } + if (propertyName != null) { + // take the last poll response body from PollingContext, + // and de-serialize the property as final result + BinaryData latestResponseBody + = BinaryData.fromString(pollingContext.getData(PollingUtils.POLL_RESPONSE_BODY)); + Map pollResult = PollingUtils.deserializeResponseSync(latestResponseBody, serializer, + PollingUtils.POST_POLL_RESULT_TYPE_REFERENCE); + if (pollResult != null && pollResult.get(propertyName) != null) { + return PollingUtils.deserializeResponseSync(BinaryData.fromObject(pollResult.get(propertyName)), + serializer, resultType); + } else { + throw LOGGER.logExceptionAsError(new AzureException("Cannot get final result")); + } + } else { + return super.getResult(pollingContext, resultType); + } + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/TrustedSigningClientImpl.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/TrustedSigningClientImpl.java new file mode 100644 index 000000000000..66a49677f402 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/TrustedSigningClientImpl.java @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.implementation; + +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +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.developer.trustedsigning.TrustedSigningServiceVersion; + +/** + * Initializes a new instance of the TrustedSigningClient type. + */ +public final class TrustedSigningClientImpl { + /** + * The Azure Trusted signing service endpoint. + */ + private final String endpoint; + + /** + * Gets The Azure Trusted signing service endpoint. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Service version. + */ + private final TrustedSigningServiceVersion serviceVersion; + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public TrustedSigningServiceVersion 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 CertificateProfileOperationsImpl object to access its operations. + */ + private final CertificateProfileOperationsImpl certificateProfileOperations; + + /** + * Gets the CertificateProfileOperationsImpl object to access its operations. + * + * @return the CertificateProfileOperationsImpl object. + */ + public CertificateProfileOperationsImpl getCertificateProfileOperations() { + return this.certificateProfileOperations; + } + + /** + * Initializes an instance of TrustedSigningClient client. + * + * @param endpoint The Azure Trusted signing service endpoint. + * @param serviceVersion Service version. + */ + public TrustedSigningClientImpl(String endpoint, TrustedSigningServiceVersion serviceVersion) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of TrustedSigningClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint The Azure Trusted signing service endpoint. + * @param serviceVersion Service version. + */ + public TrustedSigningClientImpl(HttpPipeline httpPipeline, String endpoint, + TrustedSigningServiceVersion serviceVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of TrustedSigningClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint The Azure Trusted signing service endpoint. + * @param serviceVersion Service version. + */ + public TrustedSigningClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, + TrustedSigningServiceVersion serviceVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.serviceVersion = serviceVersion; + this.certificateProfileOperations = new CertificateProfileOperationsImpl(this); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/package-info.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/package-info.java new file mode 100644 index 000000000000..e88d3fc454a6 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/implementation/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the implementations for TrustedSigning. + * Azure Trusted Signing is a service that provides managed artifact signing for all. + */ +package com.azure.developer.trustedsigning.implementation; diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/ExtendedKeyUsage.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/ExtendedKeyUsage.java new file mode 100644 index 000000000000..5219431daed6 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/ExtendedKeyUsage.java @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Extended key usage object identifier that are allowable. + */ +@Immutable +public final class ExtendedKeyUsage implements JsonSerializable { + /* + * An oid string that represents an eku. + */ + @Generated + private String eku; + + /** + * Creates an instance of ExtendedKeyUsage class. + */ + @Generated + private ExtendedKeyUsage() { + } + + /** + * Get the eku property: An oid string that represents an eku. + * + * @return the eku value. + */ + @Generated + public String getEku() { + return this.eku; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ExtendedKeyUsage from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ExtendedKeyUsage if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the ExtendedKeyUsage. + */ + @Generated + public static ExtendedKeyUsage fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ExtendedKeyUsage deserializedExtendedKeyUsage = new ExtendedKeyUsage(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("eku".equals(fieldName)) { + deserializedExtendedKeyUsage.eku = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedExtendedKeyUsage; + }); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/OperationState.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/OperationState.java new file mode 100644 index 000000000000..b3d927ab195d --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/OperationState.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Enum describing allowed operation states. + */ +public final class OperationState extends ExpandableStringEnum { + /** + * The operation has not started. + */ + @Generated + public static final OperationState NOT_STARTED = fromString("NotStarted"); + + /** + * The operation is in progress. + */ + @Generated + public static final OperationState RUNNING = fromString("Running"); + + /** + * The operation has completed successfully. + */ + @Generated + public static final OperationState SUCCEEDED = fromString("Succeeded"); + + /** + * The operation has failed. + */ + @Generated + public static final OperationState FAILED = fromString("Failed"); + + /** + * The operation has been canceled by the user. + */ + @Generated + public static final OperationState CANCELED = fromString("Canceled"); + + /** + * Creates a new instance of OperationState value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public OperationState() { + } + + /** + * Creates or finds a OperationState from its string representation. + * + * @param name a name to look for. + * @return the corresponding OperationState. + */ + @Generated + public static OperationState fromString(String name) { + return fromString(name, OperationState.class); + } + + /** + * Gets known OperationState values. + * + * @return known OperationState values. + */ + @Generated + public static Collection values() { + return values(OperationState.class); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/OperationStatusSignResultError.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/OperationStatusSignResultError.java new file mode 100644 index 000000000000..d9b9a0d80558 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/OperationStatusSignResultError.java @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.core.models.ResponseError; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Provides status details for long running operations. + */ +@Immutable +public final class OperationStatusSignResultError implements JsonSerializable { + /* + * The unique ID of the operation. + */ + @Generated + private final String id; + + /* + * The status of the operation + */ + @Generated + private final OperationState status; + + /* + * Error object that describes the error when status is "Failed". + */ + @Generated + private ResponseError error; + + /* + * The result of the operation. + */ + @Generated + private SignResult result; + + /** + * Creates an instance of OperationStatusSignResultError class. + * + * @param id the id value to set. + * @param status the status value to set. + */ + @Generated + private OperationStatusSignResultError(String id, OperationState status) { + this.id = id; + this.status = status; + } + + /** + * Get the id property: The unique ID of the operation. + * + * @return the id value. + */ + @Generated + public String getId() { + return this.id; + } + + /** + * Get the status property: The status of the operation. + * + * @return the status value. + */ + @Generated + public OperationState getStatus() { + return this.status; + } + + /** + * Get the error property: Error object that describes the error when status is "Failed". + * + * @return the error value. + */ + @Generated + public ResponseError getError() { + return this.error; + } + + /** + * Get the result property: The result of the operation. + * + * @return the result value. + */ + @Generated + public SignResult getResult() { + return this.result; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("status", this.status == null ? null : this.status.toString()); + jsonWriter.writeJsonField("error", this.error); + jsonWriter.writeJsonField("result", this.result); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationStatusSignResultError from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationStatusSignResultError if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the OperationStatusSignResultError. + */ + @Generated + public static OperationStatusSignResultError fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String id = null; + OperationState status = null; + ResponseError error = null; + SignResult result = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + id = reader.getString(); + } else if ("status".equals(fieldName)) { + status = OperationState.fromString(reader.getString()); + } else if ("error".equals(fieldName)) { + error = ResponseError.fromJson(reader); + } else if ("result".equals(fieldName)) { + result = SignResult.fromJson(reader); + } else { + reader.skipChildren(); + } + } + OperationStatusSignResultError deserializedOperationStatusSignResultError + = new OperationStatusSignResultError(id, status); + deserializedOperationStatusSignResultError.error = error; + deserializedOperationStatusSignResultError.result = result; + + return deserializedOperationStatusSignResultError; + }); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SignResult.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SignResult.java new file mode 100644 index 000000000000..0d9b104a5503 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SignResult.java @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.core.util.CoreUtils; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The sign status model. + */ +@Immutable +public final class SignResult implements JsonSerializable { + /* + * Digital signature of the requested content digest. + */ + @Generated + private byte[] signature; + + /* + * Signing certificate corresponding to the private key used to sign the requested + * digest. + */ + @Generated + private byte[] signingCertificate; + + /** + * Creates an instance of SignResult class. + */ + @Generated + private SignResult() { + } + + /** + * Get the signature property: Digital signature of the requested content digest. + * + * @return the signature value. + */ + @Generated + public byte[] getSignature() { + return CoreUtils.clone(this.signature); + } + + /** + * Get the signingCertificate property: Signing certificate corresponding to the private key used to sign the + * requested + * digest. + * + * @return the signingCertificate value. + */ + @Generated + public byte[] getSigningCertificate() { + return CoreUtils.clone(this.signingCertificate); + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeBinaryField("signature", this.signature); + jsonWriter.writeBinaryField("signingCertificate", this.signingCertificate); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SignResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SignResult if the JsonReader was pointing to an instance of it, or null if it was pointing + * to JSON null. + * @throws IOException If an error occurs while reading the SignResult. + */ + @Generated + public static SignResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SignResult deserializedSignResult = new SignResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("signature".equals(fieldName)) { + deserializedSignResult.signature = reader.getBinary(); + } else if ("signingCertificate".equals(fieldName)) { + deserializedSignResult.signingCertificate = reader.getBinary(); + } else { + reader.skipChildren(); + } + } + + return deserializedSignResult; + }); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SignatureAlgorithm.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SignatureAlgorithm.java new file mode 100644 index 000000000000..4245d917fe3b --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SignatureAlgorithm.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Algorithms supported for signing. + */ +public final class SignatureAlgorithm extends ExpandableStringEnum { + /** + * RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm RS256 = fromString("RS256"); + + /** + * RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm RS384 = fromString("RS384"); + + /** + * RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm RS512 = fromString("RS512"); + + /** + * RSASSA-PSS using SHA-256 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm PS256 = fromString("PS256"); + + /** + * RSASSA-PSS using SHA-384 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm PS384 = fromString("PS384"); + + /** + * RSASSA-PSS using SHA-512 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm PS512 = fromString("PS512"); + + /** + * ECDSA using P-256 and SHA-256 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm ES256 = fromString("ES256"); + + /** + * ECDSA using P-384 and SHA-384 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm ES384 = fromString("ES384"); + + /** + * ECDSA using P-521 and SHA-512 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm ES512 = fromString("ES512"); + + /** + * ECDSA using secp256k1 and SHA-256 hash algorithm. + */ + @Generated + public static final SignatureAlgorithm ES256K = fromString("ES256K"); + + /** + * Creates a new instance of SignatureAlgorithm value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public SignatureAlgorithm() { + } + + /** + * Creates or finds a SignatureAlgorithm from its string representation. + * + * @param name a name to look for. + * @return the corresponding SignatureAlgorithm. + */ + @Generated + public static SignatureAlgorithm fromString(String name) { + return fromString(name, SignatureAlgorithm.class); + } + + /** + * Gets known SignatureAlgorithm values. + * + * @return known SignatureAlgorithm values. + */ + @Generated + public static Collection values() { + return values(SignatureAlgorithm.class); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SigningPayloadOptions.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SigningPayloadOptions.java new file mode 100644 index 000000000000..3416dccb8c39 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/SigningPayloadOptions.java @@ -0,0 +1,178 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.core.util.CoreUtils; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; + +/** + * The artifact request information to be signed by the service. + */ +@Fluent +public final class SigningPayloadOptions implements JsonSerializable { + /* + * The supported signature algorithm identifiers. + */ + @Generated + private final SignatureAlgorithm signatureAlgorithm; + + /* + * Content digest to sign. + */ + @Generated + private final byte[] digest; + + /* + * List of full file digital signatures. + */ + @Generated + private List fileHashList; + + /* + * List of authenticode digital signatures. + */ + @Generated + private List authenticodeHashList; + + /** + * Creates an instance of SigningPayloadOptions class. + * + * @param signatureAlgorithm the signatureAlgorithm value to set. + * @param digest the digest value to set. + */ + @Generated + public SigningPayloadOptions(SignatureAlgorithm signatureAlgorithm, byte[] digest) { + this.signatureAlgorithm = signatureAlgorithm; + this.digest = digest; + } + + /** + * Get the signatureAlgorithm property: The supported signature algorithm identifiers. + * + * @return the signatureAlgorithm value. + */ + @Generated + public SignatureAlgorithm getSignatureAlgorithm() { + return this.signatureAlgorithm; + } + + /** + * Get the digest property: Content digest to sign. + * + * @return the digest value. + */ + @Generated + public byte[] getDigest() { + return CoreUtils.clone(this.digest); + } + + /** + * Get the fileHashList property: List of full file digital signatures. + * + * @return the fileHashList value. + */ + @Generated + public List getFileHashList() { + return this.fileHashList; + } + + /** + * Set the fileHashList property: List of full file digital signatures. + * + * @param fileHashList the fileHashList value to set. + * @return the SigningPayloadOptions object itself. + */ + @Generated + public SigningPayloadOptions setFileHashList(List fileHashList) { + this.fileHashList = fileHashList; + return this; + } + + /** + * Get the authenticodeHashList property: List of authenticode digital signatures. + * + * @return the authenticodeHashList value. + */ + @Generated + public List getAuthenticodeHashList() { + return this.authenticodeHashList; + } + + /** + * Set the authenticodeHashList property: List of authenticode digital signatures. + * + * @param authenticodeHashList the authenticodeHashList value to set. + * @return the SigningPayloadOptions object itself. + */ + @Generated + public SigningPayloadOptions setAuthenticodeHashList(List authenticodeHashList) { + this.authenticodeHashList = authenticodeHashList; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("signatureAlgorithm", + this.signatureAlgorithm == null ? null : this.signatureAlgorithm.toString()); + jsonWriter.writeBinaryField("digest", this.digest); + jsonWriter.writeArrayField("fileHashList", this.fileHashList, (writer, element) -> writer.writeBinary(element)); + jsonWriter.writeArrayField("authenticodeHashList", this.authenticodeHashList, + (writer, element) -> writer.writeBinary(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SigningPayloadOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SigningPayloadOptions if the JsonReader was pointing to an instance of it, or null if it + * was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the SigningPayloadOptions. + */ + @Generated + public static SigningPayloadOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SignatureAlgorithm signatureAlgorithm = null; + byte[] digest = null; + List fileHashList = null; + List authenticodeHashList = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("signatureAlgorithm".equals(fieldName)) { + signatureAlgorithm = SignatureAlgorithm.fromString(reader.getString()); + } else if ("digest".equals(fieldName)) { + digest = reader.getBinary(); + } else if ("fileHashList".equals(fieldName)) { + fileHashList = reader.readArray(reader1 -> reader1.getBinary()); + } else if ("authenticodeHashList".equals(fieldName)) { + authenticodeHashList = reader.readArray(reader1 -> reader1.getBinary()); + } else { + reader.skipChildren(); + } + } + SigningPayloadOptions deserializedSigningPayloadOptions + = new SigningPayloadOptions(signatureAlgorithm, digest); + deserializedSigningPayloadOptions.fileHashList = fileHashList; + deserializedSigningPayloadOptions.authenticodeHashList = authenticodeHashList; + + return deserializedSigningPayloadOptions; + }); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/package-info.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/package-info.java new file mode 100644 index 000000000000..ccd653262ab0 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the data models for TrustedSigning. + * Azure Trusted Signing is a service that provides managed artifact signing for all. + */ +package com.azure.developer.trustedsigning.models; diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/package-info.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/package-info.java new file mode 100644 index 000000000000..fe975c454d71 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/com/azure/developer/trustedsigning/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the classes for TrustedSigning. + * Azure Trusted Signing is a service that provides managed artifact signing for all. + */ +package com.azure.developer.trustedsigning; diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/java/module-info.java b/sdk/developer/azure-developer-trustedsigning/src/main/java/module-info.java new file mode 100644 index 000000000000..f21f1f7c092c --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/java/module-info.java @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +module com.azure.developer.trustedsigning { + requires transitive com.azure.core; + + exports com.azure.developer.trustedsigning; + exports com.azure.developer.trustedsigning.models; + + opens com.azure.developer.trustedsigning.models to com.azure.core; +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/resources/META-INF/azure-developer-trustedsigning_apiview_properties.json b/sdk/developer/azure-developer-trustedsigning/src/main/resources/META-INF/azure-developer-trustedsigning_apiview_properties.json new file mode 100644 index 000000000000..a039e9c65e32 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/resources/META-INF/azure-developer-trustedsigning_apiview_properties.json @@ -0,0 +1,28 @@ +{ + "flavor": "azure", + "CrossLanguageDefinitionId": { + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient": "Azure.Developer.TrustedSigning.CertificateProfileOperations", + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient.beginSign": "Azure.Developer.TrustedSigning.CertificateProfileOperations.sign", + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient.beginSignWithModel": "Azure.Developer.TrustedSigning.CertificateProfileOperations.sign", + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient.getSignRootCertificate": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSignRootCertificate", + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient.getSignRootCertificateWithResponse": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSignRootCertificate", + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient.getSigningStatus": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSigningStatus", + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient.getSigningStatusWithResponse": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSigningStatus", + "com.azure.developer.trustedsigning.TrustedSigningAsyncClient.listExtendedKeyUsages": "Azure.Developer.TrustedSigning.CertificateProfileOperations.listExtendedKeyUsages", + "com.azure.developer.trustedsigning.TrustedSigningClient": "Azure.Developer.TrustedSigning.CertificateProfileOperations", + "com.azure.developer.trustedsigning.TrustedSigningClient.beginSign": "Azure.Developer.TrustedSigning.CertificateProfileOperations.sign", + "com.azure.developer.trustedsigning.TrustedSigningClient.beginSignWithModel": "Azure.Developer.TrustedSigning.CertificateProfileOperations.sign", + "com.azure.developer.trustedsigning.TrustedSigningClient.getSignRootCertificate": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSignRootCertificate", + "com.azure.developer.trustedsigning.TrustedSigningClient.getSignRootCertificateWithResponse": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSignRootCertificate", + "com.azure.developer.trustedsigning.TrustedSigningClient.getSigningStatus": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSigningStatus", + "com.azure.developer.trustedsigning.TrustedSigningClient.getSigningStatusWithResponse": "Azure.Developer.TrustedSigning.CertificateProfileOperations.getSigningStatus", + "com.azure.developer.trustedsigning.TrustedSigningClient.listExtendedKeyUsages": "Azure.Developer.TrustedSigning.CertificateProfileOperations.listExtendedKeyUsages", + "com.azure.developer.trustedsigning.TrustedSigningClientBuilder": "Azure.Developer.TrustedSigning", + "com.azure.developer.trustedsigning.models.ExtendedKeyUsage": "Azure.Developer.TrustedSigning.ExtendedKeyUsage", + "com.azure.developer.trustedsigning.models.OperationState": "Azure.Core.Foundations.OperationState", + "com.azure.developer.trustedsigning.models.OperationStatusSignResultError": "Azure.Core.Foundations.OperationStatus", + "com.azure.developer.trustedsigning.models.SignResult": "Azure.Developer.TrustedSigning.SignResult", + "com.azure.developer.trustedsigning.models.SignatureAlgorithm": "Azure.Developer.TrustedSigning.SignatureAlgorithm", + "com.azure.developer.trustedsigning.models.SigningPayloadOptions": "Azure.Developer.TrustedSigning.SigningPayloadOptions" + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/main/resources/azure-developer-trustedsigning.properties b/sdk/developer/azure-developer-trustedsigning/src/main/resources/azure-developer-trustedsigning.properties new file mode 100644 index 000000000000..ca812989b4f2 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/main/resources/azure-developer-trustedsigning.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/ReadmeSamples.java b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/ReadmeSamples.java new file mode 100644 index 000000000000..8988d2235c9f --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/ReadmeSamples.java @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning; + +public final class ReadmeSamples { + public void readmeSamples() { + // BEGIN: com.azure.developer.trustedsigning.readme + // END: com.azure.developer.trustedsigning.readme + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowed.java b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowed.java new file mode 100644 index 000000000000..cc1b86d4fd63 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowed.java @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Configuration; +import com.azure.developer.trustedsigning.TrustedSigningClient; +import com.azure.developer.trustedsigning.TrustedSigningClientBuilder; +import com.azure.developer.trustedsigning.models.ExtendedKeyUsage; +import com.azure.identity.DefaultAzureCredentialBuilder; + +public class GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowed { + public static void main(String[] args) { + TrustedSigningClient trustedSigningClient + = new TrustedSigningClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.developer.trustedsigning.generated.certificateprofileoperationslistextendedkeyusages.getsalistofextendedkeyusageobjectidentifiersthatareallowed + PagedIterable response + = trustedSigningClient.listExtendedKeyUsages("YourAccountName", "YourCertificateProfileName"); + // END:com.azure.developer.trustedsigning.generated.certificateprofileoperationslistextendedkeyusages.getsalistofextendedkeyusageobjectidentifiersthatareallowed + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileName.java b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileName.java new file mode 100644 index 000000000000..3c10868acb7e --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileName.java @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.core.util.BinaryData; +import com.azure.core.util.Configuration; +import com.azure.developer.trustedsigning.TrustedSigningClient; +import com.azure.developer.trustedsigning.TrustedSigningClientBuilder; +import com.azure.identity.DefaultAzureCredentialBuilder; + +public class GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileName { + public static void main(String[] args) { + TrustedSigningClient trustedSigningClient + = new TrustedSigningClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.developer.trustedsigning.generated.certificateprofileoperationsgetsignrootcertificate.getsthecodesigningrootcertificateonthecertificatechainforthataccountandprofilename + BinaryData response + = trustedSigningClient.getSignRootCertificate("YourAccountName", "YourCertificateProfileName"); + // END:com.azure.developer.trustedsigning.generated.certificateprofileoperationsgetsignrootcertificate.getsthecodesigningrootcertificateonthecertificatechainforthataccountandprofilename + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsTheStatusOfACodesignOperation.java b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsTheStatusOfACodesignOperation.java new file mode 100644 index 000000000000..531a8e33069a --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/GetsTheStatusOfACodesignOperation.java @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.core.util.Configuration; +import com.azure.developer.trustedsigning.TrustedSigningClient; +import com.azure.developer.trustedsigning.TrustedSigningClientBuilder; +import com.azure.developer.trustedsigning.models.OperationStatusSignResultError; +import com.azure.identity.DefaultAzureCredentialBuilder; + +public class GetsTheStatusOfACodesignOperation { + public static void main(String[] args) { + TrustedSigningClient trustedSigningClient + = new TrustedSigningClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.developer.trustedsigning.generated.certificateprofileoperationsgetsigningstatus.getsthestatusofacodesignoperation + OperationStatusSignResultError response = trustedSigningClient.getSigningStatus("YourAccountName", + "YourCertificateProfileName", "9797c668-5b3c-4586-8e0c-2768c8160bad"); + // END:com.azure.developer.trustedsigning.generated.certificateprofileoperationsgetsigningstatus.getsthestatusofacodesignoperation + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/SubmitACodesignOperation.java b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/SubmitACodesignOperation.java new file mode 100644 index 000000000000..0c2aee535911 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/samples/java/com/azure/developer/trustedsigning/generated/SubmitACodesignOperation.java @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.core.util.Configuration; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; +import com.azure.developer.trustedsigning.TrustedSigningClient; +import com.azure.developer.trustedsigning.TrustedSigningClientBuilder; +import com.azure.developer.trustedsigning.models.SignResult; +import com.azure.developer.trustedsigning.models.SignatureAlgorithm; +import com.azure.developer.trustedsigning.models.SigningPayloadOptions; +import com.azure.identity.DefaultAzureCredentialBuilder; +import java.util.Arrays; + +public class SubmitACodesignOperation { + public static void main(String[] args) { + TrustedSigningClient trustedSigningClient + = new TrustedSigningClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.developer.trustedsigning.generated.certificateprofileoperationssign.submitacodesignoperation + SyncPoller response + = trustedSigningClient.beginSign("YourAccountName", "YourCertificateProfileName", + new SigningPayloadOptions(SignatureAlgorithm.RS256, "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=".getBytes()) + .setFileHashList(Arrays.asList("Y29uc2VjdGV0dXIgYWRpcGlzY2luZyBlbGl0".getBytes(), + "c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQ=".getBytes())) + .setAuthenticodeHashList(Arrays.asList("dXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlxdWE=".getBytes(), + "IFV0IGVuaW0gYWQgbWluaW0gdmVuaWFt".getBytes())), + "serviceName@1.0.0.0", "9797c668-5b3c-4586-8e0c-2768c8160bad"); + // END:com.azure.developer.trustedsigning.generated.certificateprofileoperationssign.submitacodesignoperation + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowedTests.java b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowedTests.java new file mode 100644 index 000000000000..f10ff9835dee --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowedTests.java @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.developer.trustedsigning.models.ExtendedKeyUsage; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class GetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowedTests + extends TrustedSigningClientTestBase { + @Test + @Disabled + public void testGetsAListOfExtendedKeyUsageObjectIdentifiersThatAreAllowedTests() { + // method invocation + PagedIterable response + = trustedSigningClient.listExtendedKeyUsages("YourAccountName", "YourCertificateProfileName"); + + // response assertion + Assertions.assertEquals(200, response.iterableByPage().iterator().next().getStatusCode()); + ExtendedKeyUsage firstItem = response.iterator().next(); + Assertions.assertNotNull(firstItem); + // verify property "eku" + Assertions.assertEquals("1.3.6.1.5.5.7.3.8", firstItem.getEku()); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileNameTests.java b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileNameTests.java new file mode 100644 index 000000000000..ee1ec4f42e6f --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileNameTests.java @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.core.util.BinaryData; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class GetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileNameTests + extends TrustedSigningClientTestBase { + @Test + @Disabled + public void testGetsTheCodesigningRootCertificateOnTheCertificateChainForThatAccountAndProfileNameTests() { + // method invocation + BinaryData response + = trustedSigningClient.getSignRootCertificate("YourAccountName", "YourCertificateProfileName"); + + // response assertion + Assertions.assertNotNull(response); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsTheStatusOfACodesignOperationTests.java b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsTheStatusOfACodesignOperationTests.java new file mode 100644 index 000000000000..7136e42b7af9 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/GetsTheStatusOfACodesignOperationTests.java @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.developer.trustedsigning.models.OperationState; +import com.azure.developer.trustedsigning.models.OperationStatusSignResultError; +import com.azure.developer.trustedsigning.models.SignResult; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class GetsTheStatusOfACodesignOperationTests extends TrustedSigningClientTestBase { + @Test + @Disabled + public void testGetsTheStatusOfACodesignOperationTests() { + // method invocation + OperationStatusSignResultError response = trustedSigningClient.getSigningStatus("YourAccountName", + "YourCertificateProfileName", "9797c668-5b3c-4586-8e0c-2768c8160bad"); + + // response assertion + Assertions.assertNotNull(response); + // verify property "id" + Assertions.assertEquals("76f60a30-d088-42e0-b16d-b76b88d3cbe1", response.getId()); + // verify property "status" + Assertions.assertEquals(OperationState.SUCCEEDED, response.getStatus()); + // verify property "result" + SignResult responseResult = response.getResult(); + Assertions.assertNotNull(responseResult); + Assertions.assertNotNull(responseResult.getSignature()); + Assertions.assertNotNull(responseResult.getSigningCertificate()); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/SubmitACodesignOperationTests.java b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/SubmitACodesignOperationTests.java new file mode 100644 index 000000000000..be868cc791e9 --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/SubmitACodesignOperationTests.java @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; +import com.azure.developer.trustedsigning.models.SignResult; +import com.azure.developer.trustedsigning.models.SignatureAlgorithm; +import com.azure.developer.trustedsigning.models.SigningPayloadOptions; +import java.util.Arrays; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class SubmitACodesignOperationTests extends TrustedSigningClientTestBase { + @Test + @Disabled + public void testSubmitACodesignOperationTests() { + // method invocation + SyncPoller response = setPlaybackSyncPollerPollInterval( + trustedSigningClient.beginSign("YourAccountName", "YourCertificateProfileName", + new SigningPayloadOptions(SignatureAlgorithm.RS256, "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=".getBytes()) + .setFileHashList(Arrays.asList("Y29uc2VjdGV0dXIgYWRpcGlzY2luZyBlbGl0".getBytes(), + "c2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQ=".getBytes())) + .setAuthenticodeHashList(Arrays.asList("dXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlxdWE=".getBytes(), + "IFV0IGVuaW0gYWQgbWluaW0gdmVuaWFt".getBytes())), + "serviceName@1.0.0.0", "9797c668-5b3c-4586-8e0c-2768c8160bad")); + + // response assertion + Assertions.assertEquals(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, + response.waitForCompletion().getStatus()); + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/TrustedSigningClientTestBase.java b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/TrustedSigningClientTestBase.java new file mode 100644 index 000000000000..0f834c3f7b2e --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/src/test/java/com/azure/developer/trustedsigning/generated/TrustedSigningClientTestBase.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.developer.trustedsigning.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestMode; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.test.utils.MockTokenCredential; +import com.azure.core.util.Configuration; +import com.azure.developer.trustedsigning.TrustedSigningClient; +import com.azure.developer.trustedsigning.TrustedSigningClientBuilder; +import com.azure.identity.DefaultAzureCredentialBuilder; + +class TrustedSigningClientTestBase extends TestProxyTestBase { + protected TrustedSigningClient trustedSigningClient; + + @Override + protected void beforeTest() { + TrustedSigningClientBuilder trustedSigningClientbuilder = new TrustedSigningClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.PLAYBACK) { + trustedSigningClientbuilder.credential(new MockTokenCredential()); + } else if (getTestMode() == TestMode.RECORD) { + trustedSigningClientbuilder.addPolicy(interceptorManager.getRecordPolicy()) + .credential(new DefaultAzureCredentialBuilder().build()); + } else if (getTestMode() == TestMode.LIVE) { + trustedSigningClientbuilder.credential(new DefaultAzureCredentialBuilder().build()); + } + trustedSigningClient = trustedSigningClientbuilder.buildClient(); + + } +} diff --git a/sdk/developer/azure-developer-trustedsigning/tsp-location.yaml b/sdk/developer/azure-developer-trustedsigning/tsp-location.yaml new file mode 100644 index 000000000000..67314089072c --- /dev/null +++ b/sdk/developer/azure-developer-trustedsigning/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/trustedsigning/TrustedSigning +commit: 65ea9a38c20488eb047876e4207713aa4a392f82 +repo: Azure/azure-rest-api-specs +additionalDirectories: diff --git a/sdk/developer/ci.yml b/sdk/developer/ci.yml new file mode 100644 index 000000000000..b5573e1d04e3 --- /dev/null +++ b/sdk/developer/ci.yml @@ -0,0 +1,46 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. + +trigger: + branches: + include: + - main + - hotfix/* + - release/* + paths: + include: + - sdk/developer/ci.yml + - sdk/developer/azure-developer-trustedsigning/ + exclude: + - sdk/developer/pom.xml + - sdk/developer/azure-developer-trustedsigning/pom.xml + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/developer/ci.yml + - sdk/developer/azure-developer-trustedsigning/ + exclude: + - sdk/developer/pom.xml + - sdk/developer/azure-developer-trustedsigning/pom.xml + +parameters: + - name: release_azuredevelopertrustedsigning + displayName: azure-developer-trustedsigning + type: boolean + default: true + +extends: + template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: developer + Artifacts: + - name: azure-developer-trustedsigning + groupId: com.azure + safeName: azuredevelopertrustedsigning + releaseInBatch: ${{ parameters.release_azuredevelopertrustedsigning }} diff --git a/sdk/developer/pom.xml b/sdk/developer/pom.xml new file mode 100644 index 000000000000..1334f1beb6c8 --- /dev/null +++ b/sdk/developer/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + com.azure + azure-developer-service + pom + 1.0.0 + + + azure-developer-trustedsigning + +