2022-07-04 17:07:13 +00:00
|
|
|
package models
|
|
|
|
|
2022-07-12 06:18:42 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
2022-07-15 16:41:08 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/refs"
|
2022-07-12 06:18:42 +00:00
|
|
|
)
|
2022-07-08 13:39:23 +00:00
|
|
|
|
2022-07-04 17:07:13 +00:00
|
|
|
// Note: any change here should be reflected in providers/casandra/provider.go as it does not have model support in collection creation
|
|
|
|
|
|
|
|
// WebhookLog model for db
|
|
|
|
type WebhookLog struct {
|
2022-10-02 19:38:12 +00:00
|
|
|
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty" dynamo:"key,omitempty"` // for arangodb
|
|
|
|
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id" dynamo:"id,hash"`
|
|
|
|
HttpStatus int64 `json:"http_status" bson:"http_status" cql:"http_status" dynamo:"http_status"`
|
|
|
|
Response string `gorm:"type:text" json:"response" bson:"response" cql:"response" dynamo:"response"`
|
|
|
|
Request string `gorm:"type:text" json:"request" bson:"request" cql:"request" dynamo:"request"`
|
2022-10-05 10:02:32 +00:00
|
|
|
WebhookID string `gorm:"type:char(36)" json:"webhook_id" bson:"webhook_id" cql:"webhook_id" dynamo:"webhook_id" index:"webhook_id,hash"`
|
2022-10-02 19:38:12 +00:00
|
|
|
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at" dynamo:"created_at"`
|
|
|
|
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at" dynamo:"updated_at"`
|
2022-07-04 17:07:13 +00:00
|
|
|
}
|
2022-07-08 13:39:23 +00:00
|
|
|
|
2022-07-15 04:42:24 +00:00
|
|
|
// AsAPIWebhookLog to return webhook log as graphql response object
|
2022-07-08 13:39:23 +00:00
|
|
|
func (w *WebhookLog) AsAPIWebhookLog() *model.WebhookLog {
|
2022-07-12 06:18:42 +00:00
|
|
|
id := w.ID
|
|
|
|
if strings.Contains(id, Collections.WebhookLog+"/") {
|
|
|
|
id = strings.TrimPrefix(id, Collections.WebhookLog+"/")
|
|
|
|
}
|
2022-07-08 13:39:23 +00:00
|
|
|
return &model.WebhookLog{
|
2022-07-12 06:18:42 +00:00
|
|
|
ID: id,
|
2022-07-15 16:41:08 +00:00
|
|
|
HTTPStatus: refs.NewInt64Ref(w.HttpStatus),
|
|
|
|
Response: refs.NewStringRef(w.Response),
|
|
|
|
Request: refs.NewStringRef(w.Request),
|
|
|
|
WebhookID: refs.NewStringRef(w.WebhookID),
|
|
|
|
CreatedAt: refs.NewInt64Ref(w.CreatedAt),
|
|
|
|
UpdatedAt: refs.NewInt64Ref(w.UpdatedAt),
|
2022-07-08 13:39:23 +00:00
|
|
|
}
|
|
|
|
}
|