-
-
Notifications
You must be signed in to change notification settings - Fork 38
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 #359 from ekristen/rebuy-1102
feat(resource): implement multiple transcribe service resources
- Loading branch information
Showing
8 changed files
with
795 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/service/transcribeservice" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
) | ||
|
||
const TranscribeCallAnalyticsCategoryResource = "TranscribeCallAnalyticsCategory" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: TranscribeCallAnalyticsCategoryResource, | ||
Scope: nuke.Account, | ||
Lister: &TranscribeCallAnalyticsCategoryLister{}, | ||
}) | ||
} | ||
|
||
type TranscribeCallAnalyticsCategoryLister struct{} | ||
|
||
func (l *TranscribeCallAnalyticsCategoryLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := transcribeservice.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
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 | ||
} | ||
|
||
type TranscribeCallAnalyticsCategory struct { | ||
svc *transcribeservice.TranscribeService | ||
name *string | ||
inputType *string | ||
createTime *time.Time | ||
lastUpdateTime *time.Time | ||
} | ||
|
||
func (r *TranscribeCallAnalyticsCategory) Remove(_ context.Context) error { | ||
deleteInput := &transcribeservice.DeleteCallAnalyticsCategoryInput{ | ||
CategoryName: r.name, | ||
} | ||
_, err := r.svc.DeleteCallAnalyticsCategory(deleteInput) | ||
return err | ||
} | ||
|
||
func (r *TranscribeCallAnalyticsCategory) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Name", r.name) | ||
properties.Set("InputType", r.inputType) | ||
properties.Set("CreateTime", r.createTime) | ||
properties.Set("LastUpdateTime", r.lastUpdateTime) | ||
return properties | ||
} | ||
|
||
func (r *TranscribeCallAnalyticsCategory) String() string { | ||
return *r.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/transcribeservice" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
) | ||
|
||
const TranscribeCallAnalyticsJobResource = "TranscribeCallAnalyticsJob" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: TranscribeCallAnalyticsJobResource, | ||
Scope: nuke.Account, | ||
Lister: &TranscribeCallAnalyticsJobLister{}, | ||
}) | ||
} | ||
|
||
type TranscribeCallAnalyticsJobLister struct{} | ||
|
||
func (l *TranscribeCallAnalyticsJobLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := transcribeservice.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
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 | ||
} | ||
|
||
type TranscribeCallAnalyticsJob struct { | ||
svc *transcribeservice.TranscribeService | ||
name *string | ||
status *string | ||
completionTime *time.Time | ||
creationTime *time.Time | ||
failureReason *string | ||
languageCode *string | ||
startTime *time.Time | ||
} | ||
|
||
func (r *TranscribeCallAnalyticsJob) Remove(_ context.Context) error { | ||
deleteInput := &transcribeservice.DeleteCallAnalyticsJobInput{ | ||
CallAnalyticsJobName: r.name, | ||
} | ||
_, err := r.svc.DeleteCallAnalyticsJob(deleteInput) | ||
return err | ||
} | ||
|
||
func (r *TranscribeCallAnalyticsJob) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Name", r.name) | ||
properties.Set("Status", r.status) | ||
properties.Set("CompletionTime", r.completionTime) | ||
properties.Set("CreationTime", r.creationTime) | ||
properties.Set("FailureReason", r.failureReason) | ||
properties.Set("LanguageCode", r.languageCode) | ||
properties.Set("StartTime", r.startTime) | ||
return properties | ||
} | ||
|
||
func (r *TranscribeCallAnalyticsJob) String() string { | ||
return *r.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/transcribeservice" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
) | ||
|
||
const TranscribeLanguageModelResource = "TranscribeLanguageModel" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: TranscribeLanguageModelResource, | ||
Scope: nuke.Account, | ||
Lister: &TranscribeLanguageModelLister{}, | ||
}) | ||
} | ||
|
||
type TranscribeLanguageModelLister struct{} | ||
|
||
func (l *TranscribeLanguageModelLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := transcribeservice.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
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 | ||
} | ||
|
||
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 (r *TranscribeLanguageModel) Remove(_ context.Context) error { | ||
deleteInput := &transcribeservice.DeleteLanguageModelInput{ | ||
ModelName: r.name, | ||
} | ||
_, err := r.svc.DeleteLanguageModel(deleteInput) | ||
return err | ||
} | ||
|
||
func (r *TranscribeLanguageModel) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Name", r.name) | ||
properties.Set("BaseModelName", r.baseModelName) | ||
properties.Set("CreateTime", r.createTime) | ||
properties.Set("FailureReason", r.failureReason) | ||
properties.Set("LanguageCode", r.languageCode) | ||
properties.Set("LastModifiedTime", r.lastModifiedTime) | ||
properties.Set("ModelStatus", r.modelStatus) | ||
properties.Set("UpgradeAvailability", r.upgradeAvailability) | ||
return properties | ||
} | ||
|
||
func (r *TranscribeLanguageModel) String() string { | ||
return *r.name | ||
} |
Oops, something went wrong.