Do I need to explicitly mention every file in the file block? - terraform

I got a quick question about azurem_function_app_function's file block property. I have a project with 3 azure functions, all in Python.
They all have several files, modules...etc.My question is the following: do I need to explicitly mention every file in the file block? Or does just mentioning the entrypoint file suffice? ie, is the following enough, or is that feature for simple functions?
resource "azurerm_function_app_function" "function" {
name = "function_name"
function_app_id = azurerm_linux_function_app.function_app.id
language = "Python"
file {
name = "app.py"
content = file("../function_name/app.py")
}
config_json = jsonencode({
"bindings" = [{
"name" : "mytimer",
"type" : "timerTrigger",
"direction" : "in",
"schedule" : "0 */5 * * * *"
}]
})
}

It is recommended that you include all files on which your function depends, including source code and any other necessary files such as configuration files, templates, or data files. If all of your other required files are in the same directory as app.py, the deployment package will include them. Suppose they are in a different directory or are not directly or indirectly imported by your Python code. In that case, you must include them explicitly in the file block to ensure they are included.
I hope I have been able to answer your question.

Related

Why can't Groovy find my file?

I wrote a script in groovy to find files java test files recursively in a given directory with certain names, the concerned part of the code is:
def projectRootDirectory = args.length ? new File(args[0]) : new File(System.getProperty("user.dir"))
def srcFilesCount = 0, testFilesCount = 0, srcLinesCount=0, testLinesCount=0
def srcFileSubstringPattern = '.java'
def testFileSubstringPattern = 'Test.java'
projectRootDirectory.eachDirRecurse() { dir ->
dir.eachFile {
if (it.name.endsWith(testFileSubstringPattern) || it.name ==~ /Test.*java/ ||
it.name.endsWith('Tests.java') || it.name.endsWith('TestCase.java')) {
//println "Test file found: " + it.name
testFilesCount++
it.eachLine { testLinesCount++ }
} else if (it.name.contains(srcFileSubstringPattern)) {
srcFilesCount++
it.eachLine { srcLinesCount++ }
}
}
}
It finds already existing files in the repo which was cloned using SVN that match for example someTestCase.java, but when I created some new ones by using the command touch dummyTestCase.java via Cygwin in Windows 7 or via the Windows 7 explorer right click -> New -> Text Document option and rename it to something like TestDummy.java, it doesn't find them. The script also treats copies of the respective files the same way i.e. it finds copies of old files that already existed but not the new ones I create. I even opened up file permissions to fullest on the newly created files, but no change. Whereas the BASH find command via Cygwin always finds all the files without any issue. I have confirmed using diagnostic print statements the the script is looking in the correct directory. I even confirmed this by having the script create some files there and confirmed they got created in the correct place.
Wow, the answer turned out to be amazingly simple. I replaced eachDirRecurse with eachFileRecurse thus also eliminating the nested loop. Thanks a ton to all the comment authors whose help led me to this discovery.

Need Help Understanding Node JS Syntax Error

Can anyone please help me to understand the syntax error based on the attached screenshot below?
My script is supposed to access a given JSON and return the specific value, but somehow it's returning this error.
Edit 1
I tested my script with a dummy JSON and the script didn't return any error, so I suspect my original JSON might be giving problem. Here's my JSON.
{
"og_object": {
"id": "1192199560899293",
"description": "Hi everyone I have an important announcement to make. So ever since Penny started school, I've been having mixed feelings. \u00a0Besides having a bit of space to myself to breathe and rest my brain/legs, I'm actually a bit bittersweet cos my little baby, who used to sleep at weird hours and gobble puree",
"title": "Fighter and Penny's new sibling",
"type": "article",
"updated_time": "2017-04-12T01:17:57+0000"
},
"share": {
"comment_count": 0,
"share_count": 109
},
"id": "http://fourfeetnine.com/2017/03/05/fighter-and-pennys-new-sibling/"
}
Edit 2
Here's my script that I run that produces the error.
var objects = require('./output.txt');
console.log(objects);
output.txt is the file that contains the JSON that I pasted in Edit 1
var objects = require('./output.txt');
The require() function belongs to the module loading system. Despite the name, it can actually load several types of files and directories and not only Node modules. As per the high-level algorithm in pseudocode shown in docs:
require(X)
If X begins with './' or '/' or '../'
a. LOAD_AS_FILE(Y + X)
[...]
LOAD_AS_FILE(X)
If X is a file, load X as JavaScript text. STOP
If X.js is a file, load X.js as JavaScript text. STOP
If X.json is a file, parse X.json to a JavaScript Object. STOP
If X.node is a file, load X.node as binary addon. STOP
Since you get SyntaxError, output.txt does not contain valid JavaScript code.
If you really want to load JSON, you need to enforce subrule #3 by renaming the file to output.json.
Thanks to #Jordan suggestion. The fault is indeed due to wrong file extension. After changing the file extension from .txt to .json, then the syntax error disappeared.

