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

#290 Added optional S3 data store for BS CSV files #301

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ dependencies {
implementation "org.grails.plugins:ala-ws-plugin:$alaSecurityLibsVersion"
implementation "au.org.ala:userdetails-service-client:$alaSecurityLibsVersion"
implementation "org.grails.plugins:ala-admin-plugin:2.3.0"
implementation "au.org.ala.plugins:openapi:1.3.0"
implementation "org.grails.plugins:aws-sdk-s3:2.4.8"

// for ContentType
implementation "org.apache.httpcomponents:httpcore:4.4.16"
Expand All @@ -136,7 +138,7 @@ dependencies {
//Using AWS SES as email provider
implementation 'org.grails.plugins:mail:4.0.0'
implementation 'au.org.ala:ala-mail:1.0.0-SNAPSHOT'
implementation group: 'com.amazonaws', name: 'aws-java-sdk-sts', version: "1.12.759"
implementation 'com.amazonaws:aws-java-sdk-sts:1.12.759'

implementation 'org.grails.plugins:schwartz-monitor:2.0.1.ALA-SNAPSHOT'
implementation 'org.grails.plugins:quartz:2.0.13'
Expand All @@ -162,7 +164,6 @@ dependencies {
runtimeOnly 'xalan:xalan:2.7.3'
implementation 'com.jayway.jsonpath:json-path:2.7.0'
implementation 'com.jayway.jsonpath:json-path-assert:2.7.0'
implementation 'au.org.ala.plugins:openapi:1.3.0'
}
//
//bootRun {
Expand Down
20 changes: 17 additions & 3 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ biosecurity:
link: https://www.ala.org.au/blogs-news/ala-helps-to-stop-pests-in-their-tracks/
csv:
local:
enabled: true
enabled: false # See environments.development section below where set to true
directory: /data/alerts/csv
s3:
enabled: false
bucket: alerts
enabled: true
directory: biosecurity # key prefix
# bucket: alerts # configured via plugin config `grails.plugin.awssdk.s3.bucket`
# read lga from the layer
lga: LGA2023
subscriptionsPerPage: 100
Expand All @@ -203,6 +204,8 @@ biosecurity:
eventDateAge: 150
firstLoadedDateAge: 8



environments:
development:
grails:
Expand All @@ -211,6 +214,15 @@ environments:
host: "localhost"
port: 1025
#username: postie.emailSender
plugin:
awssdk:
region: ap-southeast-2
s3:
# accessKey:
# secretKey:
bucket: ala-alerts-test
profile: comp-ala-developer
region: ap-southeast-2
security:
cas:
appServerName: "http://localhost:8080"
Expand All @@ -220,6 +232,8 @@ environments:
csv:
local:
enabled: true
s3:
enabled: false
userdetails:
web:
url: https://aws-auth-test-2023.test.ala.org.au/userdetails/
Expand Down
3 changes: 2 additions & 1 deletion grails-app/conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<logger name="org.hibernate.orm" level="ERROR" />
<logger name="org.grails.config.NavigableMap" level="ERROR" />
<logger name="org.quartz" level="ERROR" />
<!-- <logger name="au.org.ala" level="DEBUG" />-->
<logger name="au.org.ala.bootstrap3" level="INFO" />

<logger name="au.org.ala" level="DEBUG" />
<logger name="au.org.ala.cas.client" level="WARN">
<appender-ref ref="STDOUT" />
</logger>
Expand Down
52 changes: 24 additions & 28 deletions grails-app/controllers/au/org/ala/alerts/AdminController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -716,16 +716,20 @@ class AdminController {

@AlaSecured(value = ['ROLE_ADMIN', 'ROLE_BIOSECURITY_ADMIN'], anyRole = true, redirectController = 'notification', redirectAction = 'myAlerts', message = "You don't have permission to view that page.")
def listBiosecurityAuditCSV() {
def result = biosecurityCSVService.list()
def result = [:]
try {
result = biosecurityCSVService.list()
} catch (Exception e) {
log.error("Error in listing Biosecurity CSV files: ${e.message}")
result = [status: 1, message: "Error in listing Biosecurity CSV files: ${e.message}"]
}
render(view: 'biosecurityCSV', model: result)
}

@AlaSecured(value = ['ROLE_ADMIN', 'ROLE_BIOSECURITY_ADMIN'], anyRole = true,redirectController = 'notification', redirectAction = 'myAlerts', message = "You don't have permission to view that page.")
def aggregateBiosecurityAuditCSV(String folderName) {
def BASE_DIRECTORY = grailsApplication.config.biosecurity.csv.local.directory
def folder = new File(BASE_DIRECTORY, folderName)
if (!folder.exists() || !folder.isDirectory()) {
render(status: 404, text: "Data not found")
if (!biosecurityCSVService.folderExists(folderName)) {
render(status: 404, text: 'Data not found')
return
}

Expand All @@ -742,17 +746,17 @@ class AdminController {

@AlaSecured(value = ['ROLE_ADMIN', 'ROLE_BIOSECURITY_ADMIN'], anyRole = true,redirectController = 'notification', redirectAction = 'myAlerts', message = "You don't have permission to view that page.")
def downloadBiosecurityAuditCSV(String filename) {
def BASE_DIRECTORY = grailsApplication.config.biosecurity.csv.local.directory
def file = new File(BASE_DIRECTORY, filename)
if (!file.exists() || file.isDirectory()) {
String contents = biosecurityCSVService.getFile(filename)
if (!contents) {
render(status: 404, text: "Data not found")
return
}

def saveToFile = Paths.get(filename).collect { it.toString() }.join("_")
response.contentType = 'application/octet-stream'
response.setHeader('Content-Disposition', "attachment; filename=\"${saveToFile}\"")
response.outputStream << file.bytes
response.contentType = 'text/csv'
response.setHeader("Content-disposition", "attachment; filename=\"${filename.tokenize(File.separator).last()}\"")
response.outputStream.withWriter("UTF-8") { writer ->
writer << contents
}
response.outputStream.flush()
}

/**
Expand Down Expand Up @@ -781,22 +785,14 @@ class AdminController {

@AlaSecured(value = ['ROLE_ADMIN', 'ROLE_BIOSECURITY_ADMIN'], anyRole = true)
def deleteBiosecurityAuditCSV(String filename) {
Map message = [status : 1, message: ""]
def BASE_DIRECTORY = grailsApplication.config.biosecurity.csv.local.directory
def file = new File(BASE_DIRECTORY, filename)
if (!file.exists() || file.isDirectory()) {
message['status'] = 1
message['message'] = "File not found"
} else {
if (file.renameTo(new File(BASE_DIRECTORY, filename +'_deleted'))){
message['status'] = 0
message['message'] = "The file has been temporarily deleted. You can contact the system administrator to recover it."
} else {
message['status'] = 1
message['message'] = "File deletion failed"
}
}
Map message = biosecurityCSVService.deleteFile(filename)
render(status: 200, contentType: 'application/json', text: message as JSON)
}

@AlaSecured(value = ['ROLE_ADMIN', 'ROLE_BIOSECURITY_ADMIN'], anyRole = true)
def moveLocalFilesToS3() {
Boolean dryRun = params.boolean('dryRun', true)
Map message = biosecurityCSVService.moveLocalFilesToS3(dryRun)
render(status: 200, contentType: 'application/json', text: message as JSON)
}
}
Loading