ЛР7 на 4: HTTPS, mTLS, OpenBao AppRole и ротация leaf.
Skeleton contracts / contracts (pull_request) Blocked by required conditions

Smoke/security/grade4/persistence/failover пройдены; REPORT и DEFENSE.
This commit is contained in:
2026-12-02 23:08:27 +03:00
parent 20afc2c790
commit 2f2047909f
182 changed files with 15169 additions and 90 deletions
+98
View File
@@ -0,0 +1,98 @@
package dto
import (
"time"
"unicode"
"unicode/utf8"
"github.com/google/uuid"
"gavrilenko-sxdees/lab7/internal/model"
)
type CreateAttachmentRequest struct {
Filename string
}
type GetAttachmentContentRequest struct {
Variant string
}
type VariantResponse struct {
Name model.AttachmentVariantName `json:"name"`
ContentType model.ContentType `json:"content_type"`
SizeBytes int `json:"size_bytes"`
Width int `json:"width"`
Height int `json:"height"`
Sha256 string `json:"sha256"`
}
type AttachmentResponse struct {
ID uuid.UUID `json:"id"`
ChatID uuid.UUID `json:"chat_id"`
OwnerID uuid.UUID `json:"owner_id"`
Filename string `json:"filename"`
ContentType model.ContentType `json:"content_type"`
SizeBytes int `json:"size_bytes"`
Sha256 string `json:"sha256"`
Status model.AttachmentStatus `json:"status"`
Variants []VariantResponse `json:"variants"`
ErrorCode *string `json:"error_code"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (r CreateAttachmentRequest) Validate() bool {
if n := utf8.RuneCountInString(r.Filename); n < 1 || n > 255 {
return false
}
for _, ch := range r.Filename {
if ch == '/' || ch == '\\' || ch == 0 || unicode.IsControl(ch) {
return false
}
}
return true
}
func (r GetAttachmentContentRequest) Validate() bool {
switch model.AttachmentVariantName(r.Variant) {
case "",
model.AttachmentContentOriginal,
model.AttachmentVariantNameThumbnail,
model.AttachmentVariantNameCrop,
model.AttachmentVariantNameOptimized:
return true
default:
return false
}
}
func ToAttachmentResponse(a model.Attachment) AttachmentResponse {
variants := make([]VariantResponse, 0, len(a.Variants))
for _, v := range a.Variants {
variants = append(variants, VariantResponse{
Name: v.Name,
ContentType: v.ContentType,
SizeBytes: v.SizeBytes,
Width: v.Width,
Height: v.Height,
Sha256: v.Sha256,
})
}
return AttachmentResponse{
ID: a.ID,
ChatID: a.ChatID,
OwnerID: a.OwnerID,
Filename: a.Filename,
ContentType: a.ContentType,
SizeBytes: a.SizeBytes,
Sha256: a.Sha256,
Status: a.Status,
Variants: variants,
ErrorCode: a.ErrorCode,
CreatedAt: a.CreatedAt,
UpdatedAt: a.UpdatedAt,
}
}
+50
View File
@@ -0,0 +1,50 @@
package dto
import (
"gavrilenko-sxdees/lab7/internal/model"
"strings"
"time"
"unicode/utf8"
"github.com/google/uuid"
)
type CreateChatRequest struct {
Title string `json:"title"`
MemberIDs []uuid.UUID `json:"member_ids"`
}
type ChatResponse struct {
ID uuid.UUID `json:"id"`
Title string `json:"title"`
MemberIDs []uuid.UUID `json:"member_ids"`
CreatedAt time.Time `json:"created_at"`
}
type ChatPageResponse struct {
Items []ChatResponse `json:"items"`
NextCursor *string `json:"next_cursor"`
}
func (r CreateChatRequest) Validate() bool {
if strings.TrimSpace(r.Title) == "" ||
strings.ContainsRune(r.Title, 0) ||
utf8.RuneCountInString(r.Title) > 100 {
return false
}
if len(r.MemberIDs) < 1 || len(r.MemberIDs) > 100 {
return false
}
return true
}
func ToChatResponse(c model.Chat) ChatResponse {
return ChatResponse{
ID: c.ID,
Title: c.Title,
MemberIDs: c.MemberIDs,
CreatedAt: c.CreatedAt,
}
}
+25
View File
@@ -0,0 +1,25 @@
package dto
type ErrorCode string
const (
ErrorCodeInvalidRequest ErrorCode = "invalid_request"
ErrorCodeUnauthorized ErrorCode = "unauthorized"
ErrorCodeNotFound ErrorCode = "not_found"
ErrorCodeConflict ErrorCode = "conflict"
ErrorCodePayloadTooLarge ErrorCode = "payload_too_large"
ErrorCodeUnsupportedMediaType ErrorCode = "unsupported_media_type"
ErrorCodeRateLimited ErrorCode = "rate_limited"
ErrorCodeUnavailable ErrorCode = "unavailable"
ErrorCodeInternalError ErrorCode = "internal_error"
)
type ErrorResponse struct {
Error Error `json:"error"`
}
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
RequestID string `json:"request_id"`
}
+5
View File
@@ -0,0 +1,5 @@
package dto
type HealthResponse struct {
Status string `json:"status"`
}
+64
View File
@@ -0,0 +1,64 @@
package dto
import (
"gavrilenko-sxdees/lab7/internal/model"
"strings"
"time"
"unicode/utf8"
"github.com/google/uuid"
)
type CreateMessageRequest struct {
Text string `json:"text"`
AttachmentIDs []string `json:"attachment_ids"`
}
type MessageResponse struct {
ID uuid.UUID `json:"id"`
ChatID uuid.UUID `json:"chat_id"`
SenderID uuid.UUID `json:"sender_id"`
Text string `json:"text"`
AttachmentIDs []uuid.UUID `json:"attachment_ids"`
CreatedAt time.Time `json:"created_at"`
}
type MessagePageResponse struct {
Items []MessageResponse `json:"items"`
NextCursor *string `json:"next_cursor"`
}
func (r CreateMessageRequest) Validate() bool {
if strings.ContainsRune(r.Text, 0) || utf8.RuneCountInString(r.Text) > 4000 {
return false
}
if len(r.AttachmentIDs) > 10 {
return false
}
seen := make(map[string]struct{}, len(r.AttachmentIDs))
for _, id := range r.AttachmentIDs {
if _, ok := seen[id]; ok {
return false
}
seen[id] = struct{}{}
}
hasText := strings.TrimSpace(r.Text) != ""
hasAttachment := len(r.AttachmentIDs) > 0
return hasText || hasAttachment
}
func ToMessageResponse(m model.Message) MessageResponse {
ids := make([]uuid.UUID, len(m.AttachmentIDs))
copy(ids, m.AttachmentIDs)
return MessageResponse{
ID: m.ID,
ChatID: m.ChatID,
SenderID: m.SenderID,
Text: m.Text,
AttachmentIDs: ids,
CreatedAt: m.CreatedAt,
}
}
+10
View File
@@ -0,0 +1,10 @@
package dto
import "time"
type SessionResponse struct {
Token string `json:"token"`
TokenType string `json:"token_type"`
ExpiresAt time.Time `json:"expires_at"`
User UserResponse `json:"user"`
}
+44
View File
@@ -0,0 +1,44 @@
package dto
import (
"regexp"
"strings"
"time"
"unicode/utf8"
"github.com/google/uuid"
)
var usernamePattern = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
type CreateUserRequest struct {
Username string `json:"username"`
DisplayName string `json:"display_name"`
Password string `json:"password"`
}
type UserResponse struct {
ID uuid.UUID `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
CreatedAt time.Time `json:"created_at"`
}
func (r CreateUserRequest) Validate() bool {
if !usernamePattern.MatchString(r.Username) {
return false
}
displayNameLength := utf8.RuneCountInString(r.DisplayName)
if strings.TrimSpace(r.DisplayName) == "" ||
displayNameLength > 100 ||
strings.ContainsRune(r.DisplayName, 0) {
return false
}
if n := utf8.RuneCountInString(r.Password); n < 12 || n > 128 {
return false
}
return true
}