Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add digilocker certificate api #223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SOURCES := $(call rwildcard,java/,*.java)
RELEASE_VERSION = v0.0.13
IMAGES := dockerhub/sunbird-rc-core dockerhub/sunbird-rc-nginx dockerhub/sunbird-rc-context-proxy-service \
dockerhub/sunbird-rc-public-key-service dockerhub/sunbird-rc-keycloak dockerhub/sunbird-rc-certificate-api \
dockerhub/sunbird-rc-certificate-signer dockerhub/sunbird-rc-notification-service dockerhub/sunbird-rc-claim-ms \
dockerhub/sunbird-rc-digilocker-certificate-api dockerhub/sunbird-rc-bulk-issuance
build: java/registry/target/registry.jar
echo ${SOURCES}
rm -rf java/claim/target/*.jar
Expand All @@ -13,15 +17,17 @@ build: java/registry/target/registry.jar
make -C deps/keycloak build
make -C services/public-key-service docker
make -C services/context-proxy-service docker
make -C services/digilocker-certificate-api docker
make -C services/bulk_issuance docker
make -C services/digilocker-certificate-api docker
docker build -t dockerhub/sunbird-rc-nginx .

java/registry/target/registry.jar: $(SOURCES)
echo $(SOURCES)
sh configure-dependencies.sh
cd java && ./mvnw clean install

test:
test: build
@docker-compose down
@rm -rf db-data* || echo "no permission to delete"
# test with ES & standard definition manager
Expand Down Expand Up @@ -69,33 +75,11 @@ clean:
@rm -rf target || true
@rm java/registry/target/registry.jar || true
release: test
docker tag dockerhub/sunbird-rc-core dockerhub/sunbird-rc-core:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-claim-ms dockerhub/sunbird-rc-claim-ms:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-notification-service dockerhub/sunbird-rc-notification-service:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-certificate-signer dockerhub/sunbird-rc-certificate-signer:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-certificate-api dockerhub/sunbird-rc-certificate-api:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-keycloak dockerhub/sunbird-rc-keycloak:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-public-key-service dockerhub/sunbird-rc-public-key-service:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-context-proxy-service dockerhub/sunbird-rc-context-proxy-service:$(RELEASE_VERSION)
docker tag dockerhub/sunbird-rc-nginx dockerhub/sunbird-rc-nginx:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-core:latest
docker push dockerhub/sunbird-rc-core:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-claim-ms:latest
docker push dockerhub/sunbird-rc-claim-ms:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-notification-service:latest
docker push dockerhub/sunbird-rc-notification-service:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-certificate-signer:latest
docker push dockerhub/sunbird-rc-certificate-signer:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-certificate-api:latest
docker push dockerhub/sunbird-rc-certificate-api:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-keycloak:latest
docker push dockerhub/sunbird-rc-keycloak:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-public-key-service:latest
docker push dockerhub/sunbird-rc-public-key-service:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-context-proxy-service:latest
docker push dockerhub/sunbird-rc-context-proxy-service:$(RELEASE_VERSION)
docker push dockerhub/sunbird-rc-nginx:latest
docker push dockerhub/sunbird-rc-nginx:$(RELEASE_VERSION)
for image in $(IMAGES); \
do \
echo $$image; \
docker tag $$image:latest $$image:$(RELEASE_VERSION);\
docker push $$image:latest;\
docker push $$image:$(RELEASE_VERSION);\
done
@cd tools/cli/ && npm publish


14 changes: 13 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,22 @@ services:
image: redis:latest
ports:
- "6379:6379"
digilocker-certificate-api:
image: dockerhub/sunbird-rc-digilocker-certificate-api
volumes:
- ${PWD}/services/digilocker-certificate-api/config/:/go/config/
ports:
- "8087:8087"
environment:
KEYCLOAK_CLIENT_ID: admin-api
KEYCLOAK_CLIENT_SECRET: ${KEYCLOAK_SECRET}
DIGILOCKER_HMAC_AUTHKEY: ${DIGILOCKER_HMAC_AUTHKEY}
DIGILOCKER_AUTH_KEYNAME: x-digilocker-hmac
PORT: 8087
bulk_issuance:
image: dockerhub/sunbird-rc-bulk-issuance
ports:
- "5665:5665"
environment:
REGISTRY_BASE_URL: http://registry:8081/
DATABASE_HOST: db
DATABASE_HOST: db
29 changes: 29 additions & 0 deletions services/digilocker-certificate-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
############################
# STEP 1 build executable binary
############################
FROM golang:alpine AS builder
RUN apk update && apk add --no-cache 'git=~2'
ENV GO111MODULE=on
WORKDIR $GOPATH/src/packages/digilocker-certificate-api/
COPY . .
RUN go get -d -v
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /go/main .

############################
# STEP 2 build a small image
############################
FROM alpine:3

WORKDIR /

# Copy our static executable.
COPY --from=builder /go/main /go/main

ENV PORT 8086
ENV GIN_MODE release
EXPOSE 8086

WORKDIR /go

# Run the Go Gin binary.
ENTRYPOINT ["/go/main"]
6 changes: 6 additions & 0 deletions services/digilocker-certificate-api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
IMAGE:=dockerhub/sunbird-rc-digilocker-certificate-api

docker:
@docker build -t $(IMAGE) .
publish:
@docker push $(IMAGE)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
port: 8086
51 changes: 51 additions & 0 deletions services/digilocker-certificate-api/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package config

import (
"encoding/json"
"fmt"
"io"
"os"

"github.com/jinzhu/configor"
)

var Config = struct {
Keycloak struct {
TokenURL string `env:"KEYCLOAK_TOKEN_URL" default:"http://keycloak:8080/auth/realms/sunbird-rc/protocol/openid-connect/token"`
ClientId string `env:"KEYCLOAK_CLIENT_ID" default:"admin-api"`
ClientSecret string `env:"KEYCLOAK_CLIENT_SECRET" default:"**"`
}
Digilocker struct {
IDPrefix string `env:"DIGILOCKER_DOC_ID_PREFIX" default:"dev.sunbirdrc.vc"`
AuthKeyName string `env:"DIGILOCKER_AUTH_KEYNAME" default:"x-digilocker-hmac"`
AuthHMACKey string `env:"DIGILOCKER_HMAC_AUTHKEY" default:"***"`
}
Registry struct {
URL string `env:"REGISTRY_URL" default:"https://demo-education-registry.xiv.in/registry/"`
}
LogLevel string `env:"LOG_LEVEL" yaml:"log_level" default:"DEBUG"`
Host string `env:"HOST" yaml:"host" default:"0.0.0.0"`
Port string `env:"PORT" yaml:"port" default:"8085"`
MODE string `env:"MODE" yaml:"mode" default:"debug" `
}{}

var SchemaDocTypeMapper map[string]interface{}

func Init() {
err := configor.Load(&Config, "./config/application-default.yml") //"config/application.yml"
if err != nil {
panic("Unable to read configurations")
}
jsonFile, err := os.Open("./config/docType.json")
if err != nil {
fmt.Printf("Error : %v", err)
}
str, err := io.ReadAll(jsonFile)
if err != nil {
fmt.Printf("Error occurred while reading json file : %v", err)
}
if err := json.Unmarshal([]byte(str), &SchemaDocTypeMapper); err != nil {
fmt.Printf("Error Unmarshalling Json file: %v", err)
}
defer jsonFile.Close()
}
13 changes: 13 additions & 0 deletions services/digilocker-certificate-api/config/docType.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"docType": {
"schema": "Schema",
"template": "html",
"searchFilter": {
"filters": {
"osid": {
"eq": "{{.osid}}"
}
}
}
}
}
27 changes: 27 additions & 0 deletions services/digilocker-certificate-api/controllers/digilocker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package controllers

import (
"digilocker-certificate-api/services"
"net/http"

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)

type Digilocker struct {
service services.DigiLockerService
}
func (handler *Digilocker) Init() {
handler.service.Init()
}

func (handler Digilocker) PullURIRequest(c *gin.Context) {
log.Info("PullURIRequest triggered")
response, err := handler.service.ProcessURIRequest(c)
if response == nil {
log.Error("Error while processing URI request", err)
c.JSON(http.StatusInternalServerError, err)
} else {
c.XML(http.StatusOK, response)
}
}
12 changes: 12 additions & 0 deletions services/digilocker-certificate-api/controllers/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package controllers

import "github.com/gin-gonic/gin"

type HealthController struct {
}

func (h HealthController) Status(c *gin.Context) {
c.JSON(200, gin.H{
"status": "UP",
})
}
53 changes: 53 additions & 0 deletions services/digilocker-certificate-api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module digilocker-certificate-api

go 1.20

require (
github.com/gin-gonic/gin v1.9.0
github.com/imroc/req/v3 v3.33.2
github.com/jinzhu/configor v1.2.1
github.com/sirupsen/logrus v1.9.0
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/bytedance/sonic v1.8.7 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo/v2 v2.9.2 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading