F#: unable to use Suave.Types for build script - f#

Trying to use Thomas Petriek's build script: https://github.com/tpetricek/suave-xplat-gettingstarted/blob/master/build.fsx
Getting error that the namespace Types is not defined in open Suave.Types.
Is this some namespace that has since been deprecated?

I am not sure if that is an old version of the build script, but I am using the same build script myself, I had to make a couple of changes namely, remove the logging, use
open Suave.Http
instead of
open Suave.Types
and use these bindings
bindings = [ HttpBinding.create Protocol.HTTP Net.IPAddress.Loopback 8083us ]

Related

How do I access parsing of .nimble files from the nimble package?

Nim as a language provides .nimble files to describe its packages (example of a .nimble file). I know that the file is parsed by the nimble package and CLI-tool, as they need the information inside the .nimble file for their tasks.
I want basically all the information in there, dependencies, author, license, description, version, all of it. So in order to not do the same work twice and potentially run into issues should the format change, I would like to use the nimble package itself to parse the .nimble file for me.
I know the correct proc for it, which is getPkgInfoFromFile, but I can't seem to access it with import nimble/nimblepkg/packageparser.
Whenever I use that line I receive an error that there is no such file.
What am I doing wrong?
Further: getPkgInfoFromFile requires an Options instance that it generates when parsing a CLI command. I don't have a CLI command, so I'm not generating such an instance, can I use the proc somehow without one?
Thanks to ringabout I came to the correct solution, but first to the question.
Question 1: How do I access the proc in the first place?
You can access nimble like a package, but the import is not import nimble/nimblepkg/packageparser it is directly import nimblepkg/packageparser.
This requires you to have both nimble' installed as a library as well as the compiler` installed as a library.
So you'll have to install those first:
nimble install nimble
nimble install nim # Originally this was called "compiler", but was renamed to "nim"
Ignore any warnings if they pop up.
Now you can compile the following dummy-example:
#dummy.nim
import nimblepkg/packageparser
echo "Pointer to packageparser proc: ", packageparser.getPkgInfoFromFile.repr
with: nimble -d:ssl --mm:refc -r build (-d:ssl is required for nimble's HTTP-client and --mm:refc is required as nimble appears to not work with orc)
Question 2: Can I run the getPkgInfoFromFile without an Options instance?
Yes-ish. You still need one, but it doesn't have to be a "real" one, you can just instantiate one yourself on the fly.
import nimblepkg/[options, packageinfotypes, packageparser]
proc generateDummyOptions(): Options =
result = initOptions()
result.setNimBin()
result.setNimbleDir()
proc parseNimbleFile*(nimblePath: string): PackageInfo =
let options = generateDummyOptions()
result = getPkgInfoFromFile(nimblePath.NimbleFile, options)

import python functions into serversless

I h got an issue with the following serverless config.
this is my handler and the files/folders structure.
the issue is that after uploading my project to AWS when I test my lambda I got an error as follows:
lambda execution fails: "errorMessage": "Unable to import module 'app_monitor': No module named 'monitoring'"
{
"errorMessage": "Unable to import module 'src/app_monitor': No module named 'monitoring'",
"errorType": "Runtime.ImportModuleError",
"requestId": "bca3f67d-815f-452b-a2a6-c713ad2c6baa",
"stackTrace": []
}
have you got any clue how can I add this into serverless config.?
First, a quick tip on troubleshooting: When I ran into such issues it was helpful to go to the AWS console, look at the lambda function, and see what the uploaded file structure looks like on that end. Is the monitoring folder there?
Moreover, in order to specify how a specific function is packaged, you have to explicitly state that you want it to be individually packaged and not follow the general rules of the project as a whole.
You should try to add:
app_monitoring:
package:
individually: true
patterns:
- 'src/**'
More documentation on packaging configuration here
You may also have better luck with explicitly stating the patterns you need, I know I've had issues with globs in the past. So for example you can try:
patterns:
- 'src/app_monitoring.py'
- 'src/monitoring/get_lb.py'

TFS check if file exists in build directory

Is there a way to check if a specific .xml file exists in build directory when TFS build runs?
I'm trying to get a Boolean result true/false based on the result found/not found
I tried creating a variable that would store this result (I'm guessing that is the way to do it). However I get an error when trying to use it.
You can try writing a script to check if the specific file exist, then check in the script and run as Pre-build script in your build process:
e.g.:
$Source = $Env:TF_BUILD_BUILDDIRECTORY
$filename = "*.xml"
if (!(Test-Path "$Source\$filename"))
{
Write-Warning "$filename absent from build directory"
# Write-Error "$filename absent from build directory"
#exit 1
}
Reference Using Environment Variables in Visual Studio 2013 and TFS 2013
The expression editor uses standard VB.NET, so you can call into System.IO.File.Exists(path) to detect whether a file already exists.
Found the solution. I added a new variable "dcMatchedFile" - which is a IEnumerable type. Use this dcMatchedFile as "Result" option for FindMatchingFiles" item (see images below)
Then you can simply use "If" statement to check Any().

Running F# xUnit Fact from TestDriven.NET reporting "It looks like you're trying to execute an xUnit.net unit test."

I am trying to run xUnit tests (from an F# module, if it makes any difference) using TestDriven.NET, but whatever I do I get this error:
It looks like you're trying to execute an xUnit.net unit test.
For xUnit 1.5 or above (recommended):
Please ensure that the directory containing your 'xunit.dll' reference also contains xUnit's
test runner files ('xunit.dll.tdnet', 'xunit.runner.tdnet.dll' etc.)
For earlier versions:
You need to install support for TestDriven.Net using xUnit's 'xunit.installer.exe' application.
You can find xUnit.net downloads and support here:
http://www.codeplex.com/xunit
I tried following the suggestions, i.e. I copied the files
xunit.dll.tdnet
xunit.extensions.dll
xunit.gui.clr4.exe
xunit.runner.tdnet.dll
xunit.runner.utility.dll
xunit.runner.utility.xml
xunit.xml
to the folder with xunit.dll and I ran xunit.installer.exe. How can I get it to work?
I just figured out that I forgot to make the test a function in F# (so it was just a value). The error message can't be more misleading though!
You have two problems:
your Fact is broken:-
If you hover over the
please work
bit, you'll see something like: unit -> int
For a Fact to be picked up by an xUnit runner, it needs to yield `unit (void).
Hence, one key thing to get right first is to not return anything. In other words, replace your 123 with () (or an Assertion).
You can guard against this by putting a :unit stipulation on the test:-
[<Fact>]
let ``please work`` () : unit = 123
This will force a compilation error.
TestDriven.NET is reporting it cannot find the xunit.tdnet modules
It's critical to get step 1 right first. Then retry and the problem should be gone
If it remains...
Either try the VS-based runner which should work as long as it's installed and xunit.dll is getting to your output dir or look at the docs for your version of TD.NET for detailed troubleshooting notes (exec summary is if the .tdnet file was in your out dir or you undo and redo the xunit.installer from the folder containing the packages it should just work, esp if you are on latest)

How do I deal with WS-Security when all I have is a wsdl?

I'm trying to develop a stand-alone client app that uses web services in a Glassfish container (Metro). About all I have to work from is a wsdl for the wervices I'm trying to use. The wsdl is rife with all kinds of 'wsp:Policy' tags. Looks like IssuedToken, Trust13, ecryption are all utilized.
So I generated some code from netbeans and JAX-WS. Everything went well, but when trying to run the client I get:
'WST0029:STS location could not be obtained from either IssuedToken or from client configuration for accessing the service http://localhost:8080/ ....'
That's when it occured to me that I know nothing about WSS. It doesn't look like any code was generated to deal with security. So, I'll have to go from scratch.
So where to start? Books? Tutorials?
TIA
Metro applies the policy in runtime from either the WSDL or the wsit-client.xml config file. That's why no code is generated related to policies. According to this post it is not possible at the moment to do programatically.
This tutorial explains pretty well some of the things you can do with WSS, and though everything do probably not apply in this case it's still a good read.
The simplest way I've found of generating a client with WSS support is by using the wsimport script from Metro:
cd metro/bin/
mkdir src target
./wsimport.sh -s src -d target -extension -Xendorsed -verbose YourService.wsdl
Then install Metro into your application server (copy the libs to the correct places or run the ant script):
ant -f metro-on-glassfish.xml
Then put your local WSDL file in your classpath (e.g. your resource folder), so Metro can get it at runtime to apply the policies from your generated YourService class:
private final static URL YOURSERVICE_WSDL_LOCATION;
// This is enough, you don't need the wsdlLocation attribute
// on the #WebServiceClient annotation if you have this.
static {
YOURSERVICE_WSDL_LOCATION =
CustomerService.class.getClassLoader().getResource("YourService.wsdl");
}
public YourService() {
super(YOURSERVICE_WSDL_LOCATION,
new QName("http://tempuri.org/", "YourService"));
}
And if you want WS-Addressing you might need to add the feature manually to your binding method (Metro has never generated it for me, so I always have to add it myself).
#WebEndpoint(name = "WSHttpBinding_IYourService")
public IYourService getWSHttpBindingIYourService() {
WebServiceFeature wsAddressing = new AddressingFeature(true);
IYourService service =
super.getPort(new QName("http://xmlns.example.com/services/Your",
"WSHttpBinding_IYourService"), IYourService.class,
wsAddressing);
return service;
}

Resources