italia / verificac19-sdk

✅ Official VerificaC19 Node.js SDK
MIT License
49 stars 17 forks source link

MongoDB Cache Manager #40

Open anversoft opened 2 years ago

anversoft commented 2 years ago

I moved everything about the cache to the Mongo database so that any validation servers can be synchronized on a single database, the only substantial difference is that now the Service.updateAll(crl?: CRL, cache?: Cache) and Service.setUp(crl?: CRL, cache?: Cache) entries accept a custom Cache object as an optional second argument.

export interface Cache {
    /**
    * Setup your Cache here (database/file init)
    */
    setUp(): Promise<void>;

    /**
    * Check if the Cache Manager is set up
    */
    checkCacheManagerSetUp(): Promise<void>;

    /**
    * Check if the CRL Manager is set up
    */
    checkCrlManagerSetUp(): Promise<void>;

    /**
    * Check if the Cache Manager is ready
    */
    isReady(): Promise<boolean>;

    /**
    * Store the CRL status
    */
    storeCRLStatus(chunk: Number, totalChunk: Number, version: Number, targetVersion: Number): Promise<void>;

    /**
    * Store the Rules
    */
    storeRules(data: String): Promise<void>;

    /**
    * Store the Signatures List
    */
    storeSignaturesList(data: String): Promise<void>;

    /**
    * Store the Signatures
    */
    storeSignatures(data: String): Promise<void>;

    /**
    * Store the downlaoded UVCI
    */
    storeCRLRevokedUVCI(revokedUvci: Array<String>, deletedRevokedUvci: Array<String>): Promise<void>

    /**
    * Get the CRL Status
    */
    getCRLStatus(): Promise<CRLStatus>;

    /**
    * Get the rules
    */
    getRules(): Promise<Array<Rule>>;

    /**
    * Get the signature list
    */
    getSignatureList(): Promise<Array<Signatures>>;

    /**
    * Get the signatures
    */
    getSignatures(): Promise<SignaturesList>;

    /**
    * Check if the CRL needs to be updated
    */
    needCRLUpdate(): Promise<boolean>;

    /**
    * Check if the Rules needs to be updated
    */
    needRulesUpdate(): Promise<boolean>;

    /**
    * Check if the Signatures needs to be updated
    */
    needSignaturesUpdate(): Promise<boolean>;

    /**
    * Check if the Signature list needs to be updated
    */
    needSignaturesListUpdate(): Promise<boolean>;

    /**
    * Check if the UVCI is revoked
    */
    isUVCIRevoked(uvci: String): Promise<boolean>;

    /**
    * Close all connections
    */
    tearDown(): Promise<void>;

    /**
    * Clean the CRL
    */
    cleanCRL(): Promise<void>;

}
anversoft commented 2 years ago

To reuse the old caching method just create a new file and copy the contents of ./src/cache.js and create a new class while calling the methods listed above

codecov[bot] commented 2 years ago

Codecov Report

Merging #40 (3469ed5) into master (6326798) will decrease coverage by 1.17%. The diff coverage is 95.42%.

@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
- Coverage   98.44%   97.26%   -1.18%     
==========================================
  Files           8        9       +1     
  Lines         513      659     +146     
==========================================
+ Hits          505      641     +136     
- Misses          8       18      +10     
Impacted Files Coverage Δ
src/cache.js 93.75% <78.57%> (-6.25%) :arrow_down:
src/service.js 93.54% <91.17%> (-2.40%) :arrow_down:
src/mongocache.js 98.14% <98.14%> (ø)
src/index.js 100.00% <100.00%> (ø)
src/validator.js 98.30% <100.00%> (+0.03%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6326798...3469ed5. Read the comment docs.

anversoft commented 2 years ago

Edit, to reuse the old method just use Service.updateAll(null, new FileCache()) everytime

astagi commented 2 years ago

Really cool feature @anversoft I need to review it deeply. I suppose this feature resolves https://github.com/italia/verificac19-sdk/issues/23, does it? cc @albertorizzi