-
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 #2070 from AkhtarAmir/FS-Azure/MLRegistriesTags
Fs azure/ml registries tags
- Loading branch information
Showing
3 changed files
with
151 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,56 @@ | ||
var async = require('async'); | ||
var helpers = require('../../../helpers/azure'); | ||
|
||
module.exports = { | ||
title: 'Machine Learning Registry Has Tags', | ||
category: 'AI & ML', | ||
domain: 'Machine Learning', | ||
severity: 'Low', | ||
description: 'Ensures that Azure Machine Learning registries 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 Machine Learning registry and add tags.', | ||
link: 'https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources', | ||
apis: ['machineLearning:listRegistries'], | ||
realtime_triggers: ['microsoftmachinelearningservices:registries:write','microsoftmachinelearningservices:registries:delete', 'microsoftresources:tags:write'], | ||
|
||
run: function(cache, settings, callback) { | ||
const results = []; | ||
const source = {}; | ||
const locations = helpers.locations(settings.govcloud); | ||
|
||
async.each(locations.machineLearning, function(location, rcb) { | ||
var machineLearningRegistries = helpers.addSource(cache, source, | ||
['machineLearning', 'listRegistries', location]); | ||
|
||
if (!machineLearningRegistries) return rcb(); | ||
|
||
if (machineLearningRegistries.err || !machineLearningRegistries.data) { | ||
helpers.addResult(results, 3, | ||
'Unable to query for Machine Learning registries: ' + helpers.addError(machineLearningRegistries), location); | ||
return rcb(); | ||
} | ||
|
||
if (!machineLearningRegistries.data.length) { | ||
helpers.addResult(results, 0, 'No existing Machine Learning registries found', location); | ||
return rcb(); | ||
} | ||
|
||
for (let registry of machineLearningRegistries.data) { | ||
if (!registry.id) continue; | ||
|
||
if (registry.tags && Object.entries(registry.tags).length > 0) { | ||
helpers.addResult(results, 0, | ||
'Machine Learning registry has tags associated', location, registry.id); | ||
} else { | ||
helpers.addResult(results, 2, | ||
'Machine Learning registry does not have tags associated', location, registry.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,94 @@ | ||
var expect = require('chai').expect; | ||
var mlRegistryHasTags = require('./mlRegistryHasTags'); | ||
|
||
const registry = [ | ||
{ | ||
"id": "/subscriptions/12345667/resourceGroups/test/providers/Microsoft.MachineLearningServices/registries/test1", | ||
"name": "test", | ||
"type": "Microsoft.MachineLearningServices/registries", | ||
"tags": { | ||
"test": "test" | ||
}, | ||
"publicNetworkAccess" : "Disabled" | ||
|
||
}, | ||
{ | ||
"id": "/subscriptions/12345667/resourceGroups/test/providers/Microsoft.MachineLearningServices/registries/test1", | ||
"name": "test", | ||
"type": "Microsoft.MachineLearningServices/registries", | ||
"publicNetworkAccess" : "Enabled" | ||
}, | ||
|
||
]; | ||
|
||
const createCache = (registries) => { | ||
return { | ||
machineLearning: { | ||
listRegistries: { | ||
'eastus': { | ||
data: registries | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
const createErrorCache = () => { | ||
return { | ||
machineLearning: { | ||
listRegistries: { | ||
'eastus': {} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
describe('mlRegistryHasTags', function() { | ||
describe('run', function() { | ||
it('should give passing result if no Machine Learning registry found', function(done) { | ||
const cache = createCache([]); | ||
mlRegistryHasTags.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 Machine Learning registries found'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give unknown result if unable to query for Machine Learning registry', function(done) { | ||
const cache = createErrorCache(); | ||
mlRegistryHasTags.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 for Machine Learning registries: '); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
|
||
it('should give passing result if Machine Learning registry has tags associated', function(done) { | ||
const cache = createCache([registry[0]]); | ||
mlRegistryHasTags.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('Machine Learning registry has tags associated'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give failing result if Machine Learning registry does not have tags associated', function(done) { | ||
const cache = createCache([registry[1]]); | ||
mlRegistryHasTags.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].message).to.include('Machine Learning registry does not have tags associated'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
}); |