How to add agents to a running MAS in Jason? - agent

I want to add new Jason agents to an existing MAS which is already running. Is it possible?

Yes, this question is being addressed in Jason FAQ. As it shows any other agent may create new ones using .create_agent internal action as bellow:
+a : true
<- ... ;
.create_agent(bob, "myAgent.asl");
... .

Related

How to set a `User cap` for a particular domain in Gitlab

Original question:
I want to limit the number of users from a particular domain that can register into my Gitlab instance. I noticed that I could set a "user cap", but it wasn't specific to a domain.
For example:
I want to limit the number of users registered from these domains. 20 users from testdomain1.com and 30 users from testdomain2.com are allowed to sign up. So, if there are already 20 users registered sucessfully from testdomain1.com, new user from testdomain1.com will not be allowed to sign up.
What should I do for it?
2021.11.18 Edited:
I added a validate to the User model:
# gitlab/app/models/user.rb
class User < ApplicationRecord
# ...
validate :email_domain, :ensure_user_email_count
# ...
def email_domain
email_domain = /\#.*?$/.match(email)[0]
email_domain
end
def ensure_user_email_count
# select count(*) from users where email like '%#test.com';
if User.where("email LIKE ?", "%#{email_domain}" ).count >= 30
errors.add(email_domain, _('already has 30 registered email.'))
end
end
end
This validate can set "user cap = 30" for each domain but it's still not able to set a "User cap" for a particular domain.
Since the related issue post did not get any response yet. I'm tring to implement it by myself. And it seems like that I need to extend the UI of the Admin Settings page and add some related tables to database to set different "user cap" for different email domain.
The GitLab user cap seems to be per GitLab instance.
So if both your domains are reference the same GitLab instance, you would have only one user cap possible.
But if each of your domain redirects to one autonomous GitLab instance (per domain), then you should be able to set user cap per domain.
The OP Ann Lin has created the issue 345557 to follow that feature request.
TRhe OP reports:
A particular table is needed to store the caps.
But I don’t have enough time now to modify the UI so I found a simple way to do this:
The Allowed domains for sign-ups which called domain_allowlist in database is a text:
gitlabhq_production=# \d application_settings
...
domain_allowlist | text | | |
...
gitlabhq_production=# select domain_allowlist from >application_settings;
domain_allowlist
-------------------
--- +
- testdomain1.com+
- testdomain2.com+
(1 row)
I can modify the testdomain1.com to testdomain1.com#30 to store the user cap and use Regex to get the number 30.
I will modify the UI and add the database table later. And I’ll create a pull request on Gitlab when I’m done.

Making ServiceStack RedisSentinel use a RedisManagerPool instead of a PooledRedisClientManager

Using ServiceStack version 4.0.40.
I am trying get RedisSentinel to use the RedisManagerPool instead of the
PooledRedisClientManager so it will allow clients above the client pool size.
I see this in the docs to set this...
sentinel.RedisManagerFactory = (master,slaves) => new RedisManagerPool(master);
I'm not sure how to use this. Do I pass in the master host name? What if I don't know which is master because of a previous failover? I can't sentinel.start() to find out which is master because it will start with the PooledRedisClientManager, which isn't what I want.
Or, do I pass in the sentinel hosts? RedisManagerPool takes a list of hosts, I can pass in the sentinel hosts, but I cannot set it to sentinel.RedisManagerFactory as RedisManagerFactory is not convertible to RedisManagerPool.
I think I am missing something simple here. Any help appreciated.
UPDATE
As per mythz's comment below, this isn't available in version 4.0.40 of ServiceStack. But you can use;
sential.RedisManagerFactory.FactoryFn = (master, slaves) => new RedisManagerPool(master);
Thanks
This is literally the config you need to use to change RedisSentinel to use RedisManagerPool:
sentinel.RedisManagerFactory = (master,slaves) =>
new RedisManagerPool(master);
You don’t need to pass anything else, the master host argument uses the lambda argument.

Supervisor with Quantum Elixir Cron Job

