-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2063 from AkhtarAmir/H-plugin/azure-synapse-has-tags
H-plugin synapse workspace has tags
- Loading branch information
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var async = require('async'); | ||
var helpers = require('../../../helpers/azure'); | ||
|
||
module.exports = { | ||
title: 'Synapse Workspace Has Tags', | ||
category: 'AI & ML', | ||
domain: 'Machine Learning', | ||
severity: 'Low', | ||
description: 'Ensures that Azure Synapse workspaces have tags associated.', | ||
more_info: 'Tags help you to group resources together that are related to or associated with each other. It is a best practice to tag cloud resources to better organize and gain visibility into their usage.', | ||
recommended_action: 'Modify Synapse workspace and add tags.', | ||
link: 'https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources', | ||
apis: ['synapse:listWorkspaces'], | ||
realtime_triggers: ['microsoftsynapse:workspaces:write','microsoftsynapse:workspaces:delete','microsoftresources:tags:write'], | ||
|
||
run: function(cache, settings, callback) { | ||
const results = []; | ||
const source = {}; | ||
const locations = helpers.locations(settings.govcloud); | ||
|
||
async.each(locations.synapse, function(location, rcb) { | ||
const workspaces = helpers.addSource(cache, source, | ||
['synapse', 'listWorkspaces', location]); | ||
|
||
if (!workspaces) return rcb(); | ||
|
||
|
||
if (workspaces.err || !workspaces.data) { | ||
helpers.addResult(results, 3, 'Unable to query Synapse workspaces: ' + helpers.addError(workspaces), location); | ||
return rcb(); | ||
} | ||
|
||
if (!workspaces.data.length) { | ||
helpers.addResult(results, 0, 'No existing Synapse workspaces found', location); | ||
return rcb(); | ||
} | ||
|
||
for (let workspace of workspaces.data) { | ||
if (!workspace.id) continue; | ||
|
||
if (workspace.tags && | ||
Object.entries(workspace.tags).length > 0) { | ||
helpers.addResult(results, 0, 'Synapse workspace has tags', location, workspace.id); | ||
} else { | ||
helpers.addResult(results, 2, 'Synapse workspace does not have tags', location, workspace.id); | ||
} | ||
} | ||
rcb(); | ||
}, function() { | ||
// Global checking goes here | ||
callback(null, results, source); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
var expect = require('chai').expect; | ||
var synapseWorkspaceHasTags = require('./synapseWorkspaceHasTags'); | ||
|
||
const workspaces = [ | ||
{ | ||
type: "Microsoft.Synapse/workspaces", | ||
id: "/subscriptions/123/resourceGroups/rsgrp/providers/Microsoft.Synapse/workspaces/test", | ||
location: "eastus", | ||
name: "test", | ||
"tags": { | ||
"key": "value" | ||
} | ||
}, | ||
{ | ||
type: "Microsoft.Synapse/workspaces", | ||
id: "/subscriptions/123/resourceGroups/rsgrp/providers/Microsoft.Synapse/workspaces/test", | ||
location: "eastus", | ||
name: "test", | ||
"tags": {} | ||
}, | ||
]; | ||
|
||
|
||
const createCache = (workspaces, err) => { | ||
|
||
return { | ||
synapse: { | ||
listWorkspaces: { | ||
'eastus': { | ||
data: workspaces, | ||
err: err | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
describe('synapseWorkspaceHasTags', function () { | ||
describe('run', function () { | ||
|
||
it('should give a passing result if no Synapse workspaces are found', function (done) { | ||
const cache = createCache([], null); | ||
synapseWorkspaceHasTags.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('No existing Synapse workspaces found'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give unknown result if unable to query for Synapse workspaces', function (done) { | ||
const cache = createCache(null, ['error']); | ||
synapseWorkspaceHasTags.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(3); | ||
expect(results[0].message).to.include('Unable to query Synapse workspaces'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give passing result if workspace has tags', function (done) { | ||
const cache = createCache([workspaces[0]], null); | ||
synapseWorkspaceHasTags.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('Synapse workspace has tags'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give failing result if workspace does not have tags', function (done) { | ||
const cache = createCache([workspaces[1]], null); | ||
synapseWorkspaceHasTags.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].message).to.include('Synapse workspace does not have tags'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |