Apereo CAS HTML template does not seem to load - templates

So I initialized CAS using cas-initializr with the following command inside the cas folder:
curl https://casinit.herokuapp.com/starter.tgz -d "dependencies=core,bootadmin,metrics,gitsvc,jsonsvc,redis,support-themes-core" | tar -xzvf -
My theme name is example. Here is the file structure of cas/src/main/resources/templates:
templates
├── META-INF
│   └── spring.factories
├── application.yml
├── example.properties
├── static
│   └── themes
│   └── example
│   ├── css
│   │   └── cas.css
│   ├── images
│   │   ├── favicon.ico
│   │   └── logo.png
│   └── js
│   └── cas.js
└── templates
└── example
└── casLoginView.html
The content of casLoginView.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
The content of example.properties:
cas.theme.name=Example Theme
cas.theme.description=Example - Central Authentication Service
cas.standard.css.file=/themes/example/css/cas.css
cas.standard.js.file=/themes/example/js/cas.js
cas.logo.file=/themes/example/images/logo.png
cas.favicon.file=/themes/example/images/favicon.ico
cas.drawer-menu.enabled=false
cas.notifications-menu.enabled=false
cas.login-form.enabled=true
My cas.properties file located at /etc/cas/config/:
cas.server.name=https://localhost:8443
cas.server.prefix=${cas.server.name}/cas
cas.serviceRegistry.json.location=file:/etc/cas/services
# cas.authn.accept.enabled=false
server.ssl.key-store=file:/etc/cas/thekeystore
server.ssl.key-store-password=changeit
cas.theme.defaultThemeName=example
spring.thymeleaf.cache=false
After I started the server with ./gradlew bootRun, I opened https://localhost:8443/cas/login on my chrome browser. The CSS, Image and JS seems to load fine (I confirmed it using Chrome Devtool), but the default template was used instead of my custom template.
I had tried googling around for several hours now and I still can't figure out how to make cas load my html template.
P/s: I tried moving all the resources content to cas/build/resources, cas/build/resources/main but it does not seem to work either.

Starting with 6.4 RC5 (which is the version you run as of this writing and should provide this in your original post):
The collection of thymeleaf user interface template pages are no longer found in the context root of the web application resources. Instead, they are organized and grouped into logical folders for each feature category. For example, the pages that deal with login or logout functionality can now be found inside login or logout directories. The page names themselves remain unchecked. You should always cross-check the template locations with the CAS WAR Overlay and use the tooling provided by the build to locate or fetch the templates from the CAS web application context.
https://apereo.github.io/cas/development/release_notes/RC5.html#thymeleaf-user-interface-pages
Please read the release notes and adjust your setup.
All templates are listed here:
https://apereo.github.io/cas/development/ux/User-Interface-Customization-Views.html#templates

Related

How to properly server static files from a Flask server?

What is the proper way of serving static files (images, PDFs, Docs etc) from a flask server?
I have used the send_from_directory method before and it works fine. Here is my implementation:
#app.route('/public/assignments/<path:filename>')
def file(filename):
return send_from_directory("./public/assignments/", filename, as_attachment=True)
However if I have multiple different folders, it can get a bit hectic and repetitive because you are essentially writing the same code but for different file locations - meaning if I wanted to display files for a user instead of an assignment, I'd have to change it to /public/users/<path:filename> instead of /public/assignments/<path:filename>.
The way I thought of solving this is essentially making a /file/<path:filepath> route, where the filepath is the entire path to the destination folder + the file name and extension, instead of just the file name and extension. Then I did some formatting and separated the parent directory from the file itself and used that data when calling the send_from_directory function:
#app.route('/file/<path:filepath>', methods=["GET"])
def general_static_files(filepath):
filepath = filepath.split("/")
_dir = ""
for i, p in enumerate(filepath):
if i < len(filepath) - 1:
_dir = _dir + (p + "/")
return send_from_directory(("./" + _dir), filepath[len(filepath) - 1], as_attachment=True)
if we simulate the following request to this route:
curl http://127.0.0.1:5000/file/public/files/jobs/images/job_43_image_1.jpg
the _dir variable will hold the ./public/files/jobs/images/ value, and then filepath[len(filepath) - 1] holds the job_43_image_1.jpg value.
If i hit this route, I get a 404 - Not Found response, but all the code in the route body is being executed.
I suspect that the send_from_directory function is the reason why I'm getting a 404 - Not Found. However, I do have the image job_43_image_1.jpg stored inside the /public/files/jobs/images/ directory.
I'm afraid I don't see a lot I can do here except hope that someone has encountered the same issue/problem and found a way to fix it.
Here is the folder tree:
├── [2050] app.py
├── [2050] public
│   ├── [2050] etc
│   └── [2050] files
│   ├── [2050] jobs
│   │   ├── [2050] files
│   │   └── [2050] images
│   │   ├── [2050] job_41_image_decline_1.jpg
│   │   ├── [2050] job_41_image_decline_2554.jpg
│   │   ├── [2050] ...
│   ├── [2050] shop
│   └── [2050] videos
└── [2050] server_crash.log
Edit 1: I have set up the static_url_path. I have no reason to believe that that could be the cause of my problem.
Edit 2: Added tree
Pass these arguments when you initialise the app:
app = Flask(__name__, static_folder='public',
static_url_path='frontend_public' )
This would make the file public/blah.txt available at http://example.com/frontend_public/blah.txt.
static_folder sets the folder on the filesystem
static_url_path sets the path used within the URL
If neither of the variables are set, it defaults to 'static' for both.
Hopefully this is what you're asking.

