From a13232a11440cef851cfe4fc050b4ec7b66ec5ea Mon Sep 17 00:00:00 2001 From: Sherd White Date: Tue, 19 Sep 2023 18:02:27 -0500 Subject: [PATCH] feat(resource): adding rekognition project and dataset support --- resources/rekognition-dataset.go | 62 ++++++++++++++++++++++++++++++++ resources/rekognition-project.go | 60 +++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 resources/rekognition-dataset.go create mode 100644 resources/rekognition-project.go diff --git a/resources/rekognition-dataset.go b/resources/rekognition-dataset.go new file mode 100644 index 00000000..249d4f2c --- /dev/null +++ b/resources/rekognition-dataset.go @@ -0,0 +1,62 @@ +package resources + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/rekognition" +) + +type RekognitionDataset struct { + svc *rekognition.Rekognition + arn *string +} + +func init() { + register("RekognitionDataset", ListRekognitionDatasets) +} + +func ListRekognitionDatasets(sess *session.Session) ([]Resource, error) { + svc := rekognition.New(sess) + resources := []Resource{} + + params := &rekognition.DescribeProjectsInput{ + MaxResults: aws.Int64(100), + } + + for { + output, err := svc.DescribeProjects(params) + if err != nil { + return nil, err + } + + for _, project := range output.ProjectDescriptions { + for _, dataset := range project.Datasets { + resources = append(resources, &RekognitionDataset{ + svc: svc, + arn: dataset.DatasetArn, + }) + } + } + + if output.NextToken == nil { + break + } + + params.NextToken = output.NextToken + } + + return resources, nil +} + +func (f *RekognitionDataset) Remove() error { + + _, err := f.svc.DeleteDataset(&rekognition.DeleteDatasetInput{ + DatasetArn: f.arn, + }) + + return err +} + +func (f *RekognitionDataset) String() string { + return *f.arn +} diff --git a/resources/rekognition-project.go b/resources/rekognition-project.go new file mode 100644 index 00000000..59f2b0d7 --- /dev/null +++ b/resources/rekognition-project.go @@ -0,0 +1,60 @@ +package resources + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/rekognition" +) + +type RekognitionProject struct { + svc *rekognition.Rekognition + arn *string +} + +func init() { + register("RekognitionProject", ListRekognitionProjects) +} + +func ListRekognitionProjects(sess *session.Session) ([]Resource, error) { + svc := rekognition.New(sess) + resources := []Resource{} + + params := &rekognition.DescribeProjectsInput{ + MaxResults: aws.Int64(100), + } + + for { + output, err := svc.DescribeProjects(params) + if err != nil { + return nil, err + } + + for _, project := range output.ProjectDescriptions { + resources = append(resources, &RekognitionProject{ + svc: svc, + arn: project.ProjectArn, + }) + } + + if output.NextToken == nil { + break + } + + params.NextToken = output.NextToken + } + + return resources, nil +} + +func (f *RekognitionProject) Remove() error { + + _, err := f.svc.DeleteProject(&rekognition.DeleteProjectInput{ + ProjectArn: f.arn, + }) + + return err +} + +func (f *RekognitionProject) String() string { + return *f.arn +}