A gateway/firewall task to be able to talk someone about the real job
Fibinger Ádám
2021-10-22 fd7692eae00cbb0db3e6b732f68357e3c64a8a8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
 
namespace App\Entity;
 
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\SecretRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
 
/**
 * @ApiResource(
 *     collectionOperations={
 *         "create"={
 *              "path"="secret",
 *              "method"="post",
 *              "input"=App\Dto\CreateSecretDTO::class,
 *     *              "openapi_context": {
 *                    "requestBody": {
 *                           "content": {
 *                                "application/x-www-form-urlencoded": {
 *                                       "schema": {
 *                                             "type": "object",
 *                                             "properties": {
 *                                                 "secret": {
 *                                                     "type": "string",
 *                                                     "example": "https://i.pinimg.com/originals/e2/b8/e3/e2b8e32a0f9660e8fa0a2d68da618f0f.jpg",
 *                                                     "description": "This text will be saved as a secret"
 *                                                      },
 *                                                 "expireAfterViews": {
  *                                                      "type": "integer",
 *                                                      "example": 10,
 *                                                      "description": "The secret won't be available after the given number of views. It must be greater than 0.",
 *                                                      },
 *                                                 "expireAfter": {
 *                                                      "type": "integer",
 *                                                      "example": "100",
 *                                                      "description": "The secret won't be available after the given time. The value is provided in minutes. 0 means never expires"
 *                                                       },
 *                                                },
 *                                        },
 *                                  },
 *                             },
 *                    },
 *                 },
 *          }
 *     },
 *     itemOperations={
 *     "get"=
 *          {
 *              "path"="secret/{hash}",
 *              "controller"=\App\Controller\RetrieveSecretController::class
 *          },
 *     }
 *     )
 * @ORM\Entity(repositoryClass=SecretRepository::class)
 */
class Secret
{
    public function __construct()
    {
        $this->setCreatedAt(new \DateTimeImmutable());
    }
 
    /**
     * @ORM\Id
     * @ORM\Column(type="string", length=255, unique=true)
     * @ApiProperty(attributes={"openapi_context"={"description" = "Unique hash to identify the secrets"}})
     * @Assert\NotNull
     */
    private $hash;
 
    /**
     * @ORM\Column(type="string", length=255)
     * @ApiProperty(attributes={"openapi_context"={"description" = "The secret itself"}})
     * @Assert\NotNull
     * @Assert\Length(
     *     min = 1,
     *     max = 255
     * )
     */
    private $secretText;
 
    /**
     * @ORM\Column(type="datetime_immutable")
     * @ApiProperty(attributes={"openapi_context"={"description" = "The date and time of the creation"}})
     * @Assert\NotNull
     */
    private $createdAt;
 
    /**
     * @ORM\Column(type="datetime_immutable", nullable=true)
     * @ApiProperty(attributes={"openapi_context"={"description" = "The secret cannot be reached after this time"}})
     */
    private $expiresAt;
 
    /**
     * @ORM\Column(type="integer")
     * @ApiProperty(attributes={"openapi_context"={"description" = "How many times the secret can be viewed"}})
     * @Assert\NotNull
     * @Assert\Range(
     *     min = 0
     * )
     */
    private $remainingViews;
 
    public function getHash(): ?string
    {
        return $this->hash;
    }
 
    public function getSecretText(): ?string
    {
        return $this->secretText;
    }
 
    public function setSecretText(string $secretText): self
    {
        $this->secretText = $secretText;
        $this->hash = md5($secretText . uniqid('dont be too salty please', true));
        return $this;
    }
 
    public function getCreatedAt(): ?\DateTimeImmutable
    {
        return $this->createdAt;
    }
 
    public function setCreatedAt(\DateTimeImmutable $createdAt): self
    {
        $this->createdAt = $createdAt;
 
        return $this;
    }
 
    public function getExpiresAt(): ?\DateTimeImmutable
    {
        return $this->expiresAt;
    }
 
    public function setExpiresAt(?\DateTimeImmutable $expiresAt): self
    {
        $this->expiresAt = $expiresAt;
 
        return $this;
    }
 
    public function getRemainingViews(): ?int
    {
        return $this->remainingViews;
    }
 
    public function setRemainingViews(int $remainingViews): self
    {
        $this->remainingViews = $remainingViews;
 
        return $this;
    }
}