Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Adds in Jetpack Scan API with models#304

Merged
emilylaguna merged 36 commits intodevelopfrom
issue/15190-scan-api
Nov 20, 2020
Merged

Adds in Jetpack Scan API with models#304
emilylaguna merged 36 commits intodevelopfrom
issue/15190-scan-api

Conversation

@emilylaguna
Copy link
Copy Markdown
Contributor

Description

🙇‍♀️ I apologize this PR got bigger than I originally intended. The threat models ended up being a lot more complex.

There isn't a related WPiOS PR yet, so the tests being green and a thorough code review will work 👍

This PR introduces the JetpackScanServiceRemote class that contains the method for starting a scan and getting scan information (status, availability, threats, etc). Since the API only uses 1 endpoint for getting scan information (sites/SITE_ID/scan) I've added a few "helper" methods to reduce the amount of information returned by the getScanForSite method:

  • getScanAvailableForSite just returns the isEnabled bool
  • getCurrentScanStatusForSite just returns the current scan status if it exists
  • getThreatsForSite just returns the threats array

Threats

I had originally planned on creating sub threat objects like JetpackThreatCore, JetpackThreatDatabase and only including the relevant properties for that type, but I couldn't get that to work within the decodable structure. Looking for suggestions to make this a bit cleaner.

The JetpackScanThreat object is A LOT to look at so I'll provide any relevant information I can think of:

  • The API does not return the threat type so we have to figure that out ourselves. Luckily wp-calypso already had this logic.

  • The fixable property points to a "Fixer" object that defines how a threat will be fixed if it can be. This information will be used to generate a string later such as "Jetpack will update this plugin to version 1.3.3.7"

    • If a threat can not be fixed this object is nil.
  • JetpackThreatContext:

    • This defines a code preview for file based threats with highlighted sections
    • was created with the intent of using it later to generate an NSAttributedString which is why I opted to use NSRange's
    • The value from the API can be:
      • Not present for non-file threats
      • An empty string context: ""
      • A dictionary
    • The logic for this is kind of messy 😑 looking for suggestions to improve.

Testing Details

🟢 Tests should be good!

  • Please check here if your pull request includes additional test coverage.

@emilylaguna emilylaguna added the enhancement New feature or request label Nov 17, 2020
@emilylaguna emilylaguna self-assigned this Nov 17, 2020
Copy link
Copy Markdown
Contributor

@leandroalonso leandroalonso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilylaguna a few suggestions to reduce boilerplate code. :)

@emilylaguna
Copy link
Copy Markdown
Contributor Author

@leandroalonso Good idea about reducing boilerplate. Can you take another look?

Copy link
Copy Markdown
Contributor

@leandroalonso leandroalonso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilylaguna a few more suggestions to remove some additional lines. :)

@emilylaguna
Copy link
Copy Markdown
Contributor Author

@leandroalonso was able to switch to using the apiDecoder which handles the multiple dates formats. I was then able to remove a lot of boilerplate except for JetpackScanThreat.

I also added the UnknownCaseRepresentable handling

@emilylaguna emilylaguna merged commit 76d38e6 into develop Nov 20, 2020
@emilylaguna emilylaguna deleted the issue/15190-scan-api branch November 20, 2020 18:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants