Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions azure-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@
package com.microsoft.azure.batch;

import com.microsoft.azure.PagedList;
import com.microsoft.azure.batch.protocol.models.*;
import com.microsoft.azure.batch.protocol.models.BatchErrorException;
import com.microsoft.azure.batch.protocol.models.Certificate;
import com.microsoft.azure.batch.protocol.models.CertificateAddOptions;
import com.microsoft.azure.batch.protocol.models.CertificateAddParameter;
import com.microsoft.azure.batch.protocol.models.CertificateCancelDeletionOptions;
import com.microsoft.azure.batch.protocol.models.CertificateDeleteOptions;
import com.microsoft.azure.batch.protocol.models.CertificateFormat;
import com.microsoft.azure.batch.protocol.models.CertificateGetHeaders;
import com.microsoft.azure.batch.protocol.models.CertificateGetOptions;
import com.microsoft.azure.batch.protocol.models.CertificateListHeaders;
import com.microsoft.azure.batch.protocol.models.CertificateListOptions;
import com.microsoft.rest.ServiceResponseWithHeaders;
import org.apache.commons.codec.binary.Base64;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -18,7 +29,6 @@
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Base64;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -80,7 +90,7 @@ public void createCertificate(InputStream certStream, Iterable<BatchClientBehavi
addParam.setCertificateFormat(CertificateFormat.CER);
addParam.setThumbprintAlgorithm(SHA1_CERTIFICATE_ALGORITHM);
addParam.setThumbprint(getThumbPrint(cert));
addParam.setData(Base64.getEncoder().encodeToString(cert.getEncoded()));
addParam.setData(Base64.encodeBase64String(cert.getEncoded()));

createCertificate(addParam, additionalBehaviors);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
/**
* Copyright (c) Microsoft and contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.batch.protocol;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
/**
* Copyright (c) Microsoft and contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.batch.protocol;
Expand Down Expand Up @@ -107,42 +93,16 @@ public ServiceResponseWithHeaders<PagedList<ApplicationSummary>, ApplicationList
}
final ApplicationListOptions applicationListOptions = null;
Integer maxResults = null;
if (applicationListOptions != null) {
maxResults = applicationListOptions.getMaxResults();
}
Integer timeout = null;
if (applicationListOptions != null) {
timeout = applicationListOptions.getTimeout();
}
String clientRequestId = null;
if (applicationListOptions != null) {
clientRequestId = applicationListOptions.getClientRequestId();
}
Boolean returnClientRequestId = null;
if (applicationListOptions != null) {
returnClientRequestId = applicationListOptions.getReturnClientRequestId();
}
DateTime ocpDate = null;
if (applicationListOptions != null) {
ocpDate = applicationListOptions.getOcpDate();
}
DateTimeRfc1123 ocpDateConverted = null;
if (ocpDate != null) {
ocpDateConverted = new DateTimeRfc1123(ocpDate);
}
Call<ResponseBody> call = service.list(this.client.getApiVersion(), this.client.getAcceptLanguage(), maxResults, timeout, clientRequestId, returnClientRequestId, ocpDateConverted);
ServiceResponseWithHeaders<PageImpl<ApplicationSummary>, ApplicationListHeaders> response = listDelegate(call.execute());
PagedList<ApplicationSummary> result = new PagedList<ApplicationSummary>(response.getBody()) {
@Override
public Page<ApplicationSummary> nextPage(String nextPageLink) throws BatchErrorException, IOException {
ApplicationListNextOptions applicationListNextOptions = null;
if (applicationListOptions != null) {
applicationListNextOptions = new ApplicationListNextOptions();
applicationListNextOptions.setClientRequestId(applicationListOptions.getClientRequestId());
applicationListNextOptions.setReturnClientRequestId(applicationListOptions.getReturnClientRequestId());
applicationListNextOptions.setOcpDate(applicationListOptions.getOcpDate());
}
return listNext(nextPageLink, applicationListNextOptions).getBody();
return listNext(nextPageLink, null).getBody();
}
};
return new ServiceResponseWithHeaders<>(result, response.getHeaders(), response.getResponse());
Expand All @@ -165,29 +125,10 @@ public ServiceCall listAsync(final ListOperationCallback<ApplicationSummary> ser
}
final ApplicationListOptions applicationListOptions = null;
Integer maxResults = null;
if (applicationListOptions != null) {
maxResults = applicationListOptions.getMaxResults();
}
Integer timeout = null;
if (applicationListOptions != null) {
timeout = applicationListOptions.getTimeout();
}
String clientRequestId = null;
if (applicationListOptions != null) {
clientRequestId = applicationListOptions.getClientRequestId();
}
Boolean returnClientRequestId = null;
if (applicationListOptions != null) {
returnClientRequestId = applicationListOptions.getReturnClientRequestId();
}
DateTime ocpDate = null;
if (applicationListOptions != null) {
ocpDate = applicationListOptions.getOcpDate();
}
DateTimeRfc1123 ocpDateConverted = null;
if (ocpDate != null) {
ocpDateConverted = new DateTimeRfc1123(ocpDate);
}
Call<ResponseBody> call = service.list(this.client.getApiVersion(), this.client.getAcceptLanguage(), maxResults, timeout, clientRequestId, returnClientRequestId, ocpDateConverted);
final ServiceCall serviceCall = new ServiceCall(call);
call.enqueue(new ServiceResponseCallback<List<ApplicationSummary>>(serviceCallback) {
Expand All @@ -198,14 +139,7 @@ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
serviceCallback.load(result.getBody().getItems());
if (result.getBody().getNextPageLink() != null
&& serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) {
ApplicationListNextOptions applicationListNextOptions = null;
if (applicationListOptions != null) {
applicationListNextOptions = new ApplicationListNextOptions();
applicationListNextOptions.setClientRequestId(applicationListOptions.getClientRequestId());
applicationListNextOptions.setReturnClientRequestId(applicationListOptions.getReturnClientRequestId());
applicationListNextOptions.setOcpDate(applicationListOptions.getOcpDate());
}
listNextAsync(result.getBody().getNextPageLink(), applicationListNextOptions, serviceCall, serviceCallback);
listNextAsync(result.getBody().getNextPageLink(), null, serviceCall, serviceCallback);
} else {
serviceCallback.success(new ServiceResponseWithHeaders<>(serviceCallback.get(), result.getHeaders(), result.getResponse()));
}
Expand Down Expand Up @@ -368,25 +302,9 @@ public ServiceResponseWithHeaders<ApplicationSummary, ApplicationGetHeaders> get
}
final ApplicationGetOptions applicationGetOptions = null;
Integer timeout = null;
if (applicationGetOptions != null) {
timeout = applicationGetOptions.getTimeout();
}
String clientRequestId = null;
if (applicationGetOptions != null) {
clientRequestId = applicationGetOptions.getClientRequestId();
}
Boolean returnClientRequestId = null;
if (applicationGetOptions != null) {
returnClientRequestId = applicationGetOptions.getReturnClientRequestId();
}
DateTime ocpDate = null;
if (applicationGetOptions != null) {
ocpDate = applicationGetOptions.getOcpDate();
}
DateTimeRfc1123 ocpDateConverted = null;
if (ocpDate != null) {
ocpDateConverted = new DateTimeRfc1123(ocpDate);
}
Call<ResponseBody> call = service.get(applicationId, this.client.getApiVersion(), this.client.getAcceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted);
return getDelegate(call.execute());
}
Expand All @@ -413,25 +331,9 @@ public ServiceCall getAsync(String applicationId, final ServiceCallback<Applicat
}
final ApplicationGetOptions applicationGetOptions = null;
Integer timeout = null;
if (applicationGetOptions != null) {
timeout = applicationGetOptions.getTimeout();
}
String clientRequestId = null;
if (applicationGetOptions != null) {
clientRequestId = applicationGetOptions.getClientRequestId();
}
Boolean returnClientRequestId = null;
if (applicationGetOptions != null) {
returnClientRequestId = applicationGetOptions.getReturnClientRequestId();
}
DateTime ocpDate = null;
if (applicationGetOptions != null) {
ocpDate = applicationGetOptions.getOcpDate();
}
DateTimeRfc1123 ocpDateConverted = null;
if (ocpDate != null) {
ocpDateConverted = new DateTimeRfc1123(ocpDate);
}
Call<ResponseBody> call = service.get(applicationId, this.client.getApiVersion(), this.client.getAcceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted);
final ServiceCall serviceCall = new ServiceCall(call);
call.enqueue(new ServiceResponseCallback<ApplicationSummary>(serviceCallback) {
Expand Down Expand Up @@ -568,21 +470,8 @@ public ServiceResponseWithHeaders<PageImpl<ApplicationSummary>, ApplicationListH
}
final ApplicationListNextOptions applicationListNextOptions = null;
String clientRequestId = null;
if (applicationListNextOptions != null) {
clientRequestId = applicationListNextOptions.getClientRequestId();
}
Boolean returnClientRequestId = null;
if (applicationListNextOptions != null) {
returnClientRequestId = applicationListNextOptions.getReturnClientRequestId();
}
DateTime ocpDate = null;
if (applicationListNextOptions != null) {
ocpDate = applicationListNextOptions.getOcpDate();
}
DateTimeRfc1123 ocpDateConverted = null;
if (ocpDate != null) {
ocpDateConverted = new DateTimeRfc1123(ocpDate);
}
Call<ResponseBody> call = service.listNext(nextPageLink, this.client.getAcceptLanguage(), clientRequestId, returnClientRequestId, ocpDateConverted);
return listNextDelegate(call.execute());
}
Expand All @@ -606,21 +495,8 @@ public ServiceCall listNextAsync(final String nextPageLink, final ServiceCall se
}
final ApplicationListNextOptions applicationListNextOptions = null;
String clientRequestId = null;
if (applicationListNextOptions != null) {
clientRequestId = applicationListNextOptions.getClientRequestId();
}
Boolean returnClientRequestId = null;
if (applicationListNextOptions != null) {
returnClientRequestId = applicationListNextOptions.getReturnClientRequestId();
}
DateTime ocpDate = null;
if (applicationListNextOptions != null) {
ocpDate = applicationListNextOptions.getOcpDate();
}
DateTimeRfc1123 ocpDateConverted = null;
if (ocpDate != null) {
ocpDateConverted = new DateTimeRfc1123(ocpDate);
}
Call<ResponseBody> call = service.listNext(nextPageLink, this.client.getAcceptLanguage(), clientRequestId, returnClientRequestId, ocpDateConverted);
serviceCall.newCall(call);
call.enqueue(new ServiceResponseCallback<List<ApplicationSummary>>(serviceCallback) {
Expand All @@ -631,7 +507,7 @@ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
serviceCallback.load(result.getBody().getItems());
if (result.getBody().getNextPageLink() != null
&& serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) {
listNextAsync(result.getBody().getNextPageLink(), applicationListNextOptions, serviceCall, serviceCallback);
listNextAsync(result.getBody().getNextPageLink(), null, serviceCall, serviceCallback);
} else {
serviceCallback.success(new ServiceResponseWithHeaders<>(serviceCallback.get(), result.getHeaders(), result.getResponse()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@

package com.microsoft.azure.batch.protocol;

import com.microsoft.rest.DateTimeRfc1123;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.codec.binary.Base64;
import org.joda.time.DateTime;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.Response;
import org.joda.time.DateTime;

import com.microsoft.rest.DateTimeRfc1123;

public class BatchCredentialsInterceptor implements Interceptor {

/**
Expand Down Expand Up @@ -62,10 +60,10 @@ private String sign(String accessKey, String stringToSign) {
// Encoding the Signature
// Signature=Base64(HMAC-SHA256(UTF8(StringToSign)))
Mac hmac = Mac.getInstance("hmacSHA256");
hmac.init(new SecretKeySpec(Base64.getDecoder().decode(accessKey),
hmac.init(new SecretKeySpec(Base64.decodeBase64(accessKey),
"hmacSHA256"));
byte[] digest = hmac.doFinal(stringToSign.getBytes("UTF-8"));
return new String(Base64.getEncoder().encode(digest), "UTF-8");
return Base64.encodeBase64String(digest);
} catch (Exception e) {
throw new IllegalArgumentException("accessKey", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
/**
* Copyright (c) Microsoft and contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.batch.protocol;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
/**
* Copyright (c) Microsoft and contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.batch.protocol;
Expand Down
Loading