4 Commits
10 changed files with 121 additions and 2 deletions

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
docker-build:
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- export VERSION=`cat .version `
- echo $VERSION
- echo $CI_DOCKER_FILE
- echo $CI_REGISTRY
script:
- set
- mkdir -p migrations
- docker build -f "$CI_DOCKER_FILE" --force-rm --build-arg="version=$VERSION" --build-arg="app_name=$CI_PROJECT_NAME" --pull -t "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION" .
- |
docker tag "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION" "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
docker push "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION"
docker push "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
docker rmi -f "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION"
docker rmi -f "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
- docker logout $CI_REGISTRY
+1 -1
View File
@@ -1 +1 @@
1.3.0
1.4.2
+4
View File
@@ -1,3 +1,7 @@
# v1.4.1
* добавлена обработка ошибки при закрытии клиента `redis`
# v1.4.0
* добавлен метод `daily_limit/get` для проверки возможности отправки запроса пользователем
# v1.3.0
* добавлены методы `/daily_limit/increment` и `/daily_limit/set`
* удалена неиспользуемая структура `domain.GrpcError`
+41
View File
@@ -0,0 +1,41 @@
FROM dockerhub.mos.ru/mosos/arbat:15.5 as builder
RUN zypper --no-gpg-checks update -y && zypper --no-gpg-checks install -y go1.23 git
WORKDIR /build
ARG version
ENV version_env=$version
ARG app_name
ENV app_name_env=$app_name
COPY . .
ENV GOPROXY=https://repo-mirror.mos.ru/repository/go-public
RUN go build -ldflags="-X 'main.version=$version_env'" -o /main .
FROM dockerhub.mos.ru/mosos/arbat:15.5
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
RUN echo "Europe/Moscow" > /etc/timezone
ARG UID=10001
RUN useradd \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
--user-group \
appuser
RUN mkdir -p /app/data
RUN chown appuser:appuser /app/data
VOLUME /app/data
USER appuser
WORKDIR /app
ARG app_name
ENV app_name_env=$app_name
COPY --from=builder main /app/$app_name_env
COPY /conf/config.yml /app/config.yml
COPY /conf/default_remote_config.json* /app/default_remote_config.json
COPY /migrations /app/migrations
ENTRYPOINT /app/$app_name_env
+6 -1
View File
@@ -83,7 +83,12 @@ func (a *Assembly) Closers() []app.Closer {
return nil
}),
app.CloserFunc(func() error {
_ = a.redisCli.Close()
if a.redisCli != nil {
err := a.redisCli.Close()
if err != nil {
return errors.WithMessage(err, "shutdown redis client")
}
}
return nil
}),
}
+10
View File
@@ -10,6 +10,7 @@ import (
type dailyLimiterService interface {
Increment(ctx context.Context, req domain.IncrementRequest) (*domain.IncrementResponse, error)
Set(ctx context.Context, req domain.SetRequest) error
GetLimit(ctx context.Context, req domain.GetRequest) (*domain.GetResponse, error)
}
type DailyLimiter struct {
@@ -33,3 +34,12 @@ func (c DailyLimiter) Set(ctx context.Context, req domain.SetRequest) error {
}
return nil
}
func (c DailyLimiter) Get(ctx context.Context, req domain.GetRequest) (*domain.GetResponse, error) {
resp, err := c.svc.GetLimit(ctx, req)
if err != nil {
return nil, apierrors.NewInternalServiceError(err)
}
return resp, nil
}
+9
View File
@@ -18,3 +18,12 @@ type SetRequest struct {
Value uint64 `validate:"required"`
Today time.Time `validate:"required"`
}
type GetRequest struct {
Key string `validate:"required"`
Today time.Time `validate:"required"`
}
type GetResponse struct {
Value uint64
}
+12
View File
@@ -49,3 +49,15 @@ func (r dailyLimiter) Set(ctx context.Context, key string, dailyLimit uint64) er
}
return nil
}
func (r dailyLimiter) GetLimit(ctx context.Context, key string) (uint64, error) {
val, err := r.redisCli.Get(ctx, makeKey(r.keyPrefix, key)).Uint64()
if errors.Is(err, redis.Nil) {
return 0, nil
}
if err != nil {
return 0, errors.WithMessage(err, "redis cli get daily limit")
}
return val, nil
}
+5
View File
@@ -52,5 +52,10 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
Inner: true,
UserAuthRequired: false,
Handler: c.DailyLimiter.Set,
}, {
Path: "isp-lock-service/daily_limit/get",
Inner: true,
UserAuthRequired: false,
Handler: c.DailyLimiter.Get,
}}
}
+10
View File
@@ -12,6 +12,7 @@ import (
type dailyLimiterRepo interface {
Increment(ctx context.Context, key string) (uint64, error)
Set(ctx context.Context, key string, dailyLimit uint64) error
GetLimit(ctx context.Context, key string) (uint64, error)
}
type dailyLimiter struct {
@@ -36,6 +37,15 @@ func (s dailyLimiter) Set(ctx context.Context, req domain.SetRequest) error {
return nil
}
func (s dailyLimiter) GetLimit(ctx context.Context, req domain.GetRequest) (*domain.GetResponse, error) {
v, err := s.repo.GetLimit(ctx, s.makeKey(req.Key, req.Today))
if err != nil {
return nil, errors.WithMessage(err, "repo get")
}
return &domain.GetResponse{Value: v}, nil
}
func (s dailyLimiter) makeKey(key string, today time.Time) string {
return fmt.Sprintf("%s:%s", key, today.Format(time.DateOnly))
}