-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add:
delete sagemaker-user-profile
(#231)
- Loading branch information
1 parent
0ce9a0b
commit 536b7ac
Showing
7 changed files
with
150 additions
and
7 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
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,32 @@ | ||
package delete | ||
|
||
import ( | ||
"github.com/awslabs/eksdemo/pkg/resource" | ||
"github.com/awslabs/eksdemo/pkg/resource/sagemaker/userprofile" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var sagemaker []func() *resource.Resource | ||
|
||
func NewSageMakerCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "sagemaker", | ||
Short: "Amazon SageMaker Resources", | ||
Aliases: []string{"sm"}, | ||
} | ||
|
||
// Don't show flag errors for `delete sagemaker` without a subcommand | ||
cmd.DisableFlagParsing = true | ||
|
||
for _, sm := range sagemaker { | ||
cmd.AddCommand(sm().NewDeleteCmd()) | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func init() { | ||
sagemaker = []func() *resource.Resource{ | ||
userprofile.New, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,41 @@ | ||
package resource | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Manager interface { | ||
Create(options Options) error | ||
Delete(options Options) error | ||
Create(Options) error | ||
Delete(Options) error | ||
Init() | ||
SetDryRun() | ||
Update(options Options, cmd *cobra.Command) error | ||
Update(Options, *cobra.Command) error | ||
} | ||
|
||
type CreateNotSupported struct{} | ||
|
||
func (*CreateNotSupported) Create(_ Options) error { | ||
return fmt.Errorf("create not supported for this resource") | ||
} | ||
|
||
type DeleteNotSupported struct{} | ||
|
||
func (*DeleteNotSupported) Delete(_ Options) error { | ||
return fmt.Errorf("delete not supported for this resource") | ||
} | ||
|
||
type UpdateNotSupported struct{} | ||
|
||
func (*UpdateNotSupported) Update(_ Options, _ *cobra.Command) error { | ||
return fmt.Errorf("update not supported for this resource") | ||
} | ||
|
||
type DryRun struct { | ||
DryRun bool | ||
} | ||
|
||
func (m *DryRun) SetDryRun() { | ||
m.DryRun = true | ||
} |
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,57 @@ | ||
package userprofile | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
awssdk "github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/awslabs/eksdemo/pkg/aws" | ||
"github.com/awslabs/eksdemo/pkg/resource" | ||
) | ||
|
||
type Manager struct { | ||
resource.CreateNotSupported | ||
resource.DryRun | ||
resource.UpdateNotSupported | ||
sagemakerClient *aws.SageMakerClient | ||
userProfileGetter *Getter | ||
} | ||
|
||
func (m *Manager) Init() { | ||
if m.sagemakerClient == nil { | ||
m.sagemakerClient = aws.NewSageMakerClient() | ||
} | ||
m.userProfileGetter = NewGetter(m.sagemakerClient) | ||
} | ||
|
||
func (m *Manager) Delete(o resource.Options) error { | ||
options, ok := o.(*Options) | ||
if !ok { | ||
return fmt.Errorf("internal error, unable to cast options to userprofile.Options") | ||
} | ||
|
||
domainID := options.DomainID | ||
userProfileName := options.Name | ||
|
||
if domainID == "" { | ||
userProfile, err := m.userProfileGetter.GetUserProfileByName(userProfileName) | ||
|
||
if err != nil { | ||
var rnfe *resource.NotFoundByNameError | ||
if errors.As(err, &rnfe) { | ||
fmt.Printf("SageMaker User Profile with name %q does not exist\n", userProfileName) | ||
return nil | ||
} | ||
return err | ||
} | ||
domainID = awssdk.ToString(userProfile.DomainId) | ||
} | ||
|
||
err := m.sagemakerClient.DeleteUserProfile(domainID, userProfileName) | ||
if err != nil { | ||
return aws.FormatErrorAsMessageOnly(err) | ||
} | ||
fmt.Printf("SageMaker User Profile %q with Domain Id %q deleted\n", userProfileName, domainID) | ||
|
||
return nil | ||
} |
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