From 08cd574bc7a88c7a1243ab08746a2c36bc543df0 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 6 Sep 2023 14:22:42 -0500 Subject: [PATCH] Add Transcribe support (#13) * Add TranscribeCallAnalyticsCategory resource * Add TranscribeCallAnalyticsJob resource * Add TranscribeLanguageModel resource * Add TranscribeMedicalTranscriptionJob resource * Add TranscribeMedicalVocabulary resource * Add TranscribeTranscriptionJob resource * Add TranscribeVocabulary resource * Add TranscribeVocabularyFilter resource * go fmt formatting fixes --- .../transcribe-call-analytics-categories.go | 77 +++++++++++++ resources/transcribe-call-analytics-jobs.go | 90 ++++++++++++++++ resources/transcribe-language-models.go | 91 ++++++++++++++++ .../transcribe-medical-transcription-jobs.go | 102 ++++++++++++++++++ resources/transcribe-medical-vocabularies.go | 77 +++++++++++++ resources/transcribe-transcription-jobs.go | 90 ++++++++++++++++ resources/transcribe-vocabularies.go | 77 +++++++++++++ resources/transcribe-vocabulary-filter.go | 74 +++++++++++++ 8 files changed, 678 insertions(+) create mode 100644 resources/transcribe-call-analytics-categories.go create mode 100644 resources/transcribe-call-analytics-jobs.go create mode 100644 resources/transcribe-language-models.go create mode 100644 resources/transcribe-medical-transcription-jobs.go create mode 100644 resources/transcribe-medical-vocabularies.go create mode 100644 resources/transcribe-transcription-jobs.go create mode 100644 resources/transcribe-vocabularies.go create mode 100644 resources/transcribe-vocabulary-filter.go diff --git a/resources/transcribe-call-analytics-categories.go b/resources/transcribe-call-analytics-categories.go new file mode 100644 index 000000000..892b27d3e --- /dev/null +++ b/resources/transcribe-call-analytics-categories.go @@ -0,0 +1,77 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeCallAnalyticsCategory struct { + svc *transcribeservice.TranscribeService + name *string + inputType *string + createTime *time.Time + lastUpdateTime *time.Time +} + +func init() { + register("TranscribeCallAnalyticsCategory", ListTranscribeCallAnalyticsCategories) +} + +func ListTranscribeCallAnalyticsCategories(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listCallAnalyticsCategoriesInput := &transcribeservice.ListCallAnalyticsCategoriesInput{ + NextToken: nextToken, + } + + listOutput, err := svc.ListCallAnalyticsCategories(listCallAnalyticsCategoriesInput) + if err != nil { + return nil, err + } + for _, category := range listOutput.Categories { + resources = append(resources, &TranscribeCallAnalyticsCategory{ + svc: svc, + name: category.CategoryName, + inputType: category.InputType, + createTime: category.CreateTime, + lastUpdateTime: category.LastUpdateTime, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (category *TranscribeCallAnalyticsCategory) Remove() error { + deleteInput := &transcribeservice.DeleteCallAnalyticsCategoryInput{ + CategoryName: category.name, + } + _, err := category.svc.DeleteCallAnalyticsCategory(deleteInput) + return err +} + +func (category *TranscribeCallAnalyticsCategory) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", category.name) + properties.Set("InputType", category.inputType) + if category.createTime != nil { + properties.Set("CreateTime", category.createTime.Format(time.RFC3339)) + } + if category.lastUpdateTime != nil { + properties.Set("LastUpdateTime", category.lastUpdateTime.Format(time.RFC3339)) + } + return properties +} diff --git a/resources/transcribe-call-analytics-jobs.go b/resources/transcribe-call-analytics-jobs.go new file mode 100644 index 000000000..4971c9fbc --- /dev/null +++ b/resources/transcribe-call-analytics-jobs.go @@ -0,0 +1,90 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeCallAnalyticsJob struct { + svc *transcribeservice.TranscribeService + name *string + status *string + completionTime *time.Time + creationTime *time.Time + failureReason *string + languageCode *string + startTime *time.Time +} + +func init() { + register("TranscribeCallAnalyticsJob", ListTranscribeCallAnalyticsJobs) +} + +func ListTranscribeCallAnalyticsJobs(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listCallAnalyticsJobsInput := &transcribeservice.ListCallAnalyticsJobsInput{ + MaxResults: aws.Int64(100), + NextToken: nextToken, + } + + listOutput, err := svc.ListCallAnalyticsJobs(listCallAnalyticsJobsInput) + if err != nil { + return nil, err + } + for _, job := range listOutput.CallAnalyticsJobSummaries { + resources = append(resources, &TranscribeCallAnalyticsJob{ + svc: svc, + name: job.CallAnalyticsJobName, + status: job.CallAnalyticsJobStatus, + completionTime: job.CompletionTime, + creationTime: job.CreationTime, + failureReason: job.FailureReason, + languageCode: job.LanguageCode, + startTime: job.StartTime, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (job *TranscribeCallAnalyticsJob) Remove() error { + deleteInput := &transcribeservice.DeleteCallAnalyticsJobInput{ + CallAnalyticsJobName: job.name, + } + _, err := job.svc.DeleteCallAnalyticsJob(deleteInput) + return err +} + +func (job *TranscribeCallAnalyticsJob) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", job.name) + properties.Set("Status", job.status) + if job.completionTime != nil { + properties.Set("CompletionTime", job.completionTime.Format(time.RFC3339)) + } + if job.creationTime != nil { + properties.Set("CreationTime", job.creationTime.Format(time.RFC3339)) + } + properties.Set("FailureReason", job.failureReason) + properties.Set("LanguageCode", job.languageCode) + if job.startTime != nil { + properties.Set("StartTime", job.startTime.Format(time.RFC3339)) + } + return properties +} diff --git a/resources/transcribe-language-models.go b/resources/transcribe-language-models.go new file mode 100644 index 000000000..aab986e80 --- /dev/null +++ b/resources/transcribe-language-models.go @@ -0,0 +1,91 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeLanguageModel struct { + svc *transcribeservice.TranscribeService + name *string + baseModelName *string + createTime *time.Time + failureReason *string + languageCode *string + lastModifiedTime *time.Time + modelStatus *string + upgradeAvailability *bool +} + +func init() { + register("TranscribeLanguageModel", ListTranscribeLanguageModels) +} + +func ListTranscribeLanguageModels(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listLanguageModelsInput := &transcribeservice.ListLanguageModelsInput{ + MaxResults: aws.Int64(100), + NextToken: nextToken, + } + + listOutput, err := svc.ListLanguageModels(listLanguageModelsInput) + if err != nil { + return nil, err + } + for _, model := range listOutput.Models { + resources = append(resources, &TranscribeLanguageModel{ + svc: svc, + name: model.ModelName, + baseModelName: model.BaseModelName, + createTime: model.CreateTime, + failureReason: model.FailureReason, + languageCode: model.LanguageCode, + lastModifiedTime: model.LastModifiedTime, + modelStatus: model.ModelStatus, + upgradeAvailability: model.UpgradeAvailability, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (model *TranscribeLanguageModel) Remove() error { + deleteInput := &transcribeservice.DeleteLanguageModelInput{ + ModelName: model.name, + } + _, err := model.svc.DeleteLanguageModel(deleteInput) + return err +} + +func (model *TranscribeLanguageModel) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", model.name) + properties.Set("BaseModelName", model.baseModelName) + if model.createTime != nil { + properties.Set("CreateTime", model.createTime.Format(time.RFC3339)) + } + properties.Set("FailureReason", model.failureReason) + properties.Set("LanguageCode", model.languageCode) + if model.lastModifiedTime != nil { + properties.Set("LastModifiedTime", model.lastModifiedTime.Format(time.RFC3339)) + } + properties.Set("ModelStatus", model.modelStatus) + properties.Set("UpgradeAvailability", model.upgradeAvailability) + return properties +} diff --git a/resources/transcribe-medical-transcription-jobs.go b/resources/transcribe-medical-transcription-jobs.go new file mode 100644 index 000000000..6547421ce --- /dev/null +++ b/resources/transcribe-medical-transcription-jobs.go @@ -0,0 +1,102 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeMedicalTranscriptionJob struct { + svc *transcribeservice.TranscribeService + name *string + status *string + completionTime *time.Time + contentIdentificationType *string + creationTime *time.Time + failureReason *string + languageCode *string + outputLocationType *string + specialty *string + startTime *time.Time + inputType *string +} + +func init() { + register("TranscribeMedicalTranscriptionJob", ListTranscribeMedicalTranscriptionJobs) +} + +func ListTranscribeMedicalTranscriptionJobs(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listMedicalTranscriptionJobsInput := &transcribeservice.ListMedicalTranscriptionJobsInput{ + MaxResults: aws.Int64(100), + NextToken: nextToken, + } + + listOutput, err := svc.ListMedicalTranscriptionJobs(listMedicalTranscriptionJobsInput) + if err != nil { + return nil, err + } + for _, job := range listOutput.MedicalTranscriptionJobSummaries { + resources = append(resources, &TranscribeMedicalTranscriptionJob{ + svc: svc, + name: job.MedicalTranscriptionJobName, + status: job.TranscriptionJobStatus, + completionTime: job.CompletionTime, + contentIdentificationType: job.ContentIdentificationType, + creationTime: job.CreationTime, + failureReason: job.FailureReason, + languageCode: job.LanguageCode, + outputLocationType: job.OutputLocationType, + specialty: job.Specialty, + startTime: job.StartTime, + inputType: job.Type, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (job *TranscribeMedicalTranscriptionJob) Remove() error { + deleteInput := &transcribeservice.DeleteMedicalTranscriptionJobInput{ + MedicalTranscriptionJobName: job.name, + } + _, err := job.svc.DeleteMedicalTranscriptionJob(deleteInput) + return err +} + +func (job *TranscribeMedicalTranscriptionJob) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", job.name) + properties.Set("Status", job.status) + if job.completionTime != nil { + properties.Set("CompletionTime", job.completionTime.Format(time.RFC3339)) + } + properties.Set("ContentIdentificationType", job.contentIdentificationType) + if job.creationTime != nil { + properties.Set("CreationTime", job.creationTime.Format(time.RFC3339)) + } + properties.Set("FailureReason", job.failureReason) + properties.Set("LanguageCode", job.languageCode) + properties.Set("OutputLocationType", job.outputLocationType) + properties.Set("Specialty", job.specialty) + if job.startTime != nil { + properties.Set("StartTime", job.startTime.Format(time.RFC3339)) + } + properties.Set("InputType", job.inputType) + return properties +} diff --git a/resources/transcribe-medical-vocabularies.go b/resources/transcribe-medical-vocabularies.go new file mode 100644 index 000000000..0f4b1ffa4 --- /dev/null +++ b/resources/transcribe-medical-vocabularies.go @@ -0,0 +1,77 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeMedicalVocabulary struct { + svc *transcribeservice.TranscribeService + name *string + state *string + languageCode *string + lastModifiedTime *time.Time +} + +func init() { + register("TranscribeMedicalVocabulary", ListTranscribeMedicalVocabularies) +} + +func ListTranscribeMedicalVocabularies(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listMedicalVocabulariesInput := &transcribeservice.ListMedicalVocabulariesInput{ + MaxResults: aws.Int64(100), + NextToken: nextToken, + } + + listOutput, err := svc.ListMedicalVocabularies(listMedicalVocabulariesInput) + if err != nil { + return nil, err + } + for _, vocab := range listOutput.Vocabularies { + resources = append(resources, &TranscribeMedicalVocabulary{ + svc: svc, + name: vocab.VocabularyName, + state: vocab.VocabularyState, + languageCode: vocab.LanguageCode, + lastModifiedTime: vocab.LastModifiedTime, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (vocab *TranscribeMedicalVocabulary) Remove() error { + deleteInput := &transcribeservice.DeleteMedicalVocabularyInput{ + VocabularyName: vocab.name, + } + _, err := vocab.svc.DeleteMedicalVocabulary(deleteInput) + return err +} + +func (vocab *TranscribeMedicalVocabulary) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", vocab.name) + properties.Set("State", vocab.state) + properties.Set("LanguageCode", vocab.languageCode) + if vocab.lastModifiedTime != nil { + properties.Set("LastModifiedTime", vocab.lastModifiedTime.Format(time.RFC3339)) + } + return properties +} diff --git a/resources/transcribe-transcription-jobs.go b/resources/transcribe-transcription-jobs.go new file mode 100644 index 000000000..b4ff71f79 --- /dev/null +++ b/resources/transcribe-transcription-jobs.go @@ -0,0 +1,90 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeTranscriptionJob struct { + svc *transcribeservice.TranscribeService + name *string + status *string + completionTime *time.Time + creationTime *time.Time + failureReason *string + languageCode *string + startTime *time.Time +} + +func init() { + register("TranscribeTranscriptionJob", ListTranscribeTranscriptionJobs) +} + +func ListTranscribeTranscriptionJobs(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listTranscriptionJobsInput := &transcribeservice.ListTranscriptionJobsInput{ + MaxResults: aws.Int64(100), + NextToken: nextToken, + } + + listOutput, err := svc.ListTranscriptionJobs(listTranscriptionJobsInput) + if err != nil { + return nil, err + } + for _, job := range listOutput.TranscriptionJobSummaries { + resources = append(resources, &TranscribeTranscriptionJob{ + svc: svc, + name: job.TranscriptionJobName, + status: job.TranscriptionJobStatus, + completionTime: job.CompletionTime, + creationTime: job.CreationTime, + failureReason: job.FailureReason, + languageCode: job.LanguageCode, + startTime: job.StartTime, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (job *TranscribeTranscriptionJob) Remove() error { + deleteInput := &transcribeservice.DeleteTranscriptionJobInput{ + TranscriptionJobName: job.name, + } + _, err := job.svc.DeleteTranscriptionJob(deleteInput) + return err +} + +func (job *TranscribeTranscriptionJob) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", job.name) + properties.Set("Status", job.status) + if job.completionTime != nil { + properties.Set("CompletionTime", job.completionTime.Format(time.RFC3339)) + } + if job.creationTime != nil { + properties.Set("CreationTime", job.creationTime.Format(time.RFC3339)) + } + properties.Set("FailureReason", job.failureReason) + properties.Set("LanguageCode", job.languageCode) + if job.startTime != nil { + properties.Set("StartTime", job.startTime.Format(time.RFC3339)) + } + return properties +} diff --git a/resources/transcribe-vocabularies.go b/resources/transcribe-vocabularies.go new file mode 100644 index 000000000..18771b24d --- /dev/null +++ b/resources/transcribe-vocabularies.go @@ -0,0 +1,77 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeVocabulary struct { + svc *transcribeservice.TranscribeService + name *string + state *string + languageCode *string + lastModifiedTime *time.Time +} + +func init() { + register("TranscribeVocabulary", ListTranscribeVocabularies) +} + +func ListTranscribeVocabularies(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listVocabulariesInput := &transcribeservice.ListVocabulariesInput{ + MaxResults: aws.Int64(100), + NextToken: nextToken, + } + + listOutput, err := svc.ListVocabularies(listVocabulariesInput) + if err != nil { + return nil, err + } + for _, vocab := range listOutput.Vocabularies { + resources = append(resources, &TranscribeVocabulary{ + svc: svc, + name: vocab.VocabularyName, + state: vocab.VocabularyState, + languageCode: vocab.LanguageCode, + lastModifiedTime: vocab.LastModifiedTime, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (vocab *TranscribeVocabulary) Remove() error { + deleteInput := &transcribeservice.DeleteVocabularyInput{ + VocabularyName: vocab.name, + } + _, err := vocab.svc.DeleteVocabulary(deleteInput) + return err +} + +func (vocab *TranscribeVocabulary) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", vocab.name) + properties.Set("State", vocab.state) + properties.Set("LanguageCode", vocab.languageCode) + if vocab.lastModifiedTime != nil { + properties.Set("LastModifiedTime", vocab.lastModifiedTime.Format(time.RFC3339)) + } + return properties +} diff --git a/resources/transcribe-vocabulary-filter.go b/resources/transcribe-vocabulary-filter.go new file mode 100644 index 000000000..d3c518977 --- /dev/null +++ b/resources/transcribe-vocabulary-filter.go @@ -0,0 +1,74 @@ +package resources + +import ( + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/transcribeservice" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type TranscribeVocabularyFilter struct { + svc *transcribeservice.TranscribeService + name *string + languageCode *string + lastModifiedTime *time.Time +} + +func init() { + register("TranscribeVocabularyFilter", ListTranscribeVocabularyFilters) +} + +func ListTranscribeVocabularyFilters(sess *session.Session) ([]Resource, error) { + svc := transcribeservice.New(sess) + resources := []Resource{} + var nextToken *string + + for { + listVocabularyFiltersInput := &transcribeservice.ListVocabularyFiltersInput{ + MaxResults: aws.Int64(100), + NextToken: nextToken, + } + + listOutput, err := svc.ListVocabularyFilters(listVocabularyFiltersInput) + if err != nil { + return nil, err + } + for _, filter := range listOutput.VocabularyFilters { + resources = append(resources, &TranscribeVocabularyFilter{ + svc: svc, + name: filter.VocabularyFilterName, + languageCode: filter.LanguageCode, + lastModifiedTime: filter.LastModifiedTime, + }) + } + + // Check if there are more results + if listOutput.NextToken == nil { + break // No more results, exit the loop + } + + // Set the nextToken for the next iteration + nextToken = listOutput.NextToken + } + return resources, nil +} + +func (filter *TranscribeVocabularyFilter) Remove() error { + deleteInput := &transcribeservice.DeleteVocabularyFilterInput{ + VocabularyFilterName: filter.name, + } + _, err := filter.svc.DeleteVocabularyFilter(deleteInput) + return err +} + +func (filter *TranscribeVocabularyFilter) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", filter.name) + properties.Set("LanguageCode", filter.languageCode) + if filter.lastModifiedTime != nil { + properties.Set("LastModifiedTime", filter.lastModifiedTime.Format(time.RFC3339)) + } + return properties +}