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

Adds Commons IO rule to the cloud-readiness/local-storage ruleset #994

Merged
merged 1 commit into from
Jun 21, 2023
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
38 changes: 38 additions & 0 deletions rules/rules-reviewed/cloud-readiness/local-storage.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,43 @@
</iteration>
</perform>
</rule>
<rule id="local-storage-00006">
<when>
<or>
<javaclass references="org.apache.commons.io.input.{*}">
<location>IMPORT</location>
</javaclass>
<javaclass references="org.apache.commons.io.output.{*}">
<location>IMPORT</location>
</javaclass>
</or>
</when>
<perform>
<iteration>
<hint title="Apache Commons I/O" effort="1" category-id="cloud-mandatory">
<message>
An application running inside a container could lose access to a file in local storage.

Recommendations

The following recommendations depend on the function of the file in local storage:

* Logging: Log to standard output and use a centralized log collector to analyze the logs.
* Caching: Use a cache backing service.
* Configuration: Store configuration settings in environment variables so that they can be updated without code changes.
* Data storage: Use a database backing service for relational data or use a persistent data storage system.
* Temporary data storage: Use the file system of a running container as a brief, single-transaction cache.
</message>
<link href="https://12factor.net/logs" title="Twelve-Factor App: Logs"/>
<link href="https://docs.openshift.com/container-platform/4.5/logging/cluster-logging.html" title="OpenShift Container Platform: Understanding cluster logging"/>
<link href="https://12factor.net/backing-services" title="Twelve-Factor App: Backing services"/>
<link href="https://12factor.net/config" title="Twelve-Factor App: Config"/>
<link href="https://docs.openshift.com/container-platform/4.5/builds/creating-build-inputs.html#builds-input-secrets-configmaps_creating-build-inputs" title="OpenShift Container Platform: Input secrets and ConfigMaps"/>
<link href="https://docs.openshift.com/container-platform/4.5/storage/understanding-persistent-storage.html" title="OpenShift Container Platform: Understanding persistent storage"/>
<tag>storage</tag>
</hint>
</iteration>
</perform>
</rule>
</rules>
</ruleset>
17 changes: 17 additions & 0 deletions rules/rules-reviewed/cloud-readiness/tests/data/CommonIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.apache.commons.io.input.TeeInputStream;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.io.output.TeeOutputStream;

public class CommonsIO {

public static void main(String[] args) throws IOException {
String str = "Hello World.";
ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes());
ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();
ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();

FilterOutputStream teeOutputStream
= new TeeOutputStream(outputStream1, outputStream2);
new TeeInputStream(inputStream, teeOutputStream, true).read(new byte[str.length()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<rule id="local-storage-test-00001">
<when>
<not>
<iterable-filter size="48">
<iterable-filter size="51">
<hint-exists message="An application running inside a container could lose access to a file in local storage" />
</iterable-filter>
</not>
Expand Down