Forgive me if I don't understand elixir really well as I am new to it...
I'm using quantum-elixir as a cron api to dynamically create cron jobs. When someone POSTS to a route I save the cron job details into my Ecto Repo and then simultaneously create a quantum job with Quantum.add_job.
In development when I close my server and restart it, i have to re-add all my cron jobs because they don't survive through a restart. So that got me thinking that if my application were to crash that would make me lose all the cron jobs. (I'm thinking about of scenarios where I host the app on Google compute engine and for whatever reason need to do a reset on the compute instance, ie upgrades on the box, etc.)
So I was wondering what the appropriate way to restart my app is while keeping these cron jobs?
Right now I have the following:
worker(Task,[MyApp.RebootTask, :reboot, []], restart: :transient)
in the start function of my application module.
Is this the right approach? What other considerations do I need to factor in?
Any guidance is greatly appreciated
I query my db and create a list with the job definition of every item
%Quantum.Job{
name: job_name,
overlap: false,
run_strategy: %Quantum.RunStrategy.Random{nodes: :cluster},
schedule: Crontab.CronExpression.Parser.parse!(schedule),
task: task,
state: :active,
timezone: "Europe/Zurich"
}
To have the jobs started at application startup, I do something like this
defmodule Alerts.Scheduler do
use Quantum.Scheduler, otp_app: :alerts
require Logger
#environmet_blacklist [:test]
def init(opts) do
case Enum.member?(#environmet_blacklist, Mix.env()) or IEx.started?() do
true ->
IO.inspect(opts)
opts
false ->
delete_all_jobs()
opts_with_jobs = get_startup_config(opts)
opts_with_jobs |> IO.inspect()
opts_with_jobs
end
end
def get_startup_config(opts) do
job_definition = Alerts.Business.Alerts.get_all_alert_jobs_config()
(opts |> List.delete(List.keyfind(opts, :jobs, 0))) ++ [jobs: job_definition]
end
In my application start
def start(_type, _args) do
[
Alerts.Repo,
AlertsWeb.Endpoint |> supervisor([]),
if(System.get_env() != :test, do: Alerts.Scheduler),
Alerts.VersionSupervisor |> supervisor([])
]
|> Supervisor.start_link(strategy: :one_for_one, name: Alerts.Supervisor)
end
It doesn't look like Quantum persists dynamically-added cronjobs, since the more typical approach is to define your cronjobs (named or otherwise) in your config.exs.
Since you're already storing the job details with Ecto, it's just a matter of reading those details and readding them when your application starts. Since you're already using Quantum, the following in config/config.exs ought to do the trick:
config :quantum, cron: [
"#reboot": &MyApp.some_function_to_read_and_readd_my_cronjobs/0
]

How do I import members of one GitLab group into another

Does somebody know how I can import all members of one group into another in GitLab, rather than doing it manually one by one?
The only native feature which comes close is in lib/tasks/gitlab/bulk_add_permission.rake, which is mentioned in "User management"
# omnibus-gitlab
sudo gitlab-rake gitlab:import:all_users_to_all_groups
# installation from source
bundle exec rake gitlab:import:all_users_to_all_groups RAILS_ENV=production
You could take that as a model to develop our own task.
I am not aware of such a feature. But you can script it with the API. We use it here to add all users to one single group (all users to all groups is not feasible for our case).
Helpful documentation: http://doc.gitlab.com/ce/api/README.html, http://doc.gitlab.com/ce/api/users.html and http://doc.gitlab.com/ce/api/groups.html
There is also a respond to another question that might be helpful and lists also various modules for various programming languages: Is there a way to add users automatically into gitlab?
I was looking for a solution to Assign all Gitlab users to one particular group.
Here's the solution:
Create this file:
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/finder_import.rake
With this content:
namespace :gitlab do namespace :finder do
desc "GitLab | Add all users to group Colaboradores (admin users are added as owners)"
task importall: :environment do |t, args|
user_ids = User.where(admin: false).pluck(:id)
admin_ids = User.where(admin: true).pluck(:id)
groups = Group.where(name: "Colaboradores")
puts "Importing #{user_ids.size} users into #{groups.size} groups"
puts "Importing #{admin_ids.size} admins into #{groups.size} groups"
groups.each do |group|
puts "Importing into #{group.name}"
group.add_users(user_ids, GroupMember::DEVELOPER)
group.add_users(admin_ids, GroupMember::OWNER)
end
end
end end
Run this command:
gitlab-rake gitlab:finder:importall

Postfix : restricting specific domain for specific user

I am new to postfix . How can I blacklist specific domain for specific user using restriction class or by some other method.
Suppose my machine has two users - user1 and user2.
I want to blacklist or block the mails from abc.com to user1#mydomain whereas user2#mydomain.com can receive.
Similarly xyz.com should be blocked for user2#mydomain.com whereas user1#mydomain.com can receive.
Thanks in advance.
You can use restrictions class.
In main.cf, define your class like this:
smtpd_restriction_classes = ... ban_abc_com
ban_abc_com = check_sender_access hash:/etc/postfix/ban_adc_com, permit
The ban_adc_com file will contain:
adc.com REJECT
Then create a file table named protected_destinations containing:
user1#mydomain ban_abc_com
Then link all together in main.cf:
smtpd_recipient_restrictions = ..., check_recipient_access hash:/etc/postfix/protected_destinations
For user2, create a new class similar to ban_adc_com, then add in protected_destinations a new line containing:
user2#mydomain ban_xyz_com
You can see more here: Postfix restriction classes

Resources