Skip to content

Commit 6f99eae

Browse files
committed
minor change
1 parent 6253017 commit 6f99eae

File tree

4 files changed

+87
-113
lines changed

4 files changed

+87
-113
lines changed

Dockerfile

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
FROM golang:latest as build-env
2-
3-
RUN apt-get update -qq
4-
# Install gotesseract system dependecies
5-
RUN apt-get install -y -qq libtesseract-dev libleptonica-dev
6-
ENV TESSDATA_PREFIX=/usr/share/tesseract-ocr/4.00/tessdata/
7-
8-
RUN apt-get install -y -qq \
9-
tesseract-ocr-eng \
10-
tesseract-ocr-deu \
11-
tesseract-ocr-jpn
1+
FROM golang:1.17.2-bullseye as build-env
122

133
# All these steps will be cached
144
RUN mkdir /app-server
@@ -25,20 +15,11 @@ ARG CI_COMMIT_SHA
2515
ARG CI_COMMIT_REF_NAME
2616
# RUN MKDIR -p dist
2717
# Build the binary
28-
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.gitCommit=$CI_COMMIT_SHA -X main.gitRef=$CI_COMMIT_REF_NAME" -a -installsuffix cgo -o ./app ./cmd/server/main.go
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.gitCommit=$CI_COMMIT_SHA -X main.gitRef=$CI_COMMIT_REF_NAME" -a -installsuffix cgo -o ./app ./cmd/server/main.go
2919
RUN ./app -version
3020

3121
# <- Second step to build minimal image
32-
# FROM scratch
33-
FROM debian
34-
35-
RUN apt-get update
36-
RUN apt-get install -y -qq libtesseract-dev libleptonica-dev
37-
ENV TESSDATA_PREFIX=/usr/share/tesseract-ocr/4.00/tessdata/
38-
RUN apt-get install -y -qq \
39-
tesseract-ocr-eng \
40-
tesseract-ocr-deu \
41-
tesseract-ocr-jpn
22+
FROM gcr.io/distroless/static-debian11
4223

4324
WORKDIR /app-server
4425

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module github.com/aaabhilash97/aadhaar_scrapper_apis
22

3+
// +heroku goVersion go1.17.2
34
go 1.17
45

