108 lines
2.1 KiB
Go
108 lines
2.1 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/v5"
|
|
"io"
|
|
"mime/multipart"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// dummy vars to prevent
|
|
// unused imports complain
|
|
var (
|
|
_ = chi.URLParam
|
|
_ = multipart.ErrMessageTooLarge
|
|
_ = payload.ParseUint64s
|
|
_ = strings.ToLower
|
|
_ = io.EOF
|
|
_ = fmt.Errorf
|
|
_ = json.NewEncoder
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
{
|
|
// Caching 32MB to memory, the rest to disk
|
|
if err = req.ParseMultipartForm(32 << 20); err != nil && err != http.ErrNotMultipart {
|
|
return err
|
|
} else if err == nil {
|
|
// Multipart params
|
|
|
|
if val, ok := req.MultipartForm.Value["userID"]; ok && len(val) > 0 {
|
|
r.UserID, err = payload.ParseUint64(val[0]), nil
|
|
if err != nil {
|
|
return 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
|
|
}
|