MCPcopy
hub / github.com/apache/devlake / PostApiKey

Function PostApiKey

backend/server/api/apikeys/apikeys.go:124–142  ·  view source on GitHub ↗

@Summary Create a new api key @Description Create a new api key @Tags framework/api-keys @Accept application/json @Param apikey body models.ApiInputApiKey true "json" @Success 200 {object} models.ApiOutputApiKey @Failure 400 {string} errcode.Error "Bad Request" @Failure 500 {string} errcode.Error

(c *gin.Context)

Source from the content-addressed store, hash-verified

122// @Failure 500 {string} errcode.Error "Internal Error"
123// @Router /api-keys [post]
124func PostApiKey(c *gin.Context) {
125 apiKeyInput := &models.ApiInputApiKey{}
126 err := c.ShouldBind(apiKeyInput)
127 if err != nil {
128 shared.ApiOutputError(c, errors.BadInput.Wrap(err, shared.BadRequestBody))
129 return
130 }
131 user, exist := shared.GetUser(c)
132 if !exist {
133 logruslog.Global.Warn(nil, "user doesn't exist")
134 }
135 apiKeyOutput, err := services.CreateApiKey(user, apiKeyInput)
136 if err != nil {
137 shared.ApiOutputError(c, errors.Default.Wrap(err, "error creating api key"))
138 return
139 }
140
141 shared.ApiOutputSuccess(c, apiKeyOutput, http.StatusCreated)
142}

Callers

nothing calls this directly

Calls 3

WrapMethod · 0.80
GetUserMethod · 0.80
WarnMethod · 0.65

Tested by

no test coverage detected