validate the private end point without the db instance - azure

When we are doing the dry run for private endpoint, its checking the instance of db instance.
Can we find whether any ways to validate the private end point without the db instance and later update it?

Related

Node.js express app architecture with testing

Creating new project with auto-testing feature.
It uses basic express.
The question is how to orginize the code in order to be able to test it properly. (with mocha)
Almost every controller needs to have access to the database in order to fetch some data to proceed. But while testing - reaching the actual database is unwanted.
There are two ways as I see:
Stubbing a function, which intends to read/write from/to database.
Building two separate controller builders, one of each will be used to reach it from the endpoints, another one from tests.
just like that:
let myController = new TargetController(AuthService, DatabaseService...);
myController.targetMethod()
let myTestController = new TargetController(FakeAuthService, FakeDatabaseService...);
myTestController.targetMethod() // This method will use fake services which doesnt have any remote connection functionality
Every property passed will be set to a private variable inside the constructor of the controller. And by aiming to this private variable we could not care about what type of call it is. Test or Production one.
Is that a good approach of should it be remade?
Alright, It's considered to be a good practice as it is actually a dependency injection pattern

How to create a new Authority in jHipster?

I wonder if it is possible to create a new Authority in Jhispter. I tried adding a ROLE_WRITER:
/project/src/main/java/location/security/AuthoritiesConstants.java
package location.security;
/**
* Constants for Spring Security authorities.
*/
public final class AuthoritiesConstants {
public static final String ADMIN = "ROLE_ADMIN";
public static final String USER = "ROLE_USER";
public static final String WRITER = "ROLE_WRITER";
public static final String ANONYMOUS = "ROLE_ANONYMOUS";
private AuthoritiesConstants() {
}
}
When I run the app, it does not crash, but when I tried to change the localhost:9000/#/user-management ROLE in the profile, it did not offer me the option.
So I went to the database and add a new ROLE in the JHI_AUTHORITY Table and now it appears in the user-management, but I have the feeling that i'm getting into trouble if I mess around with the User Entity.
Is there any official way of doing it? (that I am not aware of)
Is there any danger with doing it?
Is there anything else that I should consider?
Thanks
Is there any official way of doing it? (that I am not aware of)
Have you seen src/main/resources/liquibase/authorities.csv? I think that is a right place to add a new authority before production, and when you are in production stage, then it is recommended to add your change(insert into) as liquibase changeset.
Is there any danger with doing it?
AFAIK new role will work like other existing roles in Spring security context. having said that I might misunderstood your question.
Is there anything else that I should consider?
Automation, this type of manual changes will cause dysfunction in production or new installation, so we need to automate this type of changes for both situations.
Although this is already answered, I think it's a good idea to put a link to a related tip posted in the official website of JHipster:
https://www.jhipster.tech/tips/025_tip_create_new_authority.html
I faced the same issue, I added drop-first: true parameter to src/main/resources/config/application-dev.yml:
....
liquibase:
contexts: dev
drop-first: true
....
It seems like it ais a parameter to regenerate the database (for development mode).

Refreshing in-memory cache across multiple instances in Azure

I have an Azure web app which uses in-memory caching, adding keys as follows
public static void Add(object item, string key)
{
var wrapper = new CacheItemWrapper()
{
InsertedAt = DateTime.Now,
Item = item
};
MemoryCache.Default.Add(key, wrapper, ObjectCache.InfiniteAbsoluteExpiration);
}
Occasionally the user of our application will make a change which requires the cache to refresh. I can call a method which clears the cache, the problem is, it only works on the instance which picks up the request. Other instances still have the old values in memory.
Is there any way I can do either of these things
a) run a method across multiple instances, or
b) raise an event which all instances listen for?
The code above could be changed to expire within a short time so that all instances could pick this up. However, it's quite a long process to update the cache and this might affect performance. Given the application knows when it needs to refresh the cache, it would be much better and more responsive if it could be done programmatically.

Add current user to entity when created

I have created an entity with the help of the Yeoman generator. I chose not to create a DAO. The entity has a relationsship with User.
Now when I create an object I get to choose owner in a dropdown, but I would want to set owner to the currently logged on user. What's the best approach to do this?
I have tried
#Autowired
private Authentication authentication;
and
activity.setOwner((User) authentication.getPrincipal());
in the Resource Class, but this throws this exception
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.Authentication
Regards
Mattias
Well, I think all of your problem is in getting the current user.
So what make you stop from using the your.package.security.SecurityUtils.getCurrentLogin()?.
The above code will give you the login name. If you need either id or the user object as a whole, then you will need to fetch from DB. You can also use UserService to do so.

How can I execute the salt state git.latest with password protected private key

I'm using salt to pull a git repo.
myrepo:
git.latest:
- rev: master
- target: home/myuser/myapp
- runas: myuser
I have added an id_rsa file into /home/myuser/.ssh/, including the private key to authenticate to github. If this private key is not password protected the above git.latest state works fine.
If the private key is password protected (as it should be) the above git.latest state fails with the error message "fatal: The remote end hung up unexpectedly". The reason that this state fails is that the system is asking for the private key password.
Now I'm wondering how I could tell my salt master to provide the password to the password protected private key. I think it should somehow work with a linux key chain util - or is there even some similar functionality build-in within saltstack?
I'd suggest that you use special key used only for that purpose. Github offers deploy keys for this very scenario: https://help.github.com/articles/managing-deploy-keys
They are easily set up and easily revoked.

Resources