Retrieving multiple objects from LDAP by DN at once - language-agnostic

I have a list of DNs, and for performance reasons I want to retrieve the attributes of every DN in the list in a single trip to the LDAP server.
Seems like searching by DN, i.e., using DN as a filter search, is not possible
Using DN in Search Filter
http://www.openldap.org/lists/openldap-software/200503/msg00520.html
....is there any alternative?

Sure you can.
ldapsearch -h <ldaphost> -b "cn=joe,dc=yourdoamin,dc=com" -s base -D cn=admin,dc=yourdomain,dc=com -W "(objectclass=*)" "*"
Will retrieve all user attributes for the DN: cn=joe,dc=yourdoamin,dc=com.
But, for the list, you would need to repeat the search for each one.
We often do this in a bash script.
Can you use a filter to identify which DNs you need?
-jim

Seems like it is only possible in Active Directory. All I had to do is filter by the distinguishedName attribute, however on my tests there was no performance gain.
Active Directory includes the distinguishedName attribute on every
object; the value is the object's DN. The following example elaborates
the previous example to include a value of distinguishedName on each
object.
http://msdn.microsoft.com/en-us/library/cc223167.aspx

Related

Deleting a front door backend by address, not index

Using the Azure CLI, I would like to remove a series of backends from a Front Door backend pool based on their address. But from what I can tell you need to know the position of the backends in the list (the index) rather than pick from the address.
I am using az network front-door backend-pool backend list to get the list of backends, the response does not provide an index to use.
Can I remove a backend by the address, or some other identifier, rather than an index?
If I am forced to delete by index:
If I list the backends multiple times, can I be guaranteed that they always come back in the same order?
If I add a new backend to the pool, is it always the last in the list, and therefore the highest index?
If I delete the first backend (index = 1), does that index get replaced with the next in the list?
Azure CLI only provides a way with an index to remove a backend. But you can use the command below to get the index of a backend that you want to remove by its address:
backends=$(az network front-door backend-pool backend list --resource-group <resource group name> --front-door-name <front door name> --pool-name <pool name>)
echo $backends |jq
echo $backends | jq '[ .[] | .address == "stantest1016.blob.core.windows.net" ] | index(true) +1'
Result:
It is recommended that query backend list to get the latest list after add/remove backends.

Azure Datafactory process and filter files to process

