Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,16 @@ export type AddConfigurationSettingOptions = ModelConfigurationClientCreateOrUpd
// @public (undocumented)
export type AddConfigurationSettingsResponse = ModelCreateOrUpdateConfigurationSettingResponse;

// @public (undocumented)
// @public
export class AppConfigurationClient {
constructor(connectionString: string);
constructor(uri: string, credential: TokenCredential);
// (undocumented)
addConfigurationSetting(key: string, configSettings: AddConfigurationSettingConfig, options?: AddConfigurationSettingOptions): Promise<AddConfigurationSettingsResponse>;
// (undocumented)
deleteConfigurationSetting(key: string, options: DeleteConfigurationSettingOptions): Promise<DeleteConfigurationSettingResponse>;
// (undocumented)
getConfigurationSetting(key: string, options?: GetConfigurationSettingOptions): Promise<GetConfigurationSettingResponse>;
// (undocumented)
listConfigurationSettings(options?: ListConfigurationSettingsOptions): Promise<ListConfigurationSettingsResponse>;
// (undocumented)
listRevisions(options?: ListRevisionsOptions): Promise<ListRevisionsResponse>;
// (undocumented)
setConfigurationSetting(key: string, configSettings: SetConfigurationSettingConfig, options?: SetConfigurationSettingOptions): Promise<SetConfigurationSettingResponse>;
// (undocumented)
updateConfigurationSetting(key: string, configSettings: UpdateConfigurationSettingConfig, options?: UpdateConfigurationSettingOptions): Promise<UpdateConfigurationSettingResponse>;
}

Expand All @@ -50,7 +43,6 @@ export type DeleteConfigurationSettingResponse = ModelDeleteConfigurationSetting

// @public (undocumented)
export interface ETagOption {
// (undocumented)
etag?: string;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as crypto from "crypto";
import { ServiceClientCredentials, WebResource, URLBuilder } from "@azure/core-http";

/**
* @internal
* @ignore
*/
export class AppConfigCredential implements ServiceClientCredentials {
private credential: string;
private secret: string;
Expand All @@ -10,31 +14,40 @@ export class AppConfigCredential implements ServiceClientCredentials {
this.secret = secret;
}

/**
* Signs a request with the values provided in the credential and secret parameter.
*
* @param {WebResource} webResource The WebResource to be signed.
* @returns {Promise<WebResource>} The signed request object.
Comment thread
richardpark-msft marked this conversation as resolved.
Outdated
*/
signRequest(webResource: WebResource): Promise<WebResource> {
const verb = webResource.method.toUpperCase()
const verb = webResource.method.toUpperCase();
const utcNow = new Date().toUTCString();
const contentHash =
crypto.createHash("sha256")
.update(webResource.body || "")
.digest("base64");
const contentHash = crypto
.createHash("sha256")
.update(webResource.body || "")
.digest("base64");

const signedHeaders = "x-ms-date;host;x-ms-content-sha256";

const url = URLBuilder.parse(webResource.url);
const query = url.getQuery();
const urlPathAndQuery = `${url.getPath()}${ query ? "?" + query : "" }`
const urlPathAndQuery = `${url.getPath()}${query ? "?" + query : ""}`;

const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${url.getHost()};${contentHash}`;

const decodedSecret = Buffer.from(this.secret, "base64");
var signature =
crypto.createHmac("sha256", decodedSecret)
var signature = crypto
.createHmac("sha256", decodedSecret)
.update(stringToSign)
.digest("base64");

webResource.headers.set("x-ms-date", utcNow);
webResource.headers.set("x-ms-content-sha256", contentHash);
webResource.headers.set("Authorization", `HMAC-SHA256 Credential=${this.credential}, SignedHeaders=${signedHeaders}, Signature=${signature}`);
webResource.headers.set(
"Authorization",
`HMAC-SHA256 Credential=${this.credential}, SignedHeaders=${signedHeaders}, Signature=${signature}`
);

return Promise.resolve(webResource);
}
Expand Down
Loading