/
external_initiators_controller.go
47 lines (40 loc) · 1.6 KB
/
external_initiators_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package web
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
"github.com/smartcontractkit/chainlink/core/services"
"github.com/smartcontractkit/chainlink/core/store/models"
)
// ExternalInitiatorsController manages external initiators
type ExternalInitiatorsController struct {
App services.Application
}
// Create builds and saves a new service agreement record.
func (eic *ExternalInitiatorsController) Create(c *gin.Context) {
if !eic.App.GetStore().Config.Dev() {
jsonAPIError(c, http.StatusMethodNotAllowed, errors.New("External Initiators are currently under development and not yet usable outside of development mode"))
return
}
eia := models.NewExternalInitiatorAuthentication()
if ea, err := models.NewExternalInitiator(eia); err != nil {
jsonAPIError(c, http.StatusInternalServerError, err)
} else if err := eic.App.GetStore().CreateExternalInitiator(ea); err != nil {
jsonAPIError(c, http.StatusInternalServerError, err)
} else {
jsonAPIResponseWithStatus(c, eia, "external initiator authenticaion", http.StatusCreated)
}
}
// Destroy deletes an ExternalInitiator
func (eic *ExternalInitiatorsController) Destroy(c *gin.Context) {
if !eic.App.GetStore().Config.Dev() {
jsonAPIError(c, http.StatusMethodNotAllowed, errors.New("External Initiators are currently under development and not yet usable outside of development mode"))
return
}
id := c.Param("AccessKey")
if err := eic.App.GetStore().DeleteExternalInitiator(id); err != nil {
jsonAPIError(c, http.StatusInternalServerError, err)
} else {
jsonAPIResponseWithStatus(c, nil, "external initiator", http.StatusNoContent)
}
}