@@ -8,15 +8,15 @@ import (
88 "github.com/function61/gokit/jsonfile"
99 "github.com/function61/lambda-alertmanager/pkg/alertmanagertypes"
1010 "github.com/function61/lambda-alertmanager/pkg/amstate"
11- "github.com/function61/lambda-alertmanager/pkg/apigatewayutils "
11+ "github.com/function61/lambda-alertmanager/pkg/lambdautils "
1212 "os"
1313 "time"
1414)
1515
1616func handleRestCall (ctx context.Context , req events.APIGatewayProxyRequest ) (* events.APIGatewayProxyResponse , error ) {
1717 app , err := getApp (ctx )
1818 if err != nil {
19- return apigatewayutils .InternalServerError (err .Error ()), nil
19+ return lambdautils .InternalServerError (err .Error ()), nil
2020 }
2121
2222 synopsis := req .HTTPMethod + " " + req .Path
@@ -29,26 +29,26 @@ func handleRestCall(ctx context.Context, req events.APIGatewayProxyRequest) (*ev
2929 // pragmatic here because we want acks to be ack-able from emails
3030 id := req .QueryStringParameters ["id" ]
3131 if id == "" {
32- return apigatewayutils .BadRequest ("id not specified" ), nil
32+ return lambdautils .BadRequest ("id not specified" ), nil
3333 }
3434
3535 return handleAcknowledgeAlert (ctx , id )
3636 case "POST /alerts/ingest" :
3737 alert := amstate.Alert {}
3838 if err := jsonfile .Unmarshal (bytes .NewBufferString (req .Body ), & alert , true ); err != nil {
39- return apigatewayutils .BadRequest (err .Error ()), nil
39+ return lambdautils .BadRequest (err .Error ()), nil
4040 }
4141 alert .Id = amstate .NewAlertId ()
4242
4343 created , err := ingestAlertsAndReturnCreatedFlag (ctx , []amstate.Alert {alert }, app )
4444 if err != nil {
45- return apigatewayutils .InternalServerError (err .Error ()), nil
45+ return lambdautils .InternalServerError (err .Error ()), nil
4646 }
4747
4848 if created {
49- return apigatewayutils .Created (), nil
49+ return lambdautils .Created (), nil
5050 } else {
51- return apigatewayutils .NoContent (), nil
51+ return lambdautils .NoContent (), nil
5252 }
5353 case "GET /deadmansswitch/checkin" : // /deadmansswitch/checkin?subject=ubackup_done&ttl=24h30m
5454 // same semantic hack here as acknowledge endpoint
@@ -59,16 +59,16 @@ func handleRestCall(ctx context.Context, req events.APIGatewayProxyRequest) (*ev
5959 case "POST /deadmansswitch/checkin" : // {"subject":"ubackup_done","ttl":"24h30m"}
6060 checkin := alertmanagertypes.DeadMansSwitchCheckinRequest {}
6161 if err := jsonfile .Unmarshal (bytes .NewBufferString (req .Body ), & checkin , true ); err != nil {
62- return apigatewayutils .BadRequest (err .Error ()), nil
62+ return lambdautils .BadRequest (err .Error ()), nil
6363 }
6464
6565 return handleDeadMansSwitchCheckin (ctx , checkin )
6666 case "GET /deadmansswitches" :
6767 return handleGetDeadMansSwitches (ctx , app )
6868 case "POST /prometheus-alertmanager/api/v1/alerts" :
69- return apigatewayutils .InternalServerError ("not implemented yet" ), nil
69+ return lambdautils .InternalServerError ("not implemented yet" ), nil
7070 default :
71- return apigatewayutils .BadRequest (fmt .Sprintf ("unknown endpoint: %s" , synopsis )), nil
71+ return lambdautils .BadRequest (fmt .Sprintf ("unknown endpoint: %s" , synopsis )), nil
7272 }
7373}
7474
@@ -77,46 +77,46 @@ func handleGetAlerts(
7777 req events.APIGatewayProxyRequest ,
7878 app * amstate.App ,
7979) (* events.APIGatewayProxyResponse , error ) {
80- return apigatewayutils .RespondJson (app .State .ActiveAlerts ())
80+ return lambdautils .RespondJson (app .State .ActiveAlerts ())
8181}
8282
8383func handleAcknowledgeAlert (ctx context.Context , id string ) (* events.APIGatewayProxyResponse , error ) {
8484 if err := alertAck (ctx , id ); err != nil {
85- return apigatewayutils .InternalServerError (err .Error ()), nil
85+ return lambdautils .InternalServerError (err .Error ()), nil
8686 }
8787
88- return apigatewayutils .OkText (fmt .Sprintf ("Ack ok for %s" , id ))
88+ return lambdautils .OkText (fmt .Sprintf ("Ack ok for %s" , id ))
8989}
9090
9191func handleGetDeadMansSwitches (
9292 ctx context.Context ,
9393 app * amstate.App ,
9494) (* events.APIGatewayProxyResponse , error ) {
95- return apigatewayutils .RespondJson (app .State .DeadMansSwitches ())
95+ return lambdautils .RespondJson (app .State .DeadMansSwitches ())
9696}
9797
9898func handleDeadMansSwitchCheckin (ctx context.Context , raw alertmanagertypes.DeadMansSwitchCheckinRequest ) (* events.APIGatewayProxyResponse , error ) {
9999 if raw .Subject == "" || raw .TTL == "" {
100- return apigatewayutils .BadRequest ("subject or ttl empty" ), nil
100+ return lambdautils .BadRequest ("subject or ttl empty" ), nil
101101 }
102102
103103 now := time .Now ()
104104
105105 ttl , err := parseTtlSpec (raw .TTL , now )
106106 if err != nil {
107- return apigatewayutils .BadRequest (err .Error ()), nil
107+ return lambdautils .BadRequest (err .Error ()), nil
108108 }
109109
110110 alertAcked , err := deadmansswitchCheckin (ctx , raw .Subject , ttl )
111111 if err != nil {
112- return apigatewayutils .InternalServerError (err .Error ()), nil
112+ return lambdautils .InternalServerError (err .Error ()), nil
113113 }
114114
115115 if alertAcked {
116- return apigatewayutils .OkText ("Check-in noted; alert that was firing for this dead mans's switch was acked" )
116+ return lambdautils .OkText ("Check-in noted; alert that was firing for this dead mans's switch was acked" )
117117 }
118118
119- return apigatewayutils .OkText ("Check-in noted" )
119+ return lambdautils .OkText ("Check-in noted" )
120120}
121121
122122func ackLink (alert amstate.Alert ) string {
0 commit comments