56
require (
@@ -21,7 +22,6 @@ require (
2122
github.com/PuerkitoBio/goquery v1.8.0
2223
github.com/envoyproxy/protoc-gen-validate v0.6.2
2324
github.com/go-redis/redis/v8 v8.11.4
24-
github.com/otiai10/gosseract v2.2.1+incompatible
2525
github.com/otiai10/gosseract/v2 v2.3.1
2626
github.com/patrickmn/go-cache v2.1.0+incompatible
2727
github.com/spf13/viper v1.9.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl
265265
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
266266
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
267267
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
268-
github.com/otiai10/gosseract v2.2.1+incompatible h1:Ry5ltVdpdp4LAa2bMjsSJH34XHVOV7XMi41HtzL8X2I=
269-
github.com/otiai10/gosseract v2.2.1+incompatible/go.mod h1:XrzWItCzCpFRZ35n3YtVTgq5bLAhFIkascoRo8G32QE=
270268
github.com/otiai10/gosseract/v2 v2.3.1 h1:BFy9Rru7dzqEYX7/tJuEvjVPkkJck0f+b5fYzzr6/RM=
271269
github.com/otiai10/gosseract/v2 v2.3.1/go.mod h1:2ZOGgdTIXQzCS5f+N1HkcXRgDX6K3ZoYe3Yvo++cpp4=
272270
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=

pkg/service/v1/aadhaar_apis.go

Lines changed: 83 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ package service
33
import (
44
"context"
55
"encoding/base64"
6-
"errors"
7-
"regexp"
8-
"strings"
96

107
"github.com/aaabhilash97/aadhaar_scrapper_apis/pkg/aadhaarapi"
118
api "github.com/aaabhilash97/aadhaar_scrapper_apis/pkg/api/v1"
12-
"github.com/otiai10/gosseract"
139
"go.uber.org/zap"
1410
)
1511

@@ -225,91 +221,90 @@ func (s AadhaarService) fetchAadhaarResFromCache(
225221
}, nil
226222
}
227223

228-
func (s AadhaarService) AutoVerifyCaptcha(ctx context.Context, req *api.AutoVerifyCaptchaRequest) (res *api.AutoVerifyCaptchaResponse, err error) {
229-
fn := "AutoVerifyCaptcha"
230-
if err = req.Validate(); err != nil {
231-
s.log.Error(fn, zap.Any("req", req), zap.Error(err))
232-
if err, ok := err.(api.AutoVerifyCaptchaRequestValidationError); ok {
233-
if status := validationErrToStaus(ctx, err); status != nil {
234-
return &api.AutoVerifyCaptchaResponse{
235-
Status: status,
236-
}, nil
237-
}
238-
}
239-
return
240-
}
224+
// func (s AadhaarService) AutoVerifyCaptcha(ctx context.Context, req *api.AutoVerifyCaptchaRequest) (res *api.AutoVerifyCaptchaResponse, err error) {
225+
// fn := "AutoVerifyCaptcha"
226+
// if err = req.Validate(); err != nil {
227+
// s.log.Error(fn, zap.Any("req", req), zap.Error(err))
228+
// if err, ok := err.(api.AutoVerifyCaptchaRequestValidationError); ok {
229+
// if status := validationErrToStaus(ctx, err); status != nil {
230+
// return &api.AutoVerifyCaptchaResponse{
231+
// Status: status,
232+
// }, nil
233+
// }
234+
// }
235+
// return
236+
// }
241237

242-
var result aadhaarapi.VerifyCaptchaResult
243-
var sessionCookie string
244-
for i := 0; i <= 3; i++ {
245-
s.log.Info(fn, zap.String("info", "fetching new captcha"))
246-
var captchaImg []byte
247-
captchaImg, sessionCookie, err = aadhaarapi.GetCaptcha()
248-
if err != nil {
249-
if aadhaarapi.IsRetryableError(err) {
250-
s.log.Info(fn, zap.NamedError("retrying_error", err))
251-
continue
252-
}
253-
break
254-
} else {
255-
s.log.Info(fn, zap.String("info", "captcha image fetch success"))
256-
client := gosseract.NewClient()
257-
defer client.Close()
258-
err = client.SetImageFromBytes(captchaImg)
259-
if err != nil {
260-
s.log.Info(fn, zap.NamedError("retrying_error", err))
261-
continue
262-
}
263-
var securityCode string
264-
securityCode, err = client.Text()
265-
if err != nil {
266-
s.log.Info(fn, zap.NamedError("retrying_error", err))
267-
continue
268-
}
269-
// Normalize security code
270-
securityCode = strings.ReplaceAll(securityCode, " ", "")
271-
securityCode = strings.ReplaceAll(securityCode, ",", "I")
272-
if re := regexp.MustCompile(`^[a-zA-Z0-9]+$`); !re.Match([]byte(securityCode)) {
273-
err = errors.New("Invalid captcha detected")
274-
s.log.Info(fn, zap.String("un_processable_security_code", securityCode))
275-
continue
276-
}
238+
// var result aadhaarapi.VerifyCaptchaResult
239+
// var sessionCookie string
240+
// for i := 0; i <= 3; i++ {
241+
// s.log.Info(fn, zap.String("info", "fetching new captcha"))
242+
// var captchaImg []byte
243+
// captchaImg, sessionCookie, err = aadhaarapi.GetCaptcha()
244+
// if err != nil {
245+
// if aadhaarapi.IsRetryableError(err) {
246+
// s.log.Info(fn, zap.NamedError("retrying_error", err))
247+
// continue
248+
// }
249+
// break
250+
// } else {
251+
// s.log.Info(fn, zap.String("info", "captcha image fetch success"))
252+
// client := gosseract.NewClient()
253+
// defer client.Close()
254+
// err = client.SetImageFromBytes(captchaImg)
255+
// if err != nil {
256+
// s.log.Info(fn, zap.NamedError("retrying_error", err))
257+
// continue
258+
// }
259+
// var securityCode string
260+
// securityCode, err = client.Text()
261+
// if err != nil {
262+
// s.log.Info(fn, zap.NamedError("retrying_error", err))
263+
// continue
264+
// }
265+
// // Normalize security code
266+
// securityCode = strings.ReplaceAll(securityCode, " ", "")
267+
// if re := regexp.MustCompile(`^[a-zA-Z0-9]+$`); !re.Match([]byte(securityCode)) {
268+
// err = errors.New("Invalid captcha detected")
269+
// s.log.Info(fn, zap.String("un_processable_security_code", securityCode))
270+
// continue
271+
// }
277272

278-
result, err = aadhaarapi.VerifyCaptcha(aadhaarapi.VerifyCaptchaOpt{
279-
SessionId: sessionCookie,
280-
UidNo: req.UidNo,
281-
SecurityCode: securityCode,
282-
})
283-
if aadhaarapi.IsInvalidCaptcha(err) {
284-
s.log.Info(fn, zap.NamedError("retrying_error", err))
285-
continue
286-
}
287-
s.log.Info(fn, zap.Any("result", result))
288-
break
289-
}
290-
}
273+
// result, err = aadhaarapi.VerifyCaptcha(aadhaarapi.VerifyCaptchaOpt{
274+
// SessionId: sessionCookie,
275+
// UidNo: req.UidNo,
276+
// SecurityCode: securityCode,
277+
// })
278+
// if aadhaarapi.IsInvalidCaptcha(err) {
279+
// s.log.Info(fn, zap.String("securityCode", securityCode), zap.NamedError("retrying_error", err))
280+
// continue
281+
// }
282+
// s.log.Info(fn, zap.Any("result", result))
283+
// break
284+
// }
285+
// }
291286

292-
if err != nil {
293-
s.log.Error(fn, zap.Any("req", req), zap.Error(err))
294-
return &api.AutoVerifyCaptchaResponse{
295-
Status: mapAadhaarErrToStatus(ctx, err),
296-
}, nil
297-
}
298-
hash, err := s.aadhaarCacheStore.SaveSession(sessionCookie)
299-
if err != nil {
300-
s.log.Error(fn, zap.Any("req", req), zap.Error(err))
301-
return &api.AutoVerifyCaptchaResponse{
302-
Status: mapToStatus(ctx, ApiUnknownError, ""),
303-
}, nil
304-
}
287+
// if err != nil {
288+
// s.log.Error(fn, zap.Any("req", req), zap.Error(err))
289+
// return &api.AutoVerifyCaptchaResponse{
290+
// Status: mapAadhaarErrToStatus(ctx, err),
291+
// }, nil
292+
// }
293+
// hash, err := s.aadhaarCacheStore.SaveSession(sessionCookie)
294+
// if err != nil {
295+
// s.log.Error(fn, zap.Any("req", req), zap.Error(err))
296+
// return &api.AutoVerifyCaptchaResponse{
297+
// Status: mapToStatus(ctx, ApiUnknownError, ""),
298+
// }, nil
299+
// }
305300

306-
return &api.AutoVerifyCaptchaResponse{
307-
Status: &api.ResponseStatus{
308-
Code: ApiSuccessCode,
309-
Message: result.Msg,
310-
},
311-
Data: &api.AutoVerifyCaptchaResponse_Data{
312-
SessionId: hash,
313-
},
314-
}, nil
315-
}
301+
// return &api.AutoVerifyCaptchaResponse{
302+
// Status: &api.ResponseStatus{
303+
// Code: ApiSuccessCode,
304+
// Message: result.Msg,
305+
// },
306+
// Data: &api.AutoVerifyCaptchaResponse_Data{
307+
// SessionId: hash,
308+
// },
309+
// }, nil
310+
// }

0 commit comments

Comments
 (0)