Reading from rotating log files in logstash

As per the documentation of logstash's file plugin, the section on File Rotation says the following:
To support programs that write to the rotated file for some time after
the rotation has taken place, include both the original filename and
the rotated filename (e.g. /var/log/syslog and /var/log/syslog.1) in
the filename patterns to watch (the path option).
If anyone can clarify how to specify two filenames in the path configuration, that will be of great help as I did not find an exact example. Some examples suggest to use wild-cards like /var/log/syslog*, however I am looking for an example that achieves exactly what is said in documentation - two filenames in the path option.
The attribute path is an array and thus you can specify multiple files as follows:
input {
file{
path => [ "/var/log/syslog.log", "/var/log/syslog1.log"]
}
}
You can also use * notation for name or directory as follows:
input {
file{
path => [ "/var/log/syslog.log", "/var/log/syslog1.log", "/var/log/*.log", "/var/*/*.log"]
}
}
When you specify path as /var/*/*.log it does a recursive search to get all files with .log extension.
Reference Documentation

Check file type in Linux

I want to check certain files and see if their types and extensions are matching. What I'm currently doing is using the file command to check the mime type (or basic output from file) and comparing it with the file extension. However, some file types returns the same mime-type, .sfx and .dll for example.
Also i have some files with no extension at all, and i should be able to determine file type of them correctly.
I want to be able to get all file types correctly but the most important file types that i m currently interested in are;
dll
msi
com
cpl
exe
ocx
tmp
upd
Is there any other tool that checks and returns a file's type?
EDIT
I wrote a nodejs script that can be used as a linux command. I have created my own file signature database by merging public databases, which has the following format for each file extension;
"ISO" : [
{
"signature": "4344303031", // byte sequence
"size": 5, // size of byte sequence
"offset": 32769 // offset in the file for the signature bytes
},
{
"signature": "4344303031",
"size": 5,
"offset": 34817
},
{
"signature": "4344303031",
"size": 5,
"offset": 36865
}
]
Now; i first check signature bytes for the extension available in the file's name (text.iso will result .iso), and i go and check the signature bytes of that file to see if that is really an iso file.If it is indeed iso, i return iso as result.
If it's not iso, i check all the signature byte sequences for every extension i have in my db against the given file to see if any of them matches. If i have a match, i return the result.
If i cannot find a match, i execute the file command, get the file's mime-type, and use another db i created for matching mime-types with extensions, to see if that has a match. The format for the mime-type db is like this;
"application/atom+xml": [
"atom",
"xml"
],
"application/atomcat+xml": [
"atomcat"
],
"application/atomsvc+xml": [
"atomsvc"
]
This solution currently meets my project's needs. Maybe this might help someone else aswell.
Using Python after pip install filemagic:
>>> import magic
>>> with magic.Magic() as m: m.id_filename('tmp.py')
...
'Python script, ASCII text executable'
>>> with magic.Magic() as m: m.id_filename('test.html')
...
'HTML document, ASCII text'
Linux has a built-in file command: man file
The main difference between Windows and *nix is that DOS/Windows has built-in dependencies on file suffix. For example, an executable must be named ".exe" (or .com); a .bat file must be named ".bat" (or .cmd).
Linux, MacOS, BSD, etc have no such restriction. Instead, they must have "execute" permission set in order to be "runable". This is true for either a binary executable (e.g. compiled code) or a script (e.g. Python, Perl ... or a shell script).
Instead of relying only on file suffix, the "file" command also looks at self-identifying "magic numbers" or other "header information" in the file itself.
SUGGESTION:
If the built-in "file" doesn't meet your needs; perhaps you can wrap it in a shell script that:
1) Checks for certain "well known suffixes" (use basename to extract the suffix), and/or
2) Calls "file" as a fallback

Jenkins - Dynamic Choice Parameter - Removing File extension from list

I am having a bit of trouble getting my groovy code to work properly in Jenkins using the Dynamic choice parameter. We currently have a folder that contains a lot of properties files for various environments. The following groovy code returns a list of all the file names correctly, however it is appending the file extension which is unneeded.
Arrays.asList(new File("path").list())
How would I change that to only list .xml files and not append the file extension in the list. I've found some examples of this while searching, but for some reason when I try some of these examples it isn't populating the list.
You mean like:
new File( 'path' ).list()
.findAll { it.endsWith( '.xml' ) }
.collect { it[ 0..-5 ] }
That gets the list of files (as Strings), keeps those that end with .xml, then removes the .xml off the end

Resources