Skip to content

Commit

Permalink
[deploy] Fixed additional problems found during deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
atb00ker committed Oct 3, 2021
1 parent 359675c commit be07c82
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 52 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ APP_SETU_AA_ENDPOINT=https://aa-sandbox.setu.co/
APP_RAHASYA_AA_ENDPOINT=https://rahasya.setu.co/
APP_SETU_CLIENT_KEY=00000000-0000-0000-0000-000000000000
APP_SETU_AA_KEY=00000000-0000-0000-0000-000000000000
APP_JWS_AA_PRIVATEKEY_PATH=./private.pem
APP_SETU_JWS_PRIVATEKEY_PATH=./private.pem
# React
REACT_CORS=*
REACT_APP_PORT=3000
Expand All @@ -21,6 +21,7 @@ AUTH0_DOMAIN=XXX
AUTH0_CLIENT_ID=XXX
AUTH0_REDIRECT_URI=http://localhost:8010/
AUTH0_LOGOUT_URI=http://localhost:8010/
AUTH0_JWT_WELKNOWNS_PATH=./jwks.json
# Nginx
NGINX_DOMAIN=localhost
# Developer
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ vendor/
*.pem
*.crt
*.key
jwks.json

# Development
ngrok
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,27 @@ Create a copy of the `.env.example` file and rename it to `.env`.
Now, we can manipulate the following variables to configure the application.
You can find example values in the `.env.example` file itself.

