Skip to content

Commit

Permalink
[App Config] Rename Snapshot Properties and Add Overload (Azure#27047)
Browse files Browse the repository at this point in the history
  • Loading branch information
minhanh-phan authored Oct 4, 2023
1 parent 1ac75e2 commit 9267636
Show file tree
Hide file tree
Showing 15 changed files with 408 additions and 249 deletions.
5 changes: 5 additions & 0 deletions sdk/appconfiguration/app-configuration/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

### Other Changes

- Rename `Snapshot` -> `ConfigurationSnapshot`
- Rename the properties `retentionPeriod` -> `retentionPeriodInSeconds`, `size` -> `sizeInBytes` for `ConfigurationSnapshot`
- Rename the type `CompositionType` -> `SnapshotComposition`, `SnapshotStatus` -> `ConfigurationSnapshotStatus`
- Update the method signature for `archiveSnapshot` and `updateSnapshot` to take in a snapshot name as a parameter

## 1.5.0-beta.1 (2023-07-14)

### Features Added
Expand Down
20 changes: 16 additions & 4 deletions sdk/appconfiguration/app-configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async function run() {
const poller = await client.beginCreateSnapshot({
name:"testsnapshot",
retentionPeriod: 2592000,
filters: [{key, label}],
filters: [{keyFilter: key, labelFilter: label}],
});
const snapshot = await poller.pollUntilDone();
}
Expand All @@ -217,7 +217,7 @@ You can also use `beginCreateSnapshotAndWait` to have the result of the creation
const snapshot = await client.beginCreateSnapshotAndWait({
name:"testsnapshot",
retentionPeriod: 2592000,
filters: [{key, label}],
filters: [{keyFilter: key, labelFilter: label}],
});
```

Expand Down Expand Up @@ -249,13 +249,25 @@ for await (const snapshot of snapshots) {
### Recover and archive the snapshot
```javascript
// Snapshot is in ready status
let archivedSnapshot = await client.archiveSnapshot({name: "testsnapshot"});
let archivedSnapshot = await client.archiveSnapshot("testsnapshot");
console.log("Snapshot updated status is:", archivedSnapshot.status);

// Snapshot is in archive status
let recoverSnapshot = await client.recoverSnapshot({name: "testsnapshot"});
let recoverSnapshot = await client.recoverSnapshot("testsnapshot");
console.log("Snapshot updated status is:", recoverSnapshot.status);
```

You can also use an overload that takes the name of the snapshot only.
```javascript
// Snapshot is in ready status
let archivedSnapshot = await client.archiveSnapshot("testsnapshot");
console.log("Snapshot updated status is:", archivedSnapshot.status);

// Snapshot is in archive status
let recoverSnapshot = await client.recoverSnapshot("testsnapshot");
console.log("Snapshot updated status is:", recoverSnapshot.status);
```

## Troubleshooting

### Logging
Expand Down
2 changes: 1 addition & 1 deletion sdk/appconfiguration/app-configuration/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/appconfiguration/app-configuration",
"Tag": "js/appconfiguration/app-configuration_89796f3f90"
"Tag": "js/appconfiguration/app-configuration_7d75890bc5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AppConfigurationClient {
constructor(connectionString: string, options?: AppConfigurationClientOptions);
constructor(endpoint: string, tokenCredential: TokenCredential, options?: AppConfigurationClientOptions);
addConfigurationSetting(configurationSetting: AddConfigurationSettingParam | AddConfigurationSettingParam<FeatureFlagValue> | AddConfigurationSettingParam<SecretReferenceValue>, options?: AddConfigurationSettingOptions): Promise<AddConfigurationSettingResponse>;
archiveSnapshot(snapshotId: SnapshotId, options?: UpdateSnapshotOptions): Promise<UpdateSnapshotResponse>;
archiveSnapshot(name: string, options?: UpdateSnapshotOptions): Promise<UpdateSnapshotResponse>;
beginCreateSnapshot(snapshot: SnapshotInfo, options?: CreateSnapshotOptions): Promise<SimplePollerLike<OperationState<CreateSnapshotResponse>, CreateSnapshotResponse>>;
beginCreateSnapshotAndWait(snapshot: SnapshotInfo, options?: CreateSnapshotOptions): Promise<CreateSnapshotResponse>;
deleteConfigurationSetting(id: ConfigurationSettingId, options?: DeleteConfigurationSettingOptions): Promise<DeleteConfigurationSettingResponse>;
Expand All @@ -50,8 +50,8 @@ export class AppConfigurationClient {
listConfigurationSettings(options?: ListConfigurationSettingsOptions): PagedAsyncIterableIterator<ConfigurationSetting, ListConfigurationSettingPage, PageSettings>;
listConfigurationSettingsForSnapshot(snapshotName: string, options?: ListConfigurationSettingsForSnapshotOptions): PagedAsyncIterableIterator<ConfigurationSetting, ListConfigurationSettingPage, PageSettings>;
listRevisions(options?: ListRevisionsOptions): PagedAsyncIterableIterator<ConfigurationSetting, ListRevisionsPage, PageSettings>;
listSnapshots(options?: ListSnapshotsOptions): PagedAsyncIterableIterator<Snapshot, ListSnapshotsPage, PageSettings>;
recoverSnapshot(snapshotId: SnapshotId, options?: UpdateSnapshotOptions): Promise<UpdateSnapshotResponse>;
listSnapshots(options?: ListSnapshotsOptions): PagedAsyncIterableIterator<ConfigurationSnapshot, ListSnapshotsPage, PageSettings>;
recoverSnapshot(name: string, options?: UpdateSnapshotOptions): Promise<UpdateSnapshotResponse>;
setConfigurationSetting(configurationSetting: SetConfigurationSettingParam | SetConfigurationSettingParam<FeatureFlagValue> | SetConfigurationSettingParam<SecretReferenceValue>, options?: SetConfigurationSettingOptions): Promise<SetConfigurationSettingResponse>;
setReadOnly(id: ConfigurationSettingId, readOnly: boolean, options?: SetReadOnlyOptions): Promise<SetReadOnlyResponse>;
updateSyncToken(syncToken: string): void;
Expand All @@ -62,18 +62,17 @@ export interface AppConfigurationClientOptions extends CommonClientOptions {
apiVersion?: AppConfigurationApiVersion;
}

// @public
export type CompositionType = string;

// @public
export type ConfigurationSetting<T extends string | FeatureFlagValue | SecretReferenceValue = string> = ConfigurationSettingParam<T> & {
isReadOnly: boolean;
lastModified?: Date;
};

// @public
export interface ConfigurationSettingId extends ConfigurationSettingsFilter {
export interface ConfigurationSettingId {
etag?: string;
key: string;
label?: string;
}

// @public
Expand All @@ -93,10 +92,30 @@ export type ConfigurationSettingResponse<HeadersT> = ConfigurationSetting & Http

// @public
export interface ConfigurationSettingsFilter {
key: string;
label?: string;
keyFilter: string;
labelFilter?: string;
}

// @public
export interface ConfigurationSnapshot {
compositionType?: SnapshotComposition;
readonly createdOn?: Date;
readonly etag?: string;
readonly expiresOn?: Date;
filters: ConfigurationSettingsFilter[];
readonly itemCount?: number;
readonly name: string;
retentionPeriodInSeconds?: number;
readonly sizeInBytes?: number;
readonly status?: ConfigurationSnapshotStatus;
tags?: {
[propertyName: string]: string;
};
}

// @public
export type ConfigurationSnapshotStatus = string;

// @public
export interface CreateSnapshotOptions extends OperationOptions {
updateIntervalInMs?: number;
Expand Down Expand Up @@ -148,7 +167,7 @@ export interface GetConfigurationSettingResponse extends ConfigurationSetting, G
}

// @public
export interface GetSnapshotOptions extends OperationOptions, HttpOnlyIfChangedField, OptionalSnapshotFields {
export interface GetSnapshotOptions extends OperationOptions, OptionalSnapshotFields {
}

// @public
Expand Down Expand Up @@ -185,27 +204,26 @@ export function isFeatureFlag(setting: ConfigurationSetting): setting is Configu
export function isSecretReference(setting: ConfigurationSetting): setting is ConfigurationSetting & Required<Pick<ConfigurationSetting, "value">>;

// @public
export enum KnownCompositionType {
Key = "key",
KeyLabel = "key_label"
}

// @public
export enum KnownSnapshotStatus {
export enum KnownConfigurationSnapshotStatus {
Archived = "archived",
Failed = "failed",
Provisioning = "provisioning",
Ready = "ready"
}

// @public
export enum KnownSnapshotComposition {
Key = "key",
KeyLabel = "key_label"
}

// @public
export interface ListConfigurationSettingPage extends HttpResponseField<SyncTokenHeaderField>, PageSettings {
items: ConfigurationSetting[];
}

// @public
export interface ListConfigurationSettingsForSnapshotOptions extends OperationOptions, OptionalFields {
acceptDateTime?: Date;
}

// @public
Expand All @@ -231,16 +249,16 @@ export interface ListSettingsOptions extends OptionalFields {
// @public
export interface ListSnapshots extends OptionalSnapshotFields {
nameFilter?: string;
statusFilter?: SnapshotStatus[];
statusFilter?: ConfigurationSnapshotStatus[];
}

// @public
export interface ListSnapshotsOptions extends OperationOptions, ListSnapshots, OptionalSnapshotFields {
}

// @public
export interface ListSnapshotsPage extends HttpResponseField<SyncTokenHeaderField>, PageSettings {
items: Snapshot[];
export interface ListSnapshotsPage extends SyncTokenHeaderField, PageSettings {
items: ConfigurationSnapshot[];
}

// @public
Expand All @@ -250,7 +268,7 @@ export interface OptionalFields {

// @public
export interface OptionalSnapshotFields {
fields?: (keyof Snapshot)[];
fields?: (keyof ConfigurationSnapshot)[];
}

// @public
Expand Down Expand Up @@ -298,56 +316,31 @@ export interface SetReadOnlyResponse extends ConfigurationSetting, SyncTokenHead
}

// @public
export interface Snapshot {
compositionType?: CompositionType;
readonly createdOn?: Date;
readonly etag?: string;
readonly expiresOn?: Date;
filters: ConfigurationSettingsFilter[];
readonly itemCount?: number;
readonly name: string;
retentionPeriod?: number;
readonly size?: number;
readonly status?: SnapshotStatus;
tags?: {
[propertyName: string]: string;
};
}

// @public
export interface SnapshotId {
etag?: string;
name: string;
}
export type SnapshotComposition = string;

// @public
export interface SnapshotInfo {
compositionType?: CompositionType;
compositionType?: SnapshotComposition;
filters: ConfigurationSettingsFilter[];
name: string;
retentionPeriod?: number;
retentionPeriodInSeconds?: number;
tags?: {
[propertyName: string]: string;
};
}

// @public
export interface SnapshotResponse extends Snapshot, SyncTokenHeaderField {
export interface SnapshotResponse extends ConfigurationSnapshot, SyncTokenHeaderField {
}

// @public
export type SnapshotStatus = string;

// @public
export type State = "NotStarted" | "Running" | "Succeeded" | "Failed" | "Canceled";

// @public
export interface SyncTokenHeaderField {
syncToken?: string;
}

// @public
export interface UpdateSnapshotOptions extends HttpOnlyIfUnchangedField, OperationOptions {
export interface UpdateSnapshotOptions extends OperationOptions {
etag?: string;
}

// @public
Expand Down
10 changes: 3 additions & 7 deletions sdk/appconfiguration/app-configuration/samples-dev/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function main() {
name: "mySnapshot",
filters: [
{
key: key1,
keyFilter: key1,
},
],
});
Expand All @@ -56,7 +56,7 @@ export async function main() {
name: "mySnapshot2",
filters: [
{
key: key2,
keyFilter: key2,
},
],
});
Expand All @@ -69,13 +69,9 @@ export async function main() {
console.log(` Found snapshot: ${snapshot.name}`);
}
// archive snapshot
await client.archiveSnapshot(newSnapshot);
await client.archiveSnapshot(newSnapshot.name);
console.log(`${newSnapshot.name} has been archived with the status ${newSnapshot.status}`);

// removing the setting
await client.archiveSnapshot({ name: newSnapshot.name as string, etag: newSnapshot.etag });
console.log(`${newSnapshot.name} has been archived`);

await cleanupSampleValues([key1], client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
SetConfigurationSettingResponse,
SetReadOnlyOptions,
SetReadOnlyResponse,
SnapshotId,
SnapshotInfo,
UpdateSnapshotOptions,
UpdateSnapshotResponse,
Expand All @@ -46,7 +45,7 @@ import {
GetKeyValuesResponse,
GetRevisionsResponse,
GetSnapshotsResponse,
Snapshot,
ConfigurationSnapshot,
} from "./generated/src/models";
import { InternalClientPipelineOptions } from "@azure/core-client";
import { PagedAsyncIterableIterator, PagedResult, getPagedAsyncIterator } from "@azure/core-paging";
Expand Down Expand Up @@ -621,7 +620,7 @@ export class AppConfigurationClient {
* @param options - Optional parameters for the request.
*/
recoverSnapshot(
snapshotId: SnapshotId,
name: string,
options: UpdateSnapshotOptions = {}
): Promise<UpdateSnapshotResponse> {
return tracingClient.withSpan(
Expand All @@ -630,11 +629,14 @@ export class AppConfigurationClient {
async (updatedOptions) => {
logger.info("[recoverSnapshot] Recover a snapshot");
const originalResponse = await this.client.updateSnapshot(
snapshotId.name,
name,
{ status: "ready" },
{
...updatedOptions,
...checkAndFormatIfAndIfNoneMatch({ etag: snapshotId.etag }, options),
...checkAndFormatIfAndIfNoneMatch(
{ etag: options.etag },
{ onlyIfUnchanged: true, ...options }
),
}
);
const response = transformSnapshotResponse(originalResponse);
Expand All @@ -643,19 +645,18 @@ export class AppConfigurationClient {
}
);
}

/**
* Archive a ready snapshot
*
* Example usage:
* ```ts
* const result = await client.archiveSnapshot("MySnapshot");
* const result = await client.archiveSnapshot({name: "MySnapshot"});
* ```
* @param name - The name of the snapshot.
* @param options - Optional parameters for the request.
*/
archiveSnapshot(
snapshotId: SnapshotId,
name: string,
options: UpdateSnapshotOptions = {}
): Promise<UpdateSnapshotResponse> {
return tracingClient.withSpan(
Expand All @@ -664,11 +665,14 @@ export class AppConfigurationClient {
async (updatedOptions) => {
logger.info("[archiveSnapshot] Archive a snapshot");
const originalResponse = await this.client.updateSnapshot(
snapshotId.name,
name,
{ status: "archived" },
{
...updatedOptions,
...checkAndFormatIfAndIfNoneMatch({ etag: snapshotId.etag }, options),
...checkAndFormatIfAndIfNoneMatch(
{ etag: options.etag },
{ onlyIfUnchanged: true, ...options }
),
}
);
const response = transformSnapshotResponse(originalResponse);
Expand All @@ -689,7 +693,7 @@ export class AppConfigurationClient {
*/
listSnapshots(
options: ListSnapshotsOptions = {}
): PagedAsyncIterableIterator<Snapshot, ListSnapshotsPage, PageSettings> {
): PagedAsyncIterableIterator<ConfigurationSnapshot, ListSnapshotsPage, PageSettings> {
const pagedResult: PagedResult<ListSnapshotsPage, PageSettings, string | undefined> = {
firstPageLink: undefined,
getPage: async (pageLink: string | undefined) => {
Expand Down
Loading

0 comments on commit 9267636

Please sign in to comment.