├── .github
└── workflows
│ └── codeguru.yml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── aws-codeguru-reviewer.yml
├── images
├── associate.png
├── clone.png
├── compare.png
├── disassociate.png
├── fork.png
├── pending.png
└── thumbs_icons.png
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── shipmentEvents
│ ├── handlers
│ └── EventHandler.java
│ └── util
│ ├── Constants.java
│ └── S3ClientUtil.java
├── resources
├── application.conf
└── setup.yml
├── some-data
└── example.json
├── some-package
└── java
│ └── com
│ └── mainpackage
│ ├── FileSyntaxError.java
│ └── Main.java
└── test
└── resources
├── 8787323232232332--55322798-dd29-4a04-97f4-93e18feed554
├── 8787323232232332--55322798-dd29-4a04-97f4-93e18feed555
├── 8787323232232332--55322798-dd29-4a04-97f4-93e18feed556
└── 8787323232232332--55322798-dd29-4a04-97f4-93e18feed557
/.github/workflows/codeguru.yml:
--------------------------------------------------------------------------------
1 | name: Analyze with CodeGuru Reviewer
2 |
3 | on:
4 | - push
5 | - workflow_dispatch # This allows manual triggering of the action through the GitHub UI.
6 |
7 | permissions:
8 | id-token: write
9 | contents: read
10 | security-events: write
11 |
12 | jobs:
13 | build:
14 | name: Analyze with CodeGuru Reviewer
15 | runs-on: ubuntu-latest
16 | steps:
17 | - name: Configure AWS credentials
18 | id: iam-role
19 | continue-on-error: true
20 | uses: aws-actions/configure-aws-credentials@v1
21 | with:
22 | role-to-assume: arn:aws:iam::048169001733:role/GuruGitHubCICDRole
23 | aws-region: us-west-2
24 |
25 | - uses: actions/checkout@v2
26 | if: steps.iam-role.outcome == 'success'
27 | with:
28 | fetch-depth: 0
29 | - name: Set up JDK 1.8
30 | if: steps.iam-role.outcome == 'success'
31 | uses: actions/setup-java@v1
32 | with:
33 | java-version: 1.8
34 | - name: Build project
35 | if: steps.iam-role.outcome == 'success'
36 | run: mvn compile -DskipTests
37 |
38 | - name: CodeGuru Reviewer
39 | uses: aws-actions/codeguru-reviewer@v1.1
40 | if: steps.iam-role.outcome == 'success'
41 | continue-on-error: false
42 | with:
43 | s3_bucket: codeguru-reviewer-github-profiler-demo-048169001733-uw2
44 | build_path: ./target/classes
45 |
46 | - name: Store SARIF file
47 | if: steps.iam-role.outcome == 'success'
48 | uses: actions/upload-artifact@v2
49 | with:
50 | name: SARIF_recommendations
51 | path: ./codeguru-results.sarif.json
52 |
53 | - name: Upload review result
54 | if: steps.iam-role.outcome == 'success'
55 | uses: github/codeql-action/upload-sarif@v1
56 | with:
57 | sarif_file: codeguru-results.sarif.json
58 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | dependency-reduced-pom.xml
3 |
4 | .idea
5 | *.iml
6 |
7 | .classpath
8 | .project
9 | .settings
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Code of Conduct
2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4 | opensource-codeofconduct@amazon.com with any additional questions or comments.
5 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4 | documentation, we greatly value feedback and contributions from our community.
5 |
6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7 | information to effectively respond to your bug report or contribution.
8 |
9 |
10 | ## Reporting Bugs/Feature Requests
11 |
12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13 |
14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16 |
17 | * A reproducible test case or series of steps
18 | * The version of our code being used
19 | * Any modifications you've made relevant to the bug
20 | * Anything unusual about your environment or deployment
21 |
22 |
23 | ## Contributing via Pull Requests
24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25 |
26 | 1. You are working against the latest source on the *master* branch.
27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29 |
30 | To send us a pull request, please:
31 |
32 | 1. Fork the repository.
33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34 | 3. Ensure local tests pass.
35 | 4. Commit to your fork using clear commit messages.
36 | 5. Send us a pull request, answering any default questions in the pull request interface.
37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38 |
39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41 |
42 |
43 | ## Finding contributions to work on
44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
45 |
46 |
47 | ## Code of Conduct
48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50 | opensource-codeofconduct@amazon.com with any additional questions or comments.
51 |
52 |
53 | ## Security issue notifications
54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
55 |
56 |
57 | ## Licensing
58 |
59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
60 |
61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
62 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 |
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Amazon CodeGuru Reviewer example app
2 |
3 | This application is intended as a test case for Amazon CodeGuru Reviewer, a service that uses program analysis and machine learning to detect potential defects in code. The implementation of this example is intentionally suboptimal to demonstrate the ability of CodeGuru Reviewer to provide recommendations. You should not use this example code in production.
4 |
5 | Note: For testing recommendations from different languages please switch to the relevant branch (Example: python).
6 |
7 | To get started with CodeGuru Reviewer, follow these steps.
8 |
9 | ## Try CodeGuru Reviewer
10 |
11 | ### Step 1: Fork this repo
12 |
13 | Log in to GitHub and choose **Fork** to fork this example app to your GitHub account.
14 |
15 | 
16 |
17 | ### Step 2: Associate the forked repo
18 |
19 | 1. Log in to the [CodeGuru dashboard](https://console.aws.amazon.com/codeguru/home?region=us-east-1).
20 | 1. Choose **Associate repository**.
21 | 1. Make sure **GitHub** is selected, and then choose **Connect to GitHub**.
22 | 1. To allow CodeGuru Reviewer to access your account, choose **Authorize aws-codesuite**. If prompted, confirm your GitHub password.
23 | 1. Select the **amazon-codeguru-reviewer-sample-app** repository, and then choose **Associate**.
24 |
25 | 
26 |
27 | CodeGuru Reviewer is now associated with the repo and listening for pull requests.
28 |
29 | ### Step 3: Push a change to the code
30 |
31 | Clone the forked repo, replacing **USER_ID** in the URL with your actual user ID.
32 |
33 | git clone https://github.com/USER_ID/amazon-codeguru-reviewer-sample-app.git
34 |
35 | You can get the URL by choosing **Clone or download**.
36 |
37 | 
38 |
39 | **Note:** If you access your GitHub repositories using SSH, use the SSH URL instead of the HTTPS URL shown here.
40 |
41 | Check out a new branch.
42 |
43 | cd amazon-codeguru-reviewer-sample-app
44 | git checkout -b dev
45 |
46 | Copy the Java class at **src/main/java/com/shipmentEvents/handlers/EventHandler.java** into **src/main/java/com/shipmentEvents/demo**.
47 |
48 | cp src/main/java/com/shipmentEvents/handlers/EventHandler.java src/main/java/com/shipmentEvents/demo/
49 |
50 | GitHub and CodeGuru Reviewer will treat this as a new file.
51 |
52 | Push your changes.
53 |
54 | git add --all
55 | git commit -m 'new demo file'
56 | git push --set-upstream origin dev
57 |
58 | ### Step 4: Create a pull request
59 |
60 | 1. In your forked GitHub repo, choose **New pull request**.
61 | 1. On the left side of the comparison (**base**), select **USER_ID/amazon-codeguru-reviewer-sample-app**, where `USER_ID` is your GitHub user ID. Leave the branch at **master**.
62 | 1. On the right side of the comparison (**compare**), change the branch to **dev**. The branches should be showing as **Able to merge**. 
63 | 1. Choose **Create pull request** and, again, **Create pull request**.
64 |
65 |
66 |
67 | ### Step 5: Review recommendations
68 |
69 | After a few minutes, CodeGuru Reviewer will issue recommendations on the same GitHub page where the pull request was created. You can check the status of the code review in the **Code reviews** view of the CodeGuru Reviewer console.
70 |
71 | 
72 |
73 | When the code review is complete and the recommendations appear in GitHub, you can provide feedback on the recommendations using the thumbs up or thumbs down icon. Any positive or negative feedback can be used to help improve the performance of CodeGuru Reviewer so that recommendations get better over time.
74 |
75 | 
76 |
77 | ### Step 6: Clean up
78 |
79 | After you're finished with this demo, clean up your resources.
80 |
81 | 1. In your GitHub fork of **amazon-codeguru-reviewer-sample-app**, go to **Settings**, and then choose **Delete this repository**. Follow the instructions to delete the forked repository.
82 | 1. Delete your clone of the forked repository, for example, `rm -rf amazon-codeguru-reviewer-sample-app`.
83 | 1. In the CodeGuru Reviewer console, select the example repository, choose **Actions**, and then choose **Disassociate repository**.
84 |
85 | 
86 |
87 | ## Learn more
88 |
89 | For more information about how to use CodeGuru Reviewer, see the [Amazon CodeGuru Reviewer User Guide](https://docs.aws.amazon.com/codeguru/latest/reviewer-ug/index.html).
90 |
91 | ## License
92 |
93 | This library is licensed under the MIT-0 License. See the LICENSE file.
94 |
95 |
--------------------------------------------------------------------------------
/aws-codeguru-reviewer.yml:
--------------------------------------------------------------------------------
1 | version: 1.0
2 |
3 | # Sample YAML file
4 | # This configuration file is an optional file for Amazon CodeGuru Reviewer.
5 | # You must name your file aws-codeguru-reviewer.yml for CodeGuru Reviewer to recognize it.
6 | # Add the file to the root directory of your repository.
7 | # For more information, see the Amazon CodeGuru Reviewer User Guide:
8 | # https://docs.aws.amazon.com/codeguru/latest/reviewer-ug/welcome.html.
9 |
10 | # Exclude files and directories
11 | # Use glob pattern syntax to specify the files and directories that you want to exclude
12 | # from analysis under excludeFiles. For more information, see glob (programming):
13 | # https://en.wikipedia.org/wiki/Glob_(programming).
14 | # The following example excludes from analysis all content in the some-package directory, all content
15 | # in the tst directory, and all JSON files in a sub-directory under a directory prefixed with some-.
16 | # Replace with your own list of files and directories that you want CodeGuru Reviewer to exclude.
17 | # We recommend that you use a schema validator to confirm that the YAML syntax is valid.
18 |
19 | excludeFiles:
20 | - 'src/some-package/**'
21 | - 'src/some-*/*.json'
22 |
--------------------------------------------------------------------------------
/images/associate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/amazon-codeguru-reviewer-sample-app/630140e2e38c5593025d07e1e4ce03a407859af5/images/associate.png
--------------------------------------------------------------------------------
/images/clone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/amazon-codeguru-reviewer-sample-app/630140e2e38c5593025d07e1e4ce03a407859af5/images/clone.png
--------------------------------------------------------------------------------
/images/compare.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/amazon-codeguru-reviewer-sample-app/630140e2e38c5593025d07e1e4ce03a407859af5/images/compare.png
--------------------------------------------------------------------------------
/images/disassociate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/amazon-codeguru-reviewer-sample-app/630140e2e38c5593025d07e1e4ce03a407859af5/images/disassociate.png
--------------------------------------------------------------------------------
/images/fork.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/amazon-codeguru-reviewer-sample-app/630140e2e38c5593025d07e1e4ce03a407859af5/images/fork.png
--------------------------------------------------------------------------------
/images/pending.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/amazon-codeguru-reviewer-sample-app/630140e2e38c5593025d07e1e4ce03a407859af5/images/pending.png
--------------------------------------------------------------------------------
/images/thumbs_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-samples/amazon-codeguru-reviewer-sample-app/630140e2e38c5593025d07e1e4ce03a407859af5/images/thumbs_icons.png
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | sample-applications
4 | Guru-Sample-application
5 | 0.0.1-SNAPSHOT
6 | Guru-Sample-application
7 |
8 | 1.8
9 | 1.8
10 |
11 |
12 |
13 | com.amazonaws
14 | aws-lambda-java-core
15 | 1.2.0
16 |
17 |
18 | com.amazonaws
19 | aws-lambda-java-events
20 | 2.2.6
21 |
22 |
23 | com.amazonaws
24 | aws-java-sdk-s3
25 | 1.12.261
26 |
27 |
28 | org.apache.commons
29 | commons-lang3
30 | 3.8
31 |
32 |
33 | com.channelape
34 | shopify-sdk
35 | 2.3.0
36 |
37 |
38 |
39 | com.channelape
40 | shopify-sdk
41 | 1.4.0
42 |
43 |
44 |
45 |
46 |
47 | org.apache.maven.plugins
48 | maven-shade-plugin
49 | 3.2.1
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/src/main/java/com/shipmentEvents/handlers/EventHandler.java:
--------------------------------------------------------------------------------
1 | package com.shipmentEvents.handlers;
2 |
3 | import java.nio.charset.StandardCharsets;
4 | import java.time.Duration;
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 | import java.util.Iterator;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Map.Entry;
11 |
12 | import javax.crypto.Cipher;
13 | import javax.crypto.SecretKey;
14 | import javax.crypto.spec.SecretKeySpec;
15 |
16 | import com.amazonaws.regions.Regions;
17 | import com.amazonaws.services.lambda.runtime.Context;
18 | import com.amazonaws.services.lambda.runtime.RequestHandler;
19 | import com.amazonaws.services.lambda.runtime.LambdaLogger;
20 | import com.amazonaws.services.lambda.runtime.events.ScheduledEvent;
21 | import com.amazonaws.services.s3.AmazonS3;
22 | import com.amazonaws.services.s3.AmazonS3ClientBuilder;
23 | import com.amazonaws.services.s3.model.DeleteObjectsRequest;
24 | import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion;
25 | import com.amazonaws.services.s3.model.ObjectListing;
26 | import com.amazonaws.services.s3.model.S3ObjectSummary;
27 | import com.shipmentEvents.util.Constants;
28 | import com.shopify.ShopifySdk;
29 | import com.shopify.model.ShopifyShop;
30 |
31 | import org.apache.commons.lang3.tuple.MutablePair;
32 | import org.apache.commons.lang3.tuple.Pair;
33 |
34 |
35 | public class EventHandler implements RequestHandler {
36 |
37 | /**
38 | * Shipment events for a carrier are uploaded to separate S3 buckets based on the source of events. E.g., events originating from
39 | * the hand-held scanner are stored in a separate bucket than the ones from mobile App. The Lambda processes events from multiple
40 | * sources and updates the latest status of the package in a summary S3 bucket every 15 minutes.
41 | *
42 | * The events are stored in following format:
43 | * - Each status update is a file, where the name of the file is tracking number + random id.
44 | * - Each file has status and time-stamp as the first 2 lines respectively.
45 | * - The time at which the file is stored in S3 is not an indication of the time-stamp of the event.
46 | * - Once the status is marked as DELIVERED, we can stop tracking the package.
47 | *
48 | * A Sample files looks as below:
49 | * FILE-NAME-> '8787323232232332--55322798-dd29-4a04-97f4-93e18feed554'
50 | * >status:IN TRANSIT
51 | * >timestamp: 1573410202
52 | * >Other fields like...tracking history and address
53 | */
54 | public String handleRequest(ScheduledEvent scheduledEvent, Context context) {
55 |
56 | final LambdaLogger logger = context.getLogger();
57 | try {
58 | processShipmentUpdates(logger);
59 | return "SUCCESS";
60 | } catch (final Exception ex) {
61 | logger.log(String.format("Failed to process shipment Updates in %s due to %s", scheduledEvent.getAccount(), ex.getMessage()));
62 | throw new RuntimeException("Hiding the exception");
63 | }
64 | }
65 |
66 | public String weakMessageEncryption(String message, String key) throws Exception {
67 | Cipher cipher = Cipher.getInstance("RSA");
68 | SecretKey secretKey = new SecretKeySpec(key.getBytes(), "AES");
69 | cipher.init(Cipher.ENCRYPT_MODE, secretKey);
70 | return new String(cipher.doFinal(message.getBytes()), StandardCharsets.UTF_8);
71 | }
72 |
73 | public ShopifyShop connectToShopify(String subdomain) {
74 | final String token = "shpss_sdkfhkjh134134141341344133412312345678";
75 | final ShopifySdk shopifySdk = ShopifySdk.newBuilder()
76 | .withSubdomain(subdomain)
77 | .withAccessToken(token).build();
78 | return shopifySdk.getShop();
79 | }
80 |
81 | private void processShipmentUpdates(final LambdaLogger logger) throws InterruptedException {
82 |
83 | final List bucketsToProcess = Constants.BUCKETS_TO_PROCESS;
84 | final Map> latestStatusForTrackingNumber = new HashMap>();
85 | final Map> filesToDelete = new HashMap>();
86 | for (final String bucketName : bucketsToProcess) {
87 | final List filesProcessed = processEventsInBucket(bucketName, logger, latestStatusForTrackingNumber);
88 | filesToDelete.put(bucketName, filesProcessed);
89 | }
90 | final AmazonS3 s3Client = EventHandler.getS3Client();
91 |
92 | //Create a new file in the Constants.SUMMARY_BUCKET
93 | logger.log("Map of statuses -> " + latestStatusForTrackingNumber);
94 | String summaryUpdateName = Long.toString(System.currentTimeMillis());
95 |
96 | EventHandler.getS3Client().putObject(Constants.SUMMARY_BUCKET, summaryUpdateName, latestStatusForTrackingNumber.toString());
97 |
98 | long expirationTime = System.currentTimeMillis() + Duration.ofMinutes(1).toMillis();
99 | while(System.currentTimeMillis() < expirationTime) {
100 | if (s3Client.doesObjectExist(Constants.SUMMARY_BUCKET, summaryUpdateName)) {
101 | break;
102 | }
103 | logger.log("waiting for file to be created " + summaryUpdateName);
104 | Thread.sleep(1000);
105 | }
106 |
107 | // Before we delete the shipment updates make sure the summary update file exists
108 | if (EventHandler.getS3Client().doesObjectExist(Constants.SUMMARY_BUCKET, summaryUpdateName)) {
109 | deleteProcessedFiles(filesToDelete);
110 | logger.log("All updates successfully processed");
111 | } else {
112 | throw new RuntimeException("Failed to write summary status, will be retried in 15 minutes");
113 | }
114 |
115 | }
116 |
117 | private List processEventsInBucket(String bucketName, LambdaLogger logger, Map> latestStatusForTrackingNumber) {
118 | final AmazonS3 s3Client = EventHandler.getS3Client();
119 | logger.log("Processing Bucket: " + bucketName);
120 |
121 | ObjectListing files = s3Client.listObjects(bucketName);
122 | List filesProcessed = new ArrayList();
123 |
124 | for (Iterator> iterator = files.getObjectSummaries().iterator(); iterator.hasNext(); ) {
125 | S3ObjectSummary summary = (S3ObjectSummary) iterator.next();
126 | logger.log("Reading Object: " + summary.getKey());
127 |
128 | String trackingNumber = summary.getKey().split("--")[0];
129 | Pair lastKnownStatus = latestStatusForTrackingNumber.get(trackingNumber);
130 |
131 | // Check if this shipment has already been delivered, skip this file
132 | if (lastKnownStatus != null && "DELIVERED".equals(lastKnownStatus.getRight())) {
133 | continue;
134 | }
135 |
136 | String fileContents = s3Client.getObjectAsString(bucketName, summary.getKey());
137 |
138 | if (!isValidFile(fileContents)) {
139 | logger.log(String.format("Skipping invalid file %s", summary.getKey()));
140 | continue;
141 | }
142 |
143 | if (!fileContents.contains("\n")) {
144 |
145 | }
146 | String[] lines = fileContents.split("\n");
147 | String line1 = lines[0];
148 | String line2 = lines[1];
149 |
150 | String status = line1.split(":")[1];
151 | Long timeStamp = Long.parseLong(line2.split(":")[1]);
152 |
153 |
154 | if (null == lastKnownStatus || lastKnownStatus.getLeft() < timeStamp) {
155 | lastKnownStatus = new MutablePair(timeStamp, status);
156 | latestStatusForTrackingNumber.put(trackingNumber, lastKnownStatus);
157 | }
158 |
159 | //Add to list of processed files
160 | filesProcessed.add(new KeyVersion(summary.getKey()));
161 | logger.log("logging Contents of the file" + fileContents);
162 | }
163 | return filesProcessed;
164 | }
165 |
166 |
167 | private void deleteProcessedFiles(Map> filesToDelete) {
168 | final AmazonS3 s3Client = EventHandler.getS3Client();
169 | for (Entry> entry : filesToDelete.entrySet()) {
170 | final DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(entry.getKey()).withKeys(entry.getValue()).withQuiet(false);
171 | s3Client.deleteObjects(deleteRequest);
172 | }
173 | }
174 |
175 | private boolean isValidFile(String fileContents) {
176 | if (!fileContents.contains("\n")) {
177 | return false;
178 | }
179 | String[] lines = fileContents.split("\n");
180 | for (String l: lines) {
181 | if (!l.contains(":")) {
182 | return false;
183 | }
184 | }
185 | return true;
186 | }
187 |
188 | public static AmazonS3 getS3Client() {
189 | return AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
190 | }
191 |
192 |
193 | }
194 |
195 |
196 |
--------------------------------------------------------------------------------
/src/main/java/com/shipmentEvents/util/Constants.java:
--------------------------------------------------------------------------------
1 | package com.shipmentEvents.util;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public final class Constants {
7 |
8 | public static final List BUCKETS_TO_PROCESS = Arrays.asList("shipment-events-from-scanner", "shipment-events-from-mobile-app");
9 | public static final String SUMMARY_BUCKET = "shipment-events-summary";
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/shipmentEvents/util/S3ClientUtil.java:
--------------------------------------------------------------------------------
1 | package com.shipmentEvents.util;
2 |
3 | import com.amazonaws.regions.Regions;
4 | import com.amazonaws.services.s3.AmazonS3;
5 | import com.amazonaws.services.s3.AmazonS3ClientBuilder;
6 |
7 | public class S3ClientUtil {
8 |
9 | public static AmazonS3 getS3Client() {
10 | return AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/resources/application.conf:
--------------------------------------------------------------------------------
1 | db.default.url="postgres://ojxarsxivjuyjc:ubKveYbvNjQ5a0CU8vK4YoVIhl@ec2-54-225-223-40.compute-1.amazonaws.com:5432/dcectn1pto16vi?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"
2 | db.default.url=${?DATABASE_URL}
3 | db.default.port="3000"
4 | db.default.datasource.username="root"
5 | db.default.datasource.password="sk_live_454kjkj4545FD3434Srere7878"
6 | db.default.jpa.generate-ddl="true"
7 | db.default.jpa.hibernate.ddl-auto="create"
8 |
--------------------------------------------------------------------------------
/src/resources/setup.yml:
--------------------------------------------------------------------------------
1 | - os: linux
2 | dist: bionic
3 | name: Solaris VM
4 | if: (branch !~ ^r/.*$ AND head_branch !~ ^r/.*$) AND ((type = push AND branch = master) OR type = pull_request OR tag =~ /^v\d+\.\d+\.\d+$/)
5 | sudo: true
6 | install:
7 | - wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
8 | - echo -e "\ndeb [arch=amd64] https://download.virtualbox.org/virtualbox/debian bionic contrib\n" | sudo tee -a /etc/apt/sources.list
9 | - sudo apt-get update > /dev/null
10 | - sudo apt-get install -y linux-headers-$(uname -r) virtualbox-5.2 rsync
11 | - wget -q "https://homepages.cwi.nl/~hannes/86Cv27lf5353lJR/Solaris10_1-13-2.ova"
12 | - VBoxManage import Solaris10_1-13-2.ova
13 | - rm Solaris10_1-13-2.ova
14 | - VBoxManage modifyvm "Solaris10_1-13" --usb off --usbehci off --usbxhci off --cpus 2 --hwvirtex on --memory 6114
15 | - VBoxManage startvm "Solaris10_1-13" --type headless
16 | - echo -e "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn\nNhAAAAAwEAAQAAAQEArPN99L/D9jXUwtFjoAzhnzA5a7t/YJiSrcTm+hKSxPp/nklfu1Km\ntDbMBOrXsAqLRcMz5JZoF8G1jebXOO3u2LRB+INFsxqDV76TZjUC1y4SAX17h5UvstT3sn\naPPt+TzwX3PmF8ooN+L8hDIZpvty6m+7b09QRFx4l7+j30MgO+kjwNHUyocn7qokoyH2p4\nfzvtoWePNyL191O9GNg6LmjneG25nN/NBoFYc/Zu+XfDY3gMECNurGHVV3W4ZNpoqjpZWU\nFx4eG0tShBZ+pvuFPy669+H8b5laNEjPGYclInW8unW6T9nuaoQjc/metBwaODgkOsAR0u\nddRxR8nIUwAAA9C2NMXdtjTF3QAAAAdzc2gtcnNhAAABAQCs8330v8P2NdTC0WOgDOGfMD\nlru39gmJKtxOb6EpLE+n+eSV+7Uqa0NswE6tewCotFwzPklmgXwbWN5tc47e7YtEH4g0Wz\nGoNXvpNmNQLXLhIBfXuHlS+y1Peydo8+35PPBfc+YXyig34vyEMhmm+3Lqb7tvT1BEXHiX\nv6PfQyA76SPA0dTKhyfuqiSjIfanh/O+2hZ483IvX3U70Y2DouaOd4bbmc380GgVhz9m75\nd8NjeAwQI26sYdVXdbhk2miqOllZQXHh4bS1KEFn6m+4U/Lrr34fxvmVo0SM8ZhyUidby6\ndbpP2e5qhCNz+Z60HBo4OCQ6wBHS511HFHychTAAAAAwEAAQAAAQEAl3IwnZ0+z96bjG0m\nvAQLngXwgjIRfFieOKPvTpPtCagBEG5X8gSSDcTeKoAqlvDkvBYO3uAGDqeFf9jgJe3T9N\ncD3cW1xvw0fyVWlW1eK2cgRUXIYhV1SzfKHvBKx1eoauRieLGNHhHe8aB/iHFf2hx0BH9V\nSSiQogX2Fk8iAphr9qLuR+M0eMtsZmq9nNpk0iXiohw7b3xNb1QrewoeiXiSI4xANdbkmx\n7R2Jnm132toa+ofPZWbpRptYyzv5TWRhEob4GQSknEvS7NEep3cxnv71d1wQvCfhkMKLXH\nKrIck4X46fLa+65OV8Bq37x91kRagOl4VFBZBT61Y9+DoQAAAIEAltUA8Zx5ETlUOXdGCQ\n+ftbCLZlmlPGGabFdg/EKM+M96Q3sj7L2lIP0Htt5w/HmM3Hz9uLk/d/m20zPq8xkltwCo\nF4R80K5HA38Q26fPRpJzDhch+k7AYuQwjziPSH1uzP3BdQo74KVuyvaTk+9VoeeFslF13P\njflhvUmCyquNkAAACBANtkmGdXwaMHrFKAibQreQuQD9CBRFRDRYNWOP4nPOp7YyCY4xbf\n02kHfFUmf7UqvY36v+jTC4RJ1mJH9KVlqJOB/JLhb6Wrv3xuddcxbwaMwb6dGgsZM+iB7G\nqBlcHlrxnWi6bXXK9WpQWaLNYdE4MKgRvKTSq20glezRWDijznAAAAgQDJzyCedgs5ibpb\nhvtNy5TGXPyX2lI9qoMDV2LSJZhp5TPL/mZqITUrehs0siM9IQ4DqhL4DgKBkYOLI/W6mW\nCXkQVFkGGLovzFUMM/wpK1Ua20k+0XakblI11yK3fjd0XJ0K5FyQ1YzG9XXZ8EuZo/2p2A\n8Y/K54JYuMflOJVftQAAABZoYW5uZXNAZGFrYXIuZGEuY3dpLm5sAQID\n-----END OPENSSH PRIVATE KEY-----\n" > id_rsa_solaris
17 | - chmod 400 id_rsa_solaris
18 | - export SSHFLAGS="-o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i id_rsa_solaris"
19 | - export SCMD="ssh $SSHFLAGS -p 8989 root@localhost"
20 | - sleep 60
21 | - while ! $SCMD ls ; do sleep 30 ; done
22 | - $SCMD 'bash -c "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"'
23 | script:
24 | - python scripts/amalgamation.py > /dev/null
25 | - rsync -a -e "ssh $SSHFLAGS -p 8989" --exclude=.git --exclude=build --exclude=third_party/sqllogictest --exclude=third_party/imdb . root@localhost:/sampledb
26 | - travis_wait 50 $SCMD 'rm -rf /sampledb/build && mkdir -p /sampledb/build && cd /sampledb/build && export PATH=/opt/csw/bin/:$PATH CXX=g++ CC=gcc && cmake -DCMAKE_AR=/opt/csw/bin/gar -DCMAKE_BUILD_TYPE=Debug -DAMALGAMATION_BUILD=1 .. && gmake -j2'
27 | - $SCMD /sampledb/build/test/unittest "~[copy]~[file_system]~[.]"
28 |
--------------------------------------------------------------------------------
/src/some-data/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "secret_in_suppressed_file": "sk_test_kovrMB0mupFJXfNZWx6Etg5y","company.tap.goSellSDKExample"
3 | }
4 |
--------------------------------------------------------------------------------
/src/some-package/java/com/mainpackage/FileSyntaxError.java:
--------------------------------------------------------------------------------
1 | package com.mainpackage;
2 |
3 | import com.amazonaws.services.s3.AmazonS3;
4 | import com.amazonaws.services.s3.model.S3Object;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import com.amazonaws.util.IOUtils;
8 |
9 | /**
10 | * Even though this file contains file syntax issues, CodeGuru Reviewer will not
11 | * report any issues in it, because it has been excluded in aws-codeguru-reviewer.yml.
12 | *
13 | * For more information, see the Amazon CodeGuru Reviewer User Guide:
14 | * https://docs.aws.amazon.com/codeguru/latest/reviewer-ug/welcome.html.
15 | */
16 | public class FileSyntaxError {
17 |
18 | public void getObjectContentNoncompliant(AmazonS3 amazonS3Client, String bucketName, String key) throws IOException {
19 | final S3Object s3object = amazonS3Client.getObject(bucketName, key);
20 | // Noncompliant: the statement is incomplete and is missing ";" at the end.
21 | System.out.println(s3object.getObjectMetadata())
22 | InputStream reportStream = s3object.getObjectContent();
23 | IOUtils.toString(reportStream);
24 | }
25 |
26 | public void getObjectContentCompliant(AmazonS3 amazonS3Client, String bucketName, String key) throws IOException {
27 | final S3Object s3object = amazonS3Client.getObject(bucketName, key);
28 | System.out.println(s3object.getObjectMetadata());
29 | InputStream reportStream = s3object.getObjectContent();
30 | IOUtils.toString(reportStream);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/some-package/java/com/mainpackage/Main.java:
--------------------------------------------------------------------------------
1 | package com.mainpackage;
2 |
3 | import javax.crypto.Cipher;
4 | import javax.crypto.SecretKey;
5 | import javax.crypto.spec.SecretKeySpec;
6 |
7 | /**
8 | * Even though this file contains weak crypto issues, CodeGuru Reviewer will not
9 | * report any issues in it, because it has been excluded in aws-codeguru-reviewer.yml.
10 | *
11 | * For more information, see the Amazon CodeGuru Reviewer User Guide:
12 | * https://docs.aws.amazon.com/codeguru/latest/reviewer-ug/welcome.html.
13 | */
14 | public class Main {
15 |
16 | public static void main(String[] argv) {
17 | String message = argv[0];
18 | String key = argv[1];
19 | Cipher cipher = Cipher.getInstance("RSA");
20 | SecretKey secretKey = new SecretKeySpec(key.getBytes(), "AES");
21 | cipher.init(Cipher.ENCRYPT_MODE, secretKey);
22 | System.out.println(String(cipher.doFinal(message.getBytes()), StandardCharsets.UTF_8));
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/resources/8787323232232332--55322798-dd29-4a04-97f4-93e18feed554:
--------------------------------------------------------------------------------
1 | status:IN_TRANSIT
2 | timestamp:1573410202
3 | tackingHistory: testinggg
4 |
--------------------------------------------------------------------------------
/src/test/resources/8787323232232332--55322798-dd29-4a04-97f4-93e18feed555:
--------------------------------------------------------------------------------
1 | status:IN_TRANSIT
2 | timestamp:1573410203
3 | tackingHistory: testinggg
4 |
--------------------------------------------------------------------------------
/src/test/resources/8787323232232332--55322798-dd29-4a04-97f4-93e18feed556:
--------------------------------------------------------------------------------
1 | status:DELIVERED
2 | timestamp:1573410206
3 | tackingHistory: testinggg
4 |
--------------------------------------------------------------------------------
/src/test/resources/8787323232232332--55322798-dd29-4a04-97f4-93e18feed557:
--------------------------------------------------------------------------------
1 | status:IN_TRANSIT
2 | timestamp:1573410209
3 | tackingHistory: testinggg
4 |
--------------------------------------------------------------------------------