Is there a way we can write mongodb aggregation pipeline by customizing services in feathers js - feathersjs

Can anyone provide basic examples of how to customize a feathers service to perform mongodb aggregation pipeline? I have tried it with hooks but I lost in the midway.

You can create Custom Service in FeathersJs where in the class you can use aggregation or also in hooks you can use it.
EX :
I have service users I want to get data through aggregation.
const userData = context.app.service('users').Model.aggregate([
// Use Your pipelines here
]);

Related

Passing sensitive information to cloud functions

Is there an "official" solution for passing sensitive information, such as API keys, to Google Cloud Functions? In particular it would be nice to avoid passing this information as arguments to the function since it will be the same for every invocation. AWS Lambda has a built-in solution using encrypted environment variables for this. Is there some similar approach for Google Cloud Functions?
I could imagine using a cloud storage bucket or cloud datastore for this, but that feels very manual.
If you're using Cloud Functions with Firebase, you're looking for environment configuration.
With that, you deploy configuration data from the Firebase CLI:
firebase functions:config:set someservice.key="THE API KEY" someservice.id="THE CLIENT ID"
And then read it in your functions with:
functions.config().someservice.id
You can use Google Secret Manager.
https://cloud.google.com/secret-manager/docs
See this article for an example:
https://dev.to/googlecloud/using-secrets-in-google-cloud-functions-5aem
The other answers are outdated, since firebase-functions v3.18.0 the recommended way is to use secrets (like env but passed explicitly to specific functions and without .env but a remote config) : https://firebase.google.com/docs/functions/config-env?hl=en#secret-manager
Before environment variable support was released in firebase-functions v3.18.0, using functions.config() was the recommended approach for environment configuration. This approach is still supported, but we recommend all new projects use environment variables instead, as they are simpler to use and improve the portability of your code.
You can use it like this:
firebase functions:secrets:set MY_SECRET
And answer a value to the CLI.
And then in your function:
exports.processPayment = functions
// Make the secret available to this function
.runWith({ secrets: ["MY_SECRET"] })
.onCall((data, context) => {
// Now you have access to process.env.MY_SECRET
});
Few options that you can go about this:
GCP Runtime Configuration. Set up a schema that can be only accessed by your service account and put your secret there. You do that prior to your deployment. Your app should be able to use Runtime Configuration API to access these. You can use this nifty library: https://www.npmjs.com/package/#google-cloud/rcloadenv
Generate a JS on the fly including that information as part of your cloud function build/deploy and include that file as part of you cloud function.
Use Google KMS to store the keys and access it with KMS's API
As for now, there's no way to do this.
https://issuetracker.google.com/issues/35907643

correct definition of methods Laravel 4

I have a question what would be the correct way to define methods within controllers.
I see many tutorials on using (index, show, create, store, edit, update, destroy) and in another use the following (getIndex, getShow, getCreate, postCreate, getEdit, postEdit).
the wake of this would like to know from the experts, which model to follow ?.
This is not really a Laravel problem and there is no "correct" way for a Laravel application, it's up to you, but there are some rules to follow in some cases.
Resourceful Controller Methods
The methods you listed are basically the Rails restfull ones:
index, show, create, store, edit, update, destroy
And they are automatically created by Artisan when you do:
php artisan controller:make ControllerName
Also a Laravel Restful route will expect them:
Route::resource('post', 'PostController');
RESTful Controllers
Here Laravel will try to automatically guess the kind of HTTP method your controller accepts and build all routes for you. So, if you have a route:
Route::controller('PostController');
And your PostController class having a method
public function getIndex()
{
...
}
You are telling Laravel to create a route GET to that method.
It's up to you
If you create all your routes manually, you could do:
Route::get('users', 'UsersController#usersIndex');
Pointing to
public function usersIndex()
{
...
}
And Laravel will not force you do any of those others ways.
Docs
Take a look at the docs: http://laravel.com/docs/controllers#restful-controllers
Here's some documentation about this in Rails: http://guides.rubyonrails.org/routing.html

SPRING-DATA-REST Backend with AngularJS frontend

