Skip to content
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

service bus and blob container snippets #1416

Merged
merged 2 commits into from
Nov 11, 2021
Merged
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
21 changes: 21 additions & 0 deletions assets/resourceSnippets/ServiceBus Namespace.snippet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"prefix": "arm-servicebus-namespace",
"description": "ServiceBus Namespace"
},
"resources": [
{
"name": "${1:serviceBusNamespace1}",
"type": "Microsoft.ServiceBus/namespaces",
"apiVersion": "2021-01-01-preview",
"location": /*${2|[parameters('location')],[resourceGroup().location]|}*/ "location",
"sku": {
"name": "Standard"
},
"properties": {
}
}
]
}
31 changes: 31 additions & 0 deletions assets/resourceSnippets/ServiceBus Queue.snippet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"prefix": "arm-servicebus-queue",
"description": "ServiceBus Queue"
},
"resources": [
{
"name": "${1:serviceBusNamespace1}/${2:serviceBusQueue1}",
"type": "Microsoft.ServiceBus/namespaces/queues",
"apiVersion": "2021-01-01-preview",
"dependsOn": [
"[resourceId('Microsoft.ServiceBus/namespaces', '${2:serviceBusQueue1}')]"
],
"properties": {
"lockDuration": "${3|PT5M,PT30S|}",
"maxSizeInMegabytes": 1024,
"requiresDuplicateDetection": false,
"requiresSession": false,
"defaultMessageTimeToLive": "${4|P14D,PT10M,P10675199DT2H48M5.4775807S|}",
"deadLetteringOnMessageExpiration": false,
"duplicateDetectionHistoryTimeWindow": "PT10M",
"maxDeliveryCount": 10,
"autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",
"enablePartitioning": false,
"enableExpress": false
}
}
]
}
21 changes: 21 additions & 0 deletions assets/resourceSnippets/Storage Blob Container.snippet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"prefix": "arm-storage-blob-container",
"description": "Storage Blob Container"
},
"resources": [
{
"name": "${1:accountName}/default/${2:blobContainerName}",
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2021-04-01",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', '${1:accountName}')]"
],
"properties": {
"publicAccess": "None"
}
}
]
}
2 changes: 1 addition & 1 deletion src/snippets/SnippetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class SnippetManager implements ISnippetManager {
const snippetFiles = await fse.readdir(folderPath);
for (const relativePath of snippetFiles.filter(f => f !== 'README.jsonc')) {
const snippetName = relativePath.replace(/(.*)\.snippet\.json$/, '$1');
assert(snippetName !== relativePath, `Incorrectly formed resource snippet file name ${relativePath}`);
assert(snippetName !== relativePath, `Resource snippet ${snippetName} should have this filename: ${relativePath}`);
const content: string = await readUtf8FileWithBom(path.join(folderPath, relativePath));
const snippet = createResourceSnippetFromFile(snippetName, content);
const internalSnippet = convertToInternalSnippet(snippetName, snippet);
Expand Down
5 changes: 0 additions & 5 deletions test/DeploymentTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,6 @@ suite("DeploymentTemplate", () => {

suite("ReferenceInVariableDefinitionJSONVisitor", () => {
suite("constructor(DeploymentTemplate)", () => {
test("with undefined", () => {
// tslint:disable-next-line:no-any
assert.throws(() => { new ReferenceInVariableDefinitionsVisitor(<any>undefined); });
});

test("with deploymentTemplate", () => {
const dt = new DeploymentTemplateDoc(`{ "variables": { "a": "[reference('test')]" } }`, fakeId, 0);
const visitor = new ReferenceInVariableDefinitionsVisitor(dt);
Expand Down
36 changes: 35 additions & 1 deletion test/functional/snippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ let resourceTemplate: string = `{
\t]
}`;

let resourceTemplateWithLocation: string = `{
\t"resources": [
\t\t//Insert here: resource
\t],
\t"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
\t"contentVersion": "1.0.0.0",
\t"variables": {
\t\t//Insert here: variable
\t},
\t"parameters": {
\t\t"location": {
\t\t\t"type": "string"
\t\t}
\t\t//Insert here: parameter
\t},
\t"outputs": {
\t\t//Insert here: output
\t},
\t"functions": [
\t\t{
\t\t\t"namespace": "udf",
\t\t\t"members": {
\t\t\t\t//Insert here: user function
\t\t\t}
\t\t}
\t]
}`;

let emptyTemplate: string = `
//Insert here: empty
`;
Expand Down Expand Up @@ -280,7 +308,13 @@ suite("Snippets functional tests", () => {

validateSnippet();

const template = overrideTemplateForSnippet[snippetName] !== undefined ? overrideTemplateForSnippet[snippetName] : resourceTemplate;
let defaultTemplate = resourceTemplate;
if (snippet.insertText.includes("parameters('location')")) {
// add location parameter if used in snippet
defaultTemplate = resourceTemplateWithLocation;
}
const template = overrideTemplateForSnippet[snippetName] !== undefined ? overrideTemplateForSnippet[snippetName] : defaultTemplate;

// tslint:disable-next-line: strict-boolean-expressions
const expectedDiagnostics = (overrideExpectedDiagnostics[snippetName] || []).sort();
// tslint:disable-next-line: strict-boolean-expressions
Expand Down
36 changes: 36 additions & 0 deletions test/snippets/expected/ServiceBus Namespace.snippetresult.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"resources": [
{
"name": "serviceBusNamespace1",
"type": "Microsoft.ServiceBus/namespaces",
"apiVersion": "2021-01-01-preview",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {}
}
],
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
//Insert here: variable
},
"parameters": {
"location": {
"type": "string"
}
//Insert here: parameter
},
"outputs": {
//Insert here: output
},
"functions": [
{
"namespace": "udf",
"members": {
//Insert here: user function
}
}
]
}
44 changes: 44 additions & 0 deletions test/snippets/expected/ServiceBus Queue.snippetresult.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"resources": [
{
"name": "serviceBusNamespace1/serviceBusQueue1",
"type": "Microsoft.ServiceBus/namespaces/queues",
"apiVersion": "2021-01-01-preview",
"dependsOn": [
"[resourceId('Microsoft.ServiceBus/namespaces', 'serviceBusQueue1')]"
],
"properties": {
"lockDuration": "PT5M",
"maxSizeInMegabytes": 1024,
"requiresDuplicateDetection": false,
"requiresSession": false,
"defaultMessageTimeToLive": "P14D",
"deadLetteringOnMessageExpiration": false,
"duplicateDetectionHistoryTimeWindow": "PT10M",
"maxDeliveryCount": 10,
"autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",
"enablePartitioning": false,
"enableExpress": false
}
}
],
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
//Insert here: variable
},
"parameters": {
//Insert here: parameter
},
"outputs": {
//Insert here: output
},
"functions": [
{
"namespace": "udf",
"members": {
//Insert here: user function
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"resources": [
{
"name": "accountName/default/blobContainerName",
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2021-04-01",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', 'accountName')]"
],
"properties": {
"publicAccess": "None"
}
}
],
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
//Insert here: variable
},
"parameters": {
//Insert here: parameter
},
"outputs": {
//Insert here: output
},
"functions": [
{
"namespace": "udf",
"members": {
//Insert here: user function
}
}
]
}