-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for updating instances (#27)
* PUT SSM Association * SPIN-2936: Implemented below update instances endpoints PUT "/{account}/instances/{id}" PUT "/{account}/instances/{id}/power" PUT "/{account}/instances/{id}/ssm/association" PUT "/{account}/instances/{id}/tags" PUT "/{account}/instances/{id}/attribute" * Fixed comments * Added policies * Role updated * updated PUT SSM * Print stack trace when encountering panic * Updated SSM Association * Fixed AssociationID output * Fixed unit testcase * Updated time format
- Loading branch information
Showing
9 changed files
with
395 additions
and
24 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
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
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,30 @@ | ||
package ec2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/YaleSpinup/apierror" | ||
"github.com/YaleSpinup/ec2-api/common" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (e *Ec2) UpdateAttributes(ctx context.Context, instanceType, instanceId string) error { | ||
if len(instanceId) == 0 || len(instanceType) == 0 { | ||
return apierror.New(apierror.ErrBadRequest, "invalid input", nil) | ||
} | ||
|
||
log.Infof("updating attributes: %v with instance type %+v", instanceId, instanceType) | ||
|
||
input := ec2.ModifyInstanceAttributeInput{ | ||
InstanceType: &ec2.AttributeValue{Value: aws.String(instanceType)}, | ||
InstanceId: aws.String(instanceId), | ||
} | ||
|
||
if _, err := e.Service.ModifyInstanceAttributeWithContext(ctx, &input); err != nil { | ||
return common.ErrCode("updating attributes", err) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ec2 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/aws/aws-sdk-go/service/ec2/ec2iface" | ||
) | ||
|
||
func (m *mockEC2Client) ModifyInstanceAttributeWithContext(ctx aws.Context, inp *ec2.ModifyInstanceAttributeInput, opt ...request.Option) (*ec2.ModifyInstanceAttributeOutput, error) { | ||
if m.err != nil { | ||
return nil, m.err | ||
} | ||
return &ec2.ModifyInstanceAttributeOutput{}, nil | ||
|
||
} | ||
func TestEc2_UpdateAttributes(t *testing.T) { | ||
type fields struct { | ||
Service ec2iface.EC2API | ||
} | ||
type args struct { | ||
ctx context.Context | ||
instanceType string | ||
instanceId string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
e *Ec2 | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "success case", | ||
args: args{ctx: context.TODO(), instanceType: "Type1", instanceId: "i-123"}, | ||
fields: fields{Service: newmockEC2Client(t, nil)}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "aws error", | ||
args: args{ctx: context.TODO(), instanceType: "Type1", instanceId: "i-123"}, | ||
fields: fields{Service: newmockEC2Client(t, awserr.New("Bad Request", "boom.", nil))}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid input, instance id is empty", | ||
args: args{ctx: context.TODO(), instanceType: "Type1", instanceId: ""}, | ||
fields: fields{Service: newmockEC2Client(t, nil)}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid input, instance type is empty", | ||
args: args{ctx: context.TODO(), instanceType: "", instanceId: "i-123"}, | ||
fields: fields{Service: newmockEC2Client(t, nil)}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
e := &Ec2{ | ||
Service: tt.fields.Service, | ||
} | ||
if err := e.UpdateAttributes(tt.args.ctx, tt.args.instanceType, tt.args.instanceId); (err != nil) != tt.wantErr { | ||
t.Errorf("Ec2.UpdateAttributes() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.