-
-
Notifications
You must be signed in to change notification settings - Fork 34
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 #158 from npellegrin/feature/sagemaker-app-space-u…
…serprofile feat(sagemaker-spaces): add support for Sagemaker Spaces
- Loading branch information
Showing
2 changed files
with
102 additions
and
1 deletion.
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
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,97 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
const SageMakerSpaceResource = "SageMakerSpace" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: SageMakerSpaceResource, | ||
Scope: nuke.Account, | ||
Lister: &SageMakerSpaceLister{}, | ||
}) | ||
} | ||
|
||
type SageMakerSpaceLister struct{} | ||
|
||
func (l *SageMakerSpaceLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := sagemaker.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
|
||
params := &sagemaker.ListSpacesInput{ | ||
MaxResults: aws.Int64(30), | ||
} | ||
|
||
for { | ||
resp, err := svc.ListSpaces(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, space := range resp.Spaces { | ||
resources = append(resources, &SageMakerSpace{ | ||
svc: svc, | ||
domainID: space.DomainId, | ||
spaceDisplayName: space.SpaceDisplayName, | ||
spaceName: space.SpaceName, | ||
status: space.Status, | ||
lastModifiedTime: space.LastModifiedTime, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
type SageMakerSpace struct { | ||
svc *sagemaker.SageMaker | ||
domainID *string | ||
spaceDisplayName *string | ||
spaceName *string | ||
status *string | ||
lastModifiedTime *time.Time | ||
} | ||
|
||
func (f *SageMakerSpace) Remove(_ context.Context) error { | ||
_, err := f.svc.DeleteSpace(&sagemaker.DeleteSpaceInput{ | ||
DomainId: f.domainID, | ||
SpaceName: f.spaceName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *SageMakerSpace) String() string { | ||
return *f.spaceName | ||
} | ||
|
||
func (f *SageMakerSpace) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties. | ||
Set("DomainID", f.domainID). | ||
Set("SpaceDisplayName", f.spaceDisplayName). | ||
Set("SpaceName", f.spaceName). | ||
Set("Status", f.status). | ||
Set("LastModifiedTime", f.lastModifiedTime) | ||
return properties | ||
} |