3
0
Files
corteza/system/rest/request/auth.go

87 lines
1.7 KiB
Go

package request
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
//
import (
"encoding/json"
"fmt"
"github.com/cortezaproject/corteza-server/pkg/payload"
"github.com/go-chi/chi"
"io"
"mime/multipart"
"net/http"
"strings"
)
// dummy vars to prevent
// unused imports complain
var (
_ = chi.URLParam
_ = multipart.ErrMessageTooLarge
_ = payload.ParseUint64s
)
type (
// Internal API interface
AuthImpersonate struct {
// UserID POST parameter
//
// ID of the impersonated user
UserID uint64 `json:",string"`
}
)
// NewAuthImpersonate request
func NewAuthImpersonate() *AuthImpersonate {
return &AuthImpersonate{}
}
// Auditable returns all auditable/loggable parameters
func (r AuthImpersonate) Auditable() map[string]interface{} {
return map[string]interface{}{
"userID": r.UserID,
}
}
// Auditable returns all auditable/loggable parameters
func (r AuthImpersonate) GetUserID() uint64 {
return r.UserID
}
// Fill processes request and fills internal variables
func (r *AuthImpersonate) Fill(req *http.Request) (err error) {
if strings.ToLower(req.Header.Get("content-type")) == "application/json" {
err = json.NewDecoder(req.Body).Decode(r)
switch {
case err == io.EOF:
err = nil
case err != nil:
return fmt.Errorf("error parsing http request body: %w", err)
}
}
{
if err = req.ParseForm(); err != nil {
return err
}
// POST params
if val, ok := req.Form["userID"]; ok && len(val) > 0 {
r.UserID, err = payload.ParseUint64(val[0]), nil
if err != nil {
return err
}
}
}
return err
}