Is there any frontend application sample that consumes RESTful services of Spring-data-rest backend which is written with angularJS.
My prefer for rest api for angularjs is RESTANGULAR module...
In the site you can see many examples that how they deal with Rest calls and really good documentation and good community as well...
In this example which is from spring example SPRING.IO they uses $http, but I should say that Restangular uses $http as well, so basically you can say that Restangular is extended version of $http...
and for the last you can look for $resource...
I will update my answer If I will find something new...
Here are some links to AngularJS apps consuming Spring RESTful services
https://github.com/spinner0815/spring-data-rest-angularjs
At the moment, I think that angular-hal is the best library to consume Spring Data Rest output and stay with its philosophy of discovering url through relations.
The home page: https://github.com/LuvDaSun/angular-hal
and some examples :
https://github.com/LuvDaSun/angular-hal/tree/master/demo (by the dev)
https://www.jiwhiz.com/blogs/Consume_RESTful_API_With_Angular_HAL
https://github.com/paulcwarren/gs-rolebased-ui-with-hypermedia
here has a nice lib spring-data-rest-js can help you.
It's a easy to use and lightweight javascript lib can run in both node.js and browser. After use this lib you can manage entity like this way:
let springRest = require('spring-data-rest-js');
let Student = springRest.entity.extend('students');
let student = new Student();
student.set('name', 'Tom');
//create entity
student.save().then(()=> {
//update entity
student.set('name', 'Physics');
retuen student.save();
}).then(()=> {
//delete entity
retuen student.delete();
}).catch(err=> {
done(err);
})
base on fetch API and Promise,inspired by Parse.
It can be work with lib like AngularJS React Vue...

Silex symfony ACL without ORM

Is there any way to implement ACL using Silex, but without Doctrine ORM?
Using entities we can handle this like this
$oidd = new Symfony\Component\Security\Acl\Domain\ObjectIdentity::fromDomainObject($message(\);
$acl = $app['security.acl.provider']->createAcl($oidd);
// the current user is the owner
$sid = Symfony\Component\Security\Acl\Domain\UserSecurityIdentity::fromAccount($currentUser);
$acl->insertObjectAce($sid, Symfony\Component\Security\Acl\Permission\MaskBuilder::MASK_OWNER);
Any solutions?
You might want to have a look at this example project.
https://github.com/davedevelopment/silex-acl-demo
The relevant bootstrap code is here (and works for me with Silex 1.2):
https://github.com/davedevelopment/silex-acl-demo/blob/master/app/bootstrap.php#L59
From the README:
This is a demo of Symfony's ACL using Silex. I've tried
to annotate the services in app/bootstrap.php, but to be honest, I
originally reverse engineered the symfony full stack frameworks DI
configuration without fully understanding what everything does, still
don't!

Angular - building a "public" function (newbie)

I'm After several days learning angularJS through converting my standart JS app to a ng one.
I was wondering about this simple scenario:
I have a global function called fb_connect(),
it can be used from any page (or any controller if you like) to make a facebook-based login.
This function makes a simple http call and receives a JSON object contain data to move on (display a pop up, login, etc...)
I read that I can define a Factory or a Service for my app and use it in any controller, which works fine.
So, I created a fb_connect factory function.
The problem is that now, in every page (every controller), I have to define that fb_connect in the constructor of every controller - for example :
function welcome($scope,fb_connect){});
What is the proper way to do this kind of actions using Angular without having to define these functions each and every time in every controller?
Thanks
Setting up factories and services is all part of the dependency injection system of Angular. Using that system is great when you need to create things that depend on other injected things. It's a big tree of dependencies. It's also nice for creating singletons, such that everywhere in your code end up using the same instance of some object.
It sounds to me like neither of these benefits apply in your case. I'd suggest just not using Angular's DI for it. You have some function defined globally, just call it directly and skip the DI. There's nothing wrong with that.
Of course you say it makes an Ajax call, so doesn't depend on the Angular $http service?
Your two options are:
Declare the function on the $rootScope
Inject it as a service
My advice is to go with making it a service. The whole purpose of services is explained in the Angular.js docs, just like this quote:
Angular services are singletons that carry out specific tasks common to web apps... To use an Angular service, you identify it as a dependency for the dependent (a controller, or another service) that depends on the service.
As you mentioned in your question, you'd prefer to not define the service in every controller you wish to use it in. With $rootScope you'll be injecting that also in every controller. So really it's a question of which you prefer, although to answer your question, the proper way of using a factory or service is to inject it into the controller you wish to use it in.
You can always put it in the $rootScope
myApp.run(function($rootScope, fb_connect){
$rootScope.welcome = function(){
};
});