Fix Azure header datetime format
This fixes the occasional "403 Forbidden" bug that we have seen, simply because
the signature ends up being invalid due to an invalid datetime format used.
Issue:
Reference:
Use statically defined formatter and explain why
This closes
@@ -50,6 +50,9 @@ public abstract class AbstractAzureLogAnalyticsReportingTask extends AbstractRep
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final String HMAC_SHA256_ALG = "HmacSHA256";
+
+ // DateTimeFormatter.RFC_1123_DATE_TIME does not work in every case, such as when a
+ // two-digit day of month is always required, so we are defining our own formatter here.
private static final DateTimeFormatter RFC_1123_DATE_TIME = DateTimeFormatter
.ofPattern("EEE, dd MMM yyyy HH:mm:ss O");
@@ -136,7 +139,7 @@ public abstract class AbstractAzureLogAnalyticsReportingTask extends AbstractRep
final int bodyLength = rawJson.getBytes(UTF8).length;
final ZonedDateTime zNow = ZonedDateTime.now(ZoneOffset.UTC);
- final String nowRfc1123 = zNow.format(DateTimeFormatter.RFC_1123_DATE_TIME);
+ final String nowRfc1123 = zNow.format(RFC_1123_DATE_TIME);
final String nowISO8601 = zNow.format(DateTimeFormatter.ISO_DATE_TIME);
final String createAuthorization = createAuthorization(workspaceId, linuxPrimaryKey, bodyLength, nowRfc1123);
request.addHeader("Authorization", createAuthorization);