AWS Glue Crawler adding tables for every partition?

I have several thousand files in an S3 bucket in this form:
├── bucket
│ ├── somedata
│ │   ├── year=2016
│ │   ├── year=2017
│ │   │   ├── month=11
│ │   | │   ├── sometype-2017-11-01.parquet
│ | | | ├── sometype-2017-11-02.parquet
│ | | | ├── ...
│ │   │   ├── month=12
│ │   | │   ├── sometype-2017-12-01.parquet
│ | | | ├── sometype-2017-12-02.parquet
│ | | | ├── ...
│ │   ├── year=2018
│ │   │   ├── month=01
│ │   | │   ├── sometype-2018-01-01.parquet
│ | | | ├── sometype-2018-01-02.parquet
│ | | | ├── ...
│ ├── moredata
│ │   ├── year=2017
│ │   │   ├── month=11
│ │   | │   ├── moretype-2017-11-01.parquet
│ | | | ├── moretype-2017-11-02.parquet
│ | | | ├── ...
│ │   ├── year=...
etc
Expected behavior:
The AWS Glue Crawler creates one table for each of somedata, moredata, etc. It creates partitions for each table based on the childrens' path names.
Actual Behavior:
The AWS Glue Crawler performs the behavior above, but ALSO creates a separate table for every partition of the data, resulting in several hundred extraneous tables (and more extraneous tables which every data add + new crawl).
I see no place to be able to set something or otherwise prevent this from happening... Does anyone have advice on the best way to prevent these unnecessary tables from being created?
Adding to the excludes
**_SUCCESS
**crc
worked for me (see aws page glue/add-crawler). Double stars match the files at all folder (ie partition) depths. I had an _SUCCESS living a few levels up.
Make sure you set up logging for glue, which quickly points out permission errors etc.
Use the Create a Single Schema for Each Amazon S3 Include Path option to avoid the AWS Glue Crawler adding all these extra tables.
I had this problem and ended up with ~7k tables 😅 so wrote the following script to remove them. It requires jq.
#!/bin/sh
aws glue get-tables --region <YOUR AWS REGION> --database-name <YOUR AWS GLUE DATABASE> | jq '.TableList[] | .Name' | grep <A PATTERN THAT MATCHES YOUR TABLENAMEs> > /tmp/table-names.json
cd /tmp
mkdir table-names
cd table-names
split -l 50 ../table-names.json
for f in `ls`; cat $f | tr '\r\n' ' ' | xargs aws glue batch-delete-table --region <YOUR AWS REGION> --database-name <YOUR AWS GLUE DATABASE> --tables-to-delete;
check if you have empty folders inside. When spark writes to S3, sometimes, the _temporary folder is not deleted, which will make Glue crawler create table for each partition.
I was having the same problem.
I added *crc* as exclude pattern to the AWS Glue crawler and it worked.
Or if you crawl entire directories add */*crc*.
So, my case was a little bit different and I was having the same behaviour.
I got a data structure like this:
├── bucket
│ ├── somedata
│ │ ├── event_date=2016-01-01
│ │ ├── event_date=2016-01-02
So when I started AWS Glue Crawler instead of update the tables, this pipeline was creating a one table per date. After digging into the problem I found that someone added a column as a bug at the json file instead of id was ID. Because my data is parquet the pipeline was working well to store the data and retrieve inside the EMR. But Glue was crashing pretty bad because Glue convert everything to lowercase and probably that was the reason why it was crashing. Removing the uppercase column glue start to work like a charm.
You need to have separate crawlers for each table / file type. So create one crawler that looks at s3://bucket/somedata/ and a 2nd crawler that looks at s3://bucket/moredata/.

Importing files from other directory in python?

I have following directory structure:
A
|
|--B--Hello.py
|
|--C--Message.py
Now if the path of root directory A is not fixed, how can i import "Hello.py" from B to "Message.py" in C.
At first I suggest to add empty __init__.py file into every directory with python sources. It will prevent many issues with imports because this is how the packages work in Python:
In your case it this should look like this:
A
├── B
│   ├── Hello.py
│   └── __init__.py
├── C
│   ├── Message.py
│   └── __init__.py
└── __init__.py
Let's say the Hello.py contains the function foo:
def foo():
return 'bar'
and the Message.py tries to use it:
from ..B.Hello import foo
print(foo())
The first way to make it work is to let the Python interpreter to do his job and to handle package constructing:
~ $ python -m A.C.Message
Another option is to add your Hello.py file into list of known sources with the following code:
# Message.py file
import sys, os
sys.path.insert(0, os.path.abspath('..'))
from B.Hello import foo
print(foo())
In this case you can execute it with
~/A/C $ python Message.py

Cant load css of Glyphicon. bootstrap - django

I work in Django, and trying to load the css file of the Glyphicon for i can use that icons.
I download the css file named "bootstrap.css" from bootstrap, and then upload this file to my statics files on the "css" directory.
The staticfile loading its not the problem, becaues another css files i put in "css directory" are work.
Should i do more actions instead of just upload "bootstrap.css" to my static files? i saw there (in the downliaded zip file) a "map" file for that css file, but i didnt think it connected.
You need to download glyphicon fonts and put them in the ../fonts directory (path relative to your bootstrap.css) so your path structure resembles that:
your_static_dir
├── css
│   └── bootstrap.css
└── fonts
   ├── glyphicons-halflings-regular.eot
   ├── glyphicons-halflings-regular.svg
   ├── glyphicons-halflings-regular.ttf
   └── glyphicons-halflings-regular.woff
look at path in "bootstrap.css" line 266
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
static
css
bootstrap.css
bootstrap.css.map
...
fonts
glyphicons-....eot
glyphicons-....svg
glyphicons-....ttf
glyphicons-....woff
glyphicons-....woff2
js
...

How to run multiple Groovy unit tests

I want to keep my groovy source files in their own directory, with the tests being in a separate directory.
I have the directory structure as follows:
.
├── build
│   └── Messenger.class
├── build.xml
├── ivy.xml
├── lib
├── src
│   └── com
│   └── myapp
│   └── Messenger.groovy
└── test
└── unit
├── AnotherTest.groovy
└── MessengerTest.groovy
I can successfully run one test by using the groovy command and specifying the class path for the units under test using -cp to point to build/ but how do I run all the tests in the directory?
Tou can run all unit test with command:
grails test-app unit:
If you have unit, integration, functional... tests you can run all tests with command:
grails test-app
I am new to groovy, but I wrote my own test runner and put it in root directory of my project. Source code:
import groovy.util.GroovyTestSuite
import junit.textui.TestRunner
import junit.framework.TestResult
import static groovy.io.FileType.FILES
public class MyTestRunner {
public static ArrayList getTestFilesPaths(String test_dir) {
// gets list of absolute test file paths
ArrayList testFilesPaths = new ArrayList();
new File(test_dir).eachFileRecurse(FILES) {
if(it.name.endsWith(".groovy")) {
testFilesPaths.add(it.absolutePath)
}
}
return testFilesPaths;
}
public static GroovyTestSuite getTestSuite(ArrayList testFilesPaths) {
// creates test suite using absolute test file paths
GroovyTestSuite suite = new GroovyTestSuite();
testFilesPaths.each {
suite.addTestSuite(suite.compile(it));
}
return suite;
}
public static void runTests(GroovyTestSuite suite) {
// runs test in test suite
TestResult result = TestRunner.run(suite);
// if tests fail return exit code non equal to 0 indicating that
// tests fail it helps if one of your build step is to test files
if (!result.wasSuccessful()) {
System.exit(1);
}
}
}
ArrayList testFilesPaths = MyTestRunner.getTestFilesPaths("tests");
GroovyTestSuite suite = MyTestRunner.getTestSuite(testFilesPaths);
MyTestRunner.runTests(suite)
if you try to use this be aware that if it fails it is most likely that getTestFilesPaths is not working properly.
My directory structure
.
├── test_runner.groovy
├── src
│ └── ...
└── tests
└── Test1.groovy
└── someDir
├── Test2.groovy
└── Test3.groovy
How to run
From the same directory where test_runner.groovy is run:
groovy test_runner.groovy