Skip to content

Commit

Permalink
Updated docs and made some small refactors for readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpark-msft committed Sep 4, 2019
1 parent dcd9a29 commit 423904a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ export type AddConfigurationSettingsResponse = ModelCreateOrUpdateConfigurationS
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
Expand Up @@ -10,6 +10,12 @@ 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.
*/
signRequest(webResource: WebResource): Promise<WebResource> {
const verb = webResource.method.toUpperCase()
const utcNow = new Date().toUTCString();
Expand Down
77 changes: 68 additions & 9 deletions sdk/appconfiguration/app-configuration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,51 @@ const deserializationContentTypes = {
}

export interface ETagOption {
/**
* Entity tag (etag) of the object
*/
etag?: string;
}

export type AddConfigurationSettingConfig = Pick<ModelConfigurationSetting, Exclude<keyof ModelConfigurationSetting, "key">>;
export type AddConfigurationSettingOptions = ModelConfigurationClientCreateOrUpdateConfigurationSettingOptionalParams;
export type AddConfigurationSettingsResponse = ModelCreateOrUpdateConfigurationSettingResponse;
type CreateOrUpdateOptions = ModelConfigurationClientCreateOrUpdateConfigurationSettingOptionalParams;
type CreateOrUpdateConfigurationSetting = Pick<ModelConfigurationSetting, Exclude<keyof ModelConfigurationSetting, "key">>;
type CreateOrUpdateResponse = ModelCreateOrUpdateConfigurationSettingResponse;

export type AddConfigurationSettingConfig = CreateOrUpdateConfigurationSetting;
export type AddConfigurationSettingOptions = CreateOrUpdateOptions;
export type AddConfigurationSettingsResponse = CreateOrUpdateResponse;

export type DeleteConfigurationSettingOptions = ModelConfigurationClientDeleteConfigurationSettingOptionalParams & ETagOption;
export type DeleteConfigurationSettingResponse = ModelDeleteConfigurationSettingResponse;

export type GetConfigurationSettingOptions = ModelConfigurationClientGetConfigurationSettingOptionalParams;
export type GetConfigurationSettingResponse = ModelGetConfigurationSettingResponse;

export type ListConfigurationSettingsOptions = ModelConfigurationClientListConfigurationSettingsOptionalParams;
export type ListConfigurationSettingsResponse = ModelListConfigurationSettingsResponse;

export type ListRevisionsOptions = ModelConfigurationClientListRevisionsOptionalParams;
export type ListRevisionsResponse = ModelListRevisionsResponse;
export type SetConfigurationSettingConfig = Pick<ModelConfigurationSetting, Exclude<keyof ModelConfigurationSetting, "key">>;
export type SetConfigurationSettingOptions = ModelConfigurationClientCreateOrUpdateConfigurationSettingOptionalParams;
export type SetConfigurationSettingResponse = ModelCreateOrUpdateConfigurationSettingResponse;
export type UpdateConfigurationSettingConfig = Pick<ModelConfigurationSetting, Exclude<keyof ModelConfigurationSetting, "key">>;
export type UpdateConfigurationSettingOptions = ModelConfigurationClientCreateOrUpdateConfigurationSettingOptionalParams;
export type UpdateConfigurationSettingResponse = ModelCreateOrUpdateConfigurationSettingResponse;

export type SetConfigurationSettingConfig = CreateOrUpdateConfigurationSetting;
export type SetConfigurationSettingOptions = CreateOrUpdateOptions;
export type SetConfigurationSettingResponse = CreateOrUpdateResponse;

export type UpdateConfigurationSettingConfig = CreateOrUpdateConfigurationSetting;
export type UpdateConfigurationSettingOptions = CreateOrUpdateOptions;
export type UpdateConfigurationSettingResponse = CreateOrUpdateResponse;

export class AppConfigurationClient {
private client: ConfigurationClient;

/**
* Initializes a new instance of the AppConfigurationClient class.
* @param connectionString Connection string needed for a client to connect to Azure.
*//**
* Initializes a new instance of the AppConfigurationClient class.
* @param uri The base URI for the Azure service
* @param credential The credentials to use for authentication.
*/
constructor(connectionString: string);
constructor(uri: string, credential: TokenCredential);
constructor(uriOrConnectionString: string, credential?: TokenCredential) {
Expand All @@ -91,6 +112,12 @@ export class AppConfigurationClient {
}
}

/**
* Add a setting into the Azure App Configuration service, failing if it already exists.
* @param key The name of the key.
* @param configSettings A configuration value.
* @param options Optional parameters for the value being added.
*/
addConfigurationSetting(key: string, configSettings: AddConfigurationSettingConfig, options: AddConfigurationSettingOptions = {}): Promise<AddConfigurationSettingsResponse> {
// add the custom header if-none-match=* to only add the key-value if it doesn't already exist
// create a copy of the options to avoid modifying the user's options
Expand All @@ -105,6 +132,12 @@ export class AppConfigurationClient {
return this.client.createOrUpdateConfigurationSetting(configSettings, key, options);
}

/**
* Delete a setting the Azure App Configuration service, allowing for an optional etag
* to delete only if unmodified.
* @param key The name of the key.
* @param options Optional parameters for the value being deleted.
*/
deleteConfigurationSetting(key: string, options: DeleteConfigurationSettingOptions): Promise<DeleteConfigurationSettingResponse> {
// hoist the etag into a custom header to ensure this update fails if the setting has been updated
options = { ...options };
Expand All @@ -118,18 +151,37 @@ export class AppConfigurationClient {
return this.client.deleteConfigurationSetting(key, options);
}

/**
* Get a setting from the Azure App Configuration service.
* @param key The name of the key
* @param options Optional parameters for the value being retrieved.
*/
getConfigurationSetting(key: string, options?: GetConfigurationSettingOptions): Promise<GetConfigurationSettingResponse> {
return this.client.getConfigurationSetting(key, options);
}

/**
* Lists the setting from the Azure App Configuration service.
* @param options Optional parameters for the values being listed.
*/
listConfigurationSettings(options?: ListConfigurationSettingsOptions): Promise<ListConfigurationSettingsResponse> {
return this.client.listConfigurationSettings(options);
}

/**
* Lists the revisions of a set of keys within the Azure App Configuration service.
* @param options Optional parameters for the revisions being listed.
*/
listRevisions(options?: ListRevisionsOptions): Promise<ListRevisionsResponse> {
return this.client.listRevisions(options);
}

/**
* Sets the value of a key in the Azure App Configuration service, allowing for an optional etag.
* @param key The name of the key.
* @param configSettings A configuration value.
* @param options Optional parameters for the key being set.
*/
setConfigurationSetting(key: string, configSettings: SetConfigurationSettingConfig, options: SetConfigurationSettingOptions = {}): Promise<SetConfigurationSettingResponse> {
// hoist the etag into a custom header to ensure this update fails if the setting has been updated
options = { ...options };
Expand All @@ -148,6 +200,12 @@ export class AppConfigurationClient {
return this.client.createOrUpdateConfigurationSetting(configSettings, key, { ...options, customHeaders });
}

/**
* Updates the value of a key in the Azure App Configuration service.
* @param key The name of the key.
* @param configSettings A configuration value.
* @param options Optional parameters for the key being updated.
*/
async updateConfigurationSetting(key: string, configSettings: UpdateConfigurationSettingConfig, options: UpdateConfigurationSettingOptions = {}): Promise<UpdateConfigurationSettingResponse> {
// retrieve existing configuration, and populate configSettings for missing fields that aren't null
const existingConfigurationSettings = await this.getConfigurationSetting(key, {
Expand All @@ -156,6 +214,7 @@ export class AppConfigurationClient {
});

const updateConfigSettings = { ...configSettings };

if (typeof updateConfigSettings.value === "undefined") {
updateConfigSettings.value = existingConfigurationSettings.value;
}
Expand Down

0 comments on commit 423904a

Please sign in to comment.