Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Description
Some of our newer code is implementing a consistent pattern for fetching remote resources via functions defined in a aws/internal/service/{SERVICE}/finder package. This issue is for documenting the existing implementation details of this for all contributors.
e.g.
package finder
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
)
// DocumentByName returns the Document corresponding to the specified name.
func DocumentByName(conn *ssm.SSM, name string) (*ssm.DocumentDescription, error) {
input := &ssm.DescribeDocumentInput{
Name: aws.String(name),
}
output, err := conn.DescribeDocument(input)
if err != nil {
return nil, err
}
if output == nil || output.Document == nil {
return nil, fmt.Errorf("error describing SSM Document (%s): empty result", name)
}
doc := output.Document
if aws.StringValue(doc.Status) == ssm.DocumentStatusFailed {
return nil, fmt.Errorf("Document is in a failed state: %s", aws.StringValue(doc.StatusInformation))
}
return output.Document, nil
}
// PatchGroup returns matching SSM Patch Group by Patch Group and BaselineId.
func PatchGroup(conn *ssm.SSM, patchGroup, baselineId string) (*ssm.PatchGroupPatchBaselineMapping, error) {
input := &ssm.DescribePatchGroupsInput{}
var result *ssm.PatchGroupPatchBaselineMapping
err := conn.DescribePatchGroupsPages(input, func(page *ssm.DescribePatchGroupsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
for _, mapping := range page.Mappings {
if mapping == nil {
continue
}
if aws.StringValue(mapping.PatchGroup) == patchGroup {
if mapping.BaselineIdentity != nil && aws.StringValue(mapping.BaselineIdentity.BaselineId) == baselineId {
result = mapping
return false
}
}
}
return !lastPage
})
return result, err
}
References
Community Note
Description
Some of our newer code is implementing a consistent pattern for fetching remote resources via functions defined in a
aws/internal/service/{SERVICE}/finderpackage. This issue is for documenting the existing implementation details of this for all contributors.e.g.
References