I have a pipeline that processes some files, and in some cases "groups" of files. Meaning the files should be processed together and are correlated with a timestamp.
Ex.
Timestamp#Customer.csv
Timestamp#Customer_Offices.csv
Timestamp_1#Customer.csv
Timestamp_1#Customer_Offices.csv
...
I have a table with all the scopes, and files with respective filemask. I have populated a variable in the beginning of the pipeline based on a parameter
The Get files activity goes to a sFTP location and grab files from a folder. Then I only want to process the "Customer.csv" and ".Customer_Offices.csv" files. This is because the folder location has more file types or scopes to be processed by other pipelines. If I don't filter, the next activities end up by processing metadata of files that are not supposed to. In terms of efficiency and performance s bad, and is even causing some issues with files being left behind.
I've tried something like
#variables('FilesToSearch').contains(#endswith(item().name, 'do I need this 2nd parm in arrays ?'))
but no luck... :(
Any help will be highly appreciated,
Best regards,
Manuel
contains function can direct for a string to find a substring, so you can try something like this expression #contains(item().name,'Customer')
and no need to create a variable.
Or use endsWith function and use this expression:
#or(endswith(item().name,'Customer.csv'),endswith(item().name,'Customer_Offices.csv'))

How to replace a character by another in a variable

I want to know if there is a way to replace a character by another in a variable. For example replacing every dots with underscores in a string variable.
I haven't tried it, but based on the Variables specification, the way I'd try to approach this would be to try to match on the text before and after a dot, and then make new variables based on the matches. Something like:
set "value" "abc.def";
if string :matches "${value}" "*.*" {
set "newvalue" "${1}_${2}
}
This will, of course, only match on a single period because Sieve doesn't include any looping structures. While there's a regex match option, I'm not aware of any regex replacement Sieve extensions.
Another approach to complex mail filtering you can do with Dovecot (if you do need loops and have full access to the mail server) is their Dovecot-specific extensions like vnd.dovecot.pipe which allows the mail administrator to define full programs (written in whatever language one wishes) to process mail on its way through.
Following #BluE's comment, if your use case is to store e-mails in folders per recipient address or something like that, perhaps you don't actually want a generic character replace function but some way to create mailboxes with dots in their names. In the case of dovecot, there seem to be a solution: [Dovecot] . (dot) in maildir folder names
https://wiki2.dovecot.org/Plugins/Listescape
Ensure one of the files in /etc/dovecot/conf.d contains this line:
mail_plugins = listescape
Then you can filter mailing lists into separate boxes based on their IDs.
This Sieve script snippet picks the ID from the x-list-id header:
if exists "x-list-id" {
if header :regex "x-list-id" "<([\.#a-z_0-9-]+)" {
set :lower "listname" "${1}";
fileinto :create "mailing_list\\${listname}";
} else {
keep;
}
stop;
}

How does one use "gcloud compute operations list" with a filter by instance name?

The root problem is that I have a project that has many tens of thousands of operations, such that it's very difficult to track down operations associated with specific instances being created or deleted. So, I'm looking for a way to list operations by target.
The deprecated gcutil docs talk about setting filter expressions to possibly filter operations by target instance name or instance selfLink, but there doesn't seem to be any mention of a similar filter expression in gcloud compute operations list described here:
gcloud compute operations list [NAME …] [--format FORMAT] [--help] [--limit LIMIT] [--log-http] [--project PROJECT_ID] [--quiet, -q] [--regexp REGEXP, -r REGEXP] [--sort-by SORT_BY] [--trace-token TRACE_TOKEN] [--uri] [--global | --regions [REGION,…] | --zones [ZONE,…]] [-h]
The only non-global flags listed there are the following:
--global
If provided, only global resources are shown.
--limit LIMIT
The maximum number of results.
--regexp REGEXP, -r REGEXP
A regular expression to filter the names of the results on. Any names that do not match the entire regular expression will be filtered out.
--regions [REGION,…]
If provided, only regional resources are shown. If arguments are provided, only resources from the given regions are shown.
--sort-by SORT_BY
A field to sort by. To perform a descending-order sort, prefix the value of this flag with a tilde (~).
--uri
If provided, the list command will only print URIs for the resources returned. If this flag is not provided, the list command will print a human-readable table of useful resource data.
--zones [ZONE,…]
If provided, only zonal resources are shown. If arguments are provided, only resources from the given zones are shown.
Furthermore, the examples given by the gcutil docs don't seem to work:
$ gcutil listoperations --zone us-east1-a --filter="target eq '.*dhuo.*'"
WARNING: 'gcutil' has been deprecated and soon will be removed from Cloud SDK distribution.
WARNING: Please use 'gcloud compute' instead.
WARNING: For more information see https://cloud.google.com/compute/docs/gcutil
Error: Invalid value for field 'filter': 'target eq '.*dhuo.*''. Unrecognized field name in list filter: target.
That's despite the raw API docs describing 'target' as an example here:
Filter expression for filtering listed resources, in the form filter={expression}. Your {expression} must contain the following:
FIELD_NAME COMPARISON_STRING LITERAL_STRING
FIELD_NAME: The name of the field you want to compare. The field name must be valid for the type of resource being filtered. Only atomic field types are supported (string, number, boolean). Array and object fields are not currently supported. For example, if you search for machineType in the Firewalls collection, the filter will fail, because the machineType field is specific to instances and other resources do not have that property.
COMPARISON_STRING: The comparison string, either eq (equals) or ne (not equals).
LITERAL_STRING: The literal string value to filter to. The literal value must be valid for the type of field (string, number, boolean). For string fields, the literal value is interpreted as a regular expression using RE2 syntax. The literal value must match the entire field. For example, when filtering instances by name, name eq my-instance won't work, but name eq .*my-instance will work.
For example, for Operation resources, you could filter by the type of the operation:
filter=operationType ne insert
The above filter returns only results whose type field does not equal insert. You can also enclose your literal string in single, double, or no quotes. For example, all three of the following would be valid expressions:
filter=operationType ne "insert"
filter=operationType ne 'insert'
filter=operationType ne insert
If you use a complex regular expression, you need to encode the special characters, including quotes. Consider the following regular expression:
target eq 'example-name-[0-9]+'
To use the expression, you would need to encode it:
filter=target+eq+%27example-name-%5B0-9%5D%2B%27
If you are using the API through a client, such as client libraries, or gcloud compute, keep in mind that your client might encode your regular expression automatically so that you will not need to encode it yourself.
Is there something I'm doing wrong, and is it indeed possible to filter zone operations based on the name of the instance I'm trying to insert?
I'm not sure how to do it using gcloud, but you can still use gcutil:
gcutil listoperations --zone us-east1-a --filter="targetLink eq '.*dhuo.*'"
So it is almost the same as your, but should use 'targetLink' instead of 'target'.
You could also do something like this if you wanted to use gcloud and search specifically for the target:
$ gcloud compute operations list | awk '$3 ~ /dhuo\./ {print $0}'

Requesting nodes by numbers and their names in SGE

How to request the number of nodes (not procs), while job submission in SGE?
for e.g. In TORQUE, we can specify qsub -l nodes=3
How to request the nodes by their names in SGE?
for e.g. In TORQUE, we can do this by qsub -l nodes=abc+xyz+pqr, where abc, xyz and pqr are hostnames
For single hostname, qsub -l hostname=abc it works. But how do I delimit multiple hostnames in SGE?
Requesting the number of nodes with Grid Engine is done indirectly.
When you want to submit a parallel job then you have to request
a parallel environment (man sge_pe) together with the amount
of slots (processors etc) like qsub -pe mytestpe 12...
Depending on the allocation_rule defined in the parallel environment
(qconf -sp mytestpe) the slots are distributed over one or more
nodes. If you have a so called fixed allocation rule where you
just add a certain number as allocation rule like 4 (4 slots per
host) it is easy. If you like one host just submit with -pe mytestpe 4
if you want 10 nodes just submit with -pe mytestpe 40.
Node name can be requested by the -l h=abc. Since node names are
RESTRINGS (regular expression strings) in Grid Engine you can create
a regular expression for host filtering: qsub -l h="abc|xyz".
You can also create host groups (qconf -ahgrp) and request
so called queue domains (qsub -q all.q##mygroup).
Daniel
http://www.gridengine.eu
you can use -tc to limit the number of concurrent tasks (i.e., number of slots that will be used for an array job). I use this when I submit array jobs with 100 sub-jobs to limit the impact on our queue, defaulting to 10 simultaneous jobs with -tc 10. As each job finishes, another array job from the pending pool will be submitted.
the only way I've been able to figure out to do this would be to set up specific resource quota sets (using qconf -mrqs) specifying the particular host groups you want to use. You would have to set up all of the combinations that you want, first. I don't see a real reason to specify specific hosts, though, unless these hosts have specific resources that you want to use (in which case, I'd set up consumable resources for those and apply the appropriate number of resources to each host that can supply them, then use that instead of specifying the specific hosts for a particular job).