-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[App Configuration] - Snapshot Reference #36105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,11 @@ | |||||||||
|
||||||||||
### Features Added | ||||||||||
|
||||||||||
- Support snapshot referece. | ||||||||||
- New types for SnapshotReference - `ConfigurationSetting<SnapshotReferenceValue>` and `ConfigurationSetting<SecretReferenceValue>` | ||||||||||
- Upon using `getConfigurationSetting`(or add/update), use `parseSnapshotReference` methods to access the properties(to translate `ConfigurationSetting` into the types above). | ||||||||||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second type should be
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
- Helper method `isSnapshotReference` checks the contentType and return boolean values. | ||||||||||
|
||||||||||
### Breaking Changes | ||||||||||
|
||||||||||
### Bugs Fixed | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,91 @@ | ||||||
// Copyright (c) Microsoft Corporation. | ||||||
// Licensed under the MIT License. | ||||||
|
||||||
import type { ConfigurationSetting, ConfigurationSettingParam } from "./models.js"; | ||||||
import type { JsonSnapshotReferenceValue } from "./internal/jsonModels.js"; | ||||||
import { logger } from "./logger.js"; | ||||||
|
||||||
/** | ||||||
* content-type for the snapshot reference. | ||||||
*/ | ||||||
export const snapshotReferenceContentType = | ||||||
'application/json; profile="https://azconfig.io/mime-profiles/snapshot-ref"; charset=utf-8'; | ||||||
|
||||||
/** | ||||||
* Necessary fields for updating or creating a new snapshot reference. | ||||||
*/ | ||||||
export interface SnapshotReferenceValue { | ||||||
/** | ||||||
* snapshot name. | ||||||
*/ | ||||||
snapshotName: string; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @internal | ||||||
*/ | ||||||
export const SnapshotReferenceHelper = { | ||||||
/** | ||||||
* Takes the SnapshotReference (JSON) and returns a ConfigurationSetting (with the props encodeed in the value). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected spelling of 'encodeed' to 'encoded'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
*/ | ||||||
toConfigurationSettingParam: ( | ||||||
snapshotReference: ConfigurationSettingParam<SnapshotReferenceValue>, | ||||||
): ConfigurationSettingParam => { | ||||||
logger.info("Encoding SnapshotReference value in a ConfigurationSetting:", snapshotReference); | ||||||
if (!snapshotReference.value) { | ||||||
logger.error(`SnapshotReference has an unexpected value`, snapshotReference); | ||||||
throw new TypeError(`SnapshotReference has an unexpected value - ${snapshotReference.value}`); | ||||||
} | ||||||
|
||||||
const jsonSnapshotReferenceValue: JsonSnapshotReferenceValue = { | ||||||
snapshot_name: snapshotReference.value.snapshotName, | ||||||
}; | ||||||
|
||||||
const configSetting = { | ||||||
...snapshotReference, | ||||||
value: JSON.stringify(jsonSnapshotReferenceValue), | ||||||
}; | ||||||
return configSetting; | ||||||
}, | ||||||
}; | ||||||
|
||||||
/** | ||||||
* Takes the ConfigurationSetting as input and returns the ConfigurationSetting<SnapshotReferenceValue> by parsing the value string. | ||||||
*/ | ||||||
export function parseSnapshotReference( | ||||||
setting: ConfigurationSetting, | ||||||
): ConfigurationSetting<SnapshotReferenceValue> { | ||||||
logger.info( | ||||||
"[parseSnapshotReference] Parsing the value to return the SnapshotReferenceValue", | ||||||
setting, | ||||||
); | ||||||
if (!isSnapshotReference(setting)) { | ||||||
logger.error("Invalid SnapshotReference input", setting); | ||||||
throw TypeError( | ||||||
`Setting with key ${setting.key} is not a valid SnapshotReference, make sure to have the correct content-type and a valid non-null value.`, | ||||||
); | ||||||
} | ||||||
|
||||||
const jsonSnapshotReferenceValue = JSON.parse(setting.value) as JsonSnapshotReferenceValue; | ||||||
|
||||||
const snapshotReference: ConfigurationSetting<SnapshotReferenceValue> = { | ||||||
...setting, | ||||||
value: { snapshotName: jsonSnapshotReferenceValue.snapshot_name }, | ||||||
}; | ||||||
return snapshotReference; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Lets you know if the ConfigurationSetting is a snapshot reference. | ||||||
* | ||||||
* [Checks if the content type is snapshotReferenceContentType `"application/json; profile=\"https://azconfig.io/mime-profiles/snapshot-ref\"; charset=utf-8"`] | ||||||
*/ | ||||||
export function isSnapshotReference( | ||||||
setting: ConfigurationSetting, | ||||||
): setting is ConfigurationSetting & Required<Pick<ConfigurationSetting, "value">> { | ||||||
return ( | ||||||
setting && | ||||||
setting.contentType === snapshotReferenceContentType && | ||||||
typeof setting.value === "string" | ||||||
); | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'referece' to 'reference'.
Copilot uses AI. Check for mistakes.