| Key | Description |
| -------------------------- | ------------------------------------------------------------------------ |
| DB_USER | PostgreSQL User |
| DB_PASS | PostgreSQL Password |
| DB_NAME | Database Table Name |
| DB_PORT | Database Port |
| DB_HOST | Database Host/Domain |
| APP_PORT | Port at which our backend will Run |
| APP_CORS | Allowed CORS for backend |
| APP_SETU_AA_ENDPOINT | Setu AA URI |
| APP_SETU_CLIENT_KEY | Setu Client Key |
| APP_SETU_AA_KEY | Setu AA Key |
| APP_JWS_AA_PRIVATEKEY_PATH | Path to the private key used for JWS (Public key shared with Setu) |
| REACT_APP_PORT | Port at which react find server (separate var helpful for reverse proxy) |
| REACT_CORS | CORS allowed from React End |
| AUTH0_DOMAIN | Auth0 Application Domain |
| AUTH0_CLIENT_ID | Auth0 Application Client ID |
| AUTH0_REDIRECT_URI | Auth0 redirect after login (eg. http://localhost:8010/register) |
| AUTH0_LOGOUT_URI | Auth0 redirect after logout (eg. http://localhost:8010) |
| DEBUG | Application Shows detailed logs when set to True |
| Key | Description |
| ---------------------------- | ------------------------------------------------------------------------ |
| DB_USER | PostgreSQL User |
| DB_PASS | PostgreSQL Password |
| DB_NAME | Database Table Name |
| DB_PORT | Database Port |
| DB_HOST | Database Host/Domain |
| APP_PORT | Port at which our backend will Run |
| APP_CORS | Allowed CORS for backend |
| APP_SETU_AA_ENDPOINT | Setu AA URI |
| APP_SETU_CLIENT_KEY | Setu Client Key |
| APP_SETU_AA_KEY | Setu AA Key |
| APP_SETU_JWS_PRIVATEKEY_PATH | Path to the private key used for JWS (Public key shared with Setu) |
| REACT_APP_PORT | Port at which react find server (separate var helpful for reverse proxy) |
| REACT_CORS | CORS allowed from React End |
| AUTH0_DOMAIN | Auth0 Application Domain |
| AUTH0_CLIENT_ID | Auth0 Application Client ID |
| AUTH0_REDIRECT_URI | Auth0 redirect after login (eg. http://localhost:8010/register) |
| AUTH0_LOGOUT_URI | Auth0 redirect after logout (eg. http://localhost:8010) |
| AUTH0_JWT_WELKNOWNS_PATH | Auth0 JWKs file (eg. content of <your-domain>/.well-known/jwks.json) |
| DEBUG | Application Shows detailed logs when set to True |

### Development

Expand Down
6 changes: 3 additions & 3 deletions src/server/controllers/account_aggregator/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func getUserConsentWithSessionId(sessionId string) (userConsent models.UserConse
}

func getPrivatePemFileContent() (x509Key interface{}, err error) {
filePath := os.Getenv("APP_JWS_AA_PRIVATEKEY_PATH")
filePath := os.Getenv("APP_SETU_JWS_PRIVATEKEY_PATH")
content, err := ioutil.ReadFile(filePath)
if err != nil {
log.Println(fmt.Sprintf("Filepath (%s) does not point to a readable file, please check the value of `APP_JWS_AA_PRIVATEKEY_PATH`.", filePath))
log.Println(fmt.Sprintf("Filepath (%s) does not point to a readable file, please check the value of `APP_SETU_JWS_PRIVATEKEY_PATH`.", filePath))
}

block, _ := pem.Decode(content)
Expand Down Expand Up @@ -179,7 +179,7 @@ func deleteUserConsent(userConsent models.UserConsents) {
userConsent.Id).Take(&userScore)

config.Database.Where("pancard = ?", userScore.Pancard).Where(
"is_insuranceng_account <> ?", 1).Delete(&models.UserInsurance{})
"is_insurance_ng_acct <> ?", true).Delete(&models.UserInsurance{})

config.Database.Where("user_id = ?", userConsent.UserId).Delete(&userConsent)
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/controllers/insurance/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type insuranceOffers struct {
YoyDeductionRate float32 `json:"yoy_deduction_rate"`
Clauses pq.StringArray `json:"clauses"`
CurrentClauses pq.StringArray `json:"current_clauses"`
IsInsuranceNgAcct bool `json:"is_insuranceng_account"`
IsInsuranceNgAcct bool `json:"is_insurance_ng_acct"`
IsActive bool `json:"is_active"`
}

Expand Down
32 changes: 17 additions & 15 deletions src/server/middleware/jwt_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"insurance-ng/src/server/config"
"net/http"
"os"

jwtmiddleware "github.com/auth0/go-jwt-middleware"
Expand All @@ -24,6 +23,8 @@ type jwks struct {
Keys []jSONWebKeys `json:"keys"`
}

var auth0Jwks = jwks{}

func JwtMiddleware() *jwtmiddleware.JWTMiddleware {
auth_aud := os.Getenv("AUTH0_CLIENT_ID")
auth_domain := "https://" + os.Getenv("AUTH0_DOMAIN") + "/"
Expand Down Expand Up @@ -58,23 +59,24 @@ func JwtMiddleware() *jwtmiddleware.JWTMiddleware {

func getPemCert(token *jwt.Token, auth_domain string) (string, error) {
cert := ""
resp, err := http.Get(auth_domain + ".well-known/jwks.json")

if err != nil {
return cert, err
}
defer resp.Body.Close()

var jwks = jwks{}
err = json.NewDecoder(resp.Body).Decode(&jwks)
// resp, err := http.Get(auth_domain + ".well-known/jwks.json")
// defer resp.Body.Close()
if auth0Jwks.Keys == nil {
resp, err := os.Open(os.Getenv("AUTH0_JWT_WELKNOWNS_PATH"))
if err != nil {
return cert, err
}
defer resp.Close()

if err != nil {
return cert, err
err = json.NewDecoder(resp).Decode(&auth0Jwks)
if err != nil {
return cert, err
}
}

for k := range jwks.Keys {
if token.Header["kid"] == jwks.Keys[k].Kid {
cert = "-----BEGIN CERTIFICATE-----\n" + jwks.Keys[k].X5c[0] + "\n-----END CERTIFICATE-----"
for k := range auth0Jwks.Keys {
if token.Header["kid"] == auth0Jwks.Keys[k].Kid {
cert = "-----BEGIN CERTIFICATE-----\n" + auth0Jwks.Keys[k].X5c[0] + "\n-----END CERTIFICATE-----"
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/models/insurances.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type UserInsurance struct {
IsActive bool `json:"is_active"`
AccountId string `json:"account_id"`
Clauses pq.StringArray `json:"clauses" gorm:"type:text[]"`
IsInsuranceNgAcct bool `json:"is_insuranceng_account"`
IsInsuranceNgAcct bool `json:"is_insurance_ng_acct"`
gorm.Model
}

Expand Down
10 changes: 5 additions & 5 deletions src/views/components/Dashboard/InsuranceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const InsuranceCard: React.FC<{ fiData: IFIData; insurance: IFIInsurance }> = ({
let recommendedText = recommend,
cardColor = 'danger';

if (insurance.is_insuranceng_account && insurance.account_id != '') {
if (insurance.is_insurance_ng_acct && insurance.account_id != '') {
recommendedText = activePlan;
cardColor = 'success';
} else if (insurance.is_insuranceng_account && insurance.account_id == '') {
} else if (insurance.is_insurance_ng_acct && insurance.account_id == '') {
recommendedText = activationInProgress;
cardColor = 'success';
} else if (insurance.account_id != '') {
Expand Down Expand Up @@ -51,7 +51,7 @@ const InsuranceCard: React.FC<{ fiData: IFIData; insurance: IFIInsurance }> = ({
</Card.Subtitle>
<Card.Text className='roboto-regular' style={{ overflow: 'hidden', height: 120 }}>
{insurance.description} <br />
{insurance.is_insuranceng_account && (
{insurance.is_insurance_ng_acct && (
<>
We are offering you a cover of
<span className={`text-${cardColor}`}>
Expand All @@ -66,7 +66,7 @@ const InsuranceCard: React.FC<{ fiData: IFIData; insurance: IFIInsurance }> = ({
. For initiating claims, please contact your agent or contact help line.
</>
)}
{!insurance.is_insuranceng_account && insurance.account_id != '' && (
{!insurance.is_insurance_ng_acct && insurance.account_id != '' && (
<>
You current have insurance provides a cover of
<span className={`text-${cardColor}`}>
Expand All @@ -88,7 +88,7 @@ const InsuranceCard: React.FC<{ fiData: IFIData; insurance: IFIInsurance }> = ({
.
</>
)}
{!insurance.is_insuranceng_account && insurance.account_id == '' && (
{!insurance.is_insurance_ng_acct && insurance.account_id == '' && (
<>
You are currently not insured, based on your information, we suggest getting a cover of{' '}
<span className={`text-${cardColor}`}>
Expand Down
2 changes: 1 addition & 1 deletion src/views/helpers/svgIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const heartFill = () => {
viewBox='0 0 16 16'
>
<path
fill-rule='evenodd'
fillRule='evenodd'
d='M8 1.314C12.438-3.248 23.534 4.735 8 15-7.534 4.736 3.562-3.248 8 1.314z'
/>
</svg>
Expand Down
2 changes: 1 addition & 1 deletion src/views/interfaces/IFIData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export interface IFIInsurance {
offer_cover: number;
is_active: boolean;
yoy_deduction_rate: number;
is_insuranceng_account: string;
is_insurance_ng_acct: string;
}
8 changes: 4 additions & 4 deletions src/views/pages/InsuranceDetails/InsuranceInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const InsuranceInfo: React.FC = () => {
tableRow.push(
<tr key={index}>
<td>{index + 1}.</td>
{!insuranceInfo.is_insuranceng_account && insuranceInfo.current_clauses?.length && (
{!insuranceInfo.is_insurance_ng_acct && insuranceInfo.current_clauses?.length && (
<td
dangerouslySetInnerHTML={{
__html: insuranceInfo.current_clauses[index]?.replace(
Expand Down Expand Up @@ -159,7 +159,7 @@ const InsuranceInfo: React.FC = () => {
<td>: {insuranceInfo.offer_premium}</td>
<td></td>
</tr>
{!insuranceInfo.is_insuranceng_account && (
{!insuranceInfo.is_insurance_ng_acct && (
<tr>
<td>Purchase</td>
{insuranceInfo.score >= 0.8 && (
Expand Down Expand Up @@ -193,7 +193,7 @@ const InsuranceInfo: React.FC = () => {
)}
</tr>
)}
{insuranceInfo.is_insuranceng_account && (
{insuranceInfo.is_insurance_ng_acct && (
<tr>
<td>Status</td>
{insuranceInfo.is_active && (
Expand Down Expand Up @@ -243,7 +243,7 @@ const InsuranceInfo: React.FC = () => {
<thead>
<tr>
<th className='text-center'>#</th>
{!insuranceInfo.is_insuranceng_account && insuranceInfo.current_clauses?.length && (
{!insuranceInfo.is_insurance_ng_acct && insuranceInfo.current_clauses?.length && (
<th className='text-center'>Current Clauses</th>
)}
<th className='text-center'>Clauses</th>
Expand Down

0 comments on commit be07c82

Please sign in to comment.