-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor inventory gathering in preparation for new source of applica…
…tion inventory
- Loading branch information
1 parent
e55692f
commit cb257d3
Showing
10 changed files
with
196 additions
and
74 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
54 changes: 54 additions & 0 deletions
54
agent/plugins/inventory/gatherers/application/dataProvider.go
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 @@ | ||
package application | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/aws/amazon-ssm-agent/agent/context" | ||
"github.com/aws/amazon-ssm-agent/agent/plugins/inventory/model" | ||
) | ||
|
||
const ( | ||
amazonPublisherName = "amazon" | ||
amazonSsmAgentLinux = "amazon-ssm-agent" | ||
amazonSsmAgentWin = "amazon ssm agent" | ||
awsToolsWindows = "aws tools for windows" | ||
ec2ConfigService = "ec2configservice" | ||
awsCfnBootstrap = "aws-cfn-bootstrap" | ||
awsPVDrivers = "aws pv drivers" | ||
awsAPIToolsPrefix = "aws-apitools-" | ||
awsAMIToolsPrefix = "aws-amitools-" | ||
) | ||
|
||
var selectAwsApps map[string]string | ||
|
||
func init() { | ||
//NOTE: | ||
// For V1 - to filter out aws components from aws applications - we are using a list of all aws components that | ||
// have been identified in various OS - amazon linux, ubuntu, windows etc. | ||
// This is also useful for amazon linux ami - where all packages have Amazon.com as publisher. | ||
selectAwsApps = make(map[string]string) | ||
selectAwsApps[amazonSsmAgentLinux] = amazonPublisherName | ||
selectAwsApps[amazonSsmAgentWin] = amazonPublisherName | ||
selectAwsApps[awsToolsWindows] = amazonPublisherName | ||
selectAwsApps[ec2ConfigService] = amazonPublisherName | ||
selectAwsApps[awsCfnBootstrap] = amazonPublisherName | ||
selectAwsApps[awsPVDrivers] = amazonPublisherName | ||
} | ||
|
||
func componentType(applicationName string) model.ComponentType { | ||
formattedName := strings.TrimSpace(applicationName) | ||
formattedName = strings.ToLower(formattedName) | ||
|
||
var compType model.ComponentType | ||
|
||
//check if application is a known aws component or part of aws-apitool- or aws-amitools- tool set. | ||
if _, found := selectAwsApps[formattedName]; found || strings.Contains(formattedName, awsAPIToolsPrefix) || strings.Contains(formattedName, awsAMIToolsPrefix) { | ||
compType |= model.AWSComponent | ||
} | ||
|
||
return compType | ||
} | ||
|
||
func CollectApplicationData(context context.T) (appData []model.ApplicationData) { | ||
return collectPlatformDependentApplicationData(context) | ||
} |
35 changes: 35 additions & 0 deletions
35
agent/plugins/inventory/gatherers/application/dataProvider_test.go
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,35 @@ | ||
// Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may not | ||
// use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
// either express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
// Package application contains a application gatherer. | ||
package application | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/amazon-ssm-agent/agent/plugins/inventory/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestComponentType(t *testing.T) { | ||
awsComponents := []string{"amazon-ssm-agent", "aws-apitools-mon", "aws-amitools-ec2", "AWS Tools for Windows", "AWS PV Drivers"} | ||
nonawsComponents := []string{"Notepad++", "Google Update Helper", "accountsservice", "pcre", "kbd-misc"} | ||
|
||
for _, name := range awsComponents { | ||
assert.Equal(t, model.AWSComponent, componentType(name)) | ||
} | ||
|
||
for _, name := range nonawsComponents { | ||
assert.Equal(t, model.ComponentType(0), componentType(name)) | ||
} | ||
} |
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
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
Oops, something went wrong.