Microsoft Graph - Delete Access Package Assignment - javascript

I'm using Microsoft Graph API Beta version to delete an access package. However, for deleting an access package, I need first to remove all its assignments.
For doing this, I found on the official doc the accessPackageAssignment object (https://learn.microsoft.com/en-us/graph/api/resources/accesspackageassignment?view=graph-rest-beta).
When I perform a get request on the assignment:
result = azureAdBeta.get('/identityGovernance/entitlementManagement/accessPackageAssignments/' + accessPackageAssignmentId)
the response is successful:
{'#odata.context': 'https://graph.microsoft.com/beta/$metadata#identityGovernance/entitlementManagement/accessPackageAssignments/$entity',
'accessPackageId': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'assignmentPolicyId': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'assignmentState': 'Delivered',
'assignmentStatus': 'Delivered',
'catalogId': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'expiredDateTime': None,
'id': '2ad2eb61-9baa-45b9-a700-bfef425d7aef',
'isExtended': False,
'schedule': {'expiration': {'duration': None,
'endDateTime': '2022-01-20T23:00:00Z',
'type': 'afterDateTime'},
'recurrence': None,
'startDateTime': '2021-12-15T11:16:04.663Z'},
'targetId': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'}
However, when I perform a delete request:
result = azureAdBeta.delete('/identityGovernance/entitlementManagement/accessPackageAssignments/' + accessPackageAssignmentId)
I get the following error:
{'error': {'code': '',
'innerError': {'client-request-id': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'date': '2021-12-15T11:32:37',
'request-id': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'},
'message': 'No HTTP resource was found that matches the request URI '
"'https://igaelm-asev3-ecapi-neu.igaelm-asev3-environment-neu.p.azurewebsites.net/api/v1/accessPackageAssignments('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')'."}}
I suppose this error is due to fact that in doc no delete method is mentioned for the accessPackageAssignment object.
So how can I delete an access package assignment via Microsoft Graph?

• You can remove an Access package assignment through Microsoft graph powershell module in the following way: -
First view all the access package assignments through the below powershell command -
‘ Connect-MgGraph -Scopes "EntitlementManagement.Read.All"
Select-MgProfile -Name "beta"
$accesspackage = Get-MgEntitlementManagementAccessPackage -DisplayNameEq "Marketing Campaign"
$assignments = Get-MgEntitlementManagementAccessPackageAssignment -AccessPackageId $accesspackage.Id -ExpandProperty target -All -ErrorAction Stop
$assignments | ft Id,AssignmentState,TargetId,{$_.Target.DisplayName} ’
The above command will display all the assignments for the access package as stated above which correspond to the stated display name. Once, all the access package assignments for the stated access package are displayed, execute the below command to remove the access package assignment for the concerned access package by entering the correct access packageID. Also, enter the correct targetID(objectID of the user/group/resource) of the assignment to be removed.
‘ Connect-MgGraph -Scopes "EntitlementManagement.ReadWrite.All"
Select-MgProfile -Name "beta"
$assignments = Get-MgEntitlementManagementAccessPackageAssignment -Filter
"accessPackageId eq '9f573551-f8e2-48f4-bf48-06efbb37c7b8' and
assignmentState eq 'Delivered'" -All -ErrorAction Stop
$toRemove = $assignments | Where-Object {$_.targetId -eq '76fd6e6a-c390-
42f0-879e-93ca093321e7'}
$req = New-MgEntitlementManagementAccessPackageAssignmentRequest -
AccessPackageAssignmentId $toRemove.Id -RequestType "AdminRemove" ’
This will remove the access package assignment for the concerned access package.
Note: - You will have to install the Microsoft Graph Identity Governance module in powershell for executing the above commands. To install the module, please run this command in elevated powershell – ‘Install-Module -Name Microsoft.Graph.Identity.Governance’
Also, you can remove the access package assignment through Microsoft Graph from an application JSON file. To do so, refer the following link and replace the value of "requestType": "AdminAdd" to "requestType": "AdminRemove"
https://learn.microsoft.com/en-us/graph/api/accesspackageassignmentrequest-post?view=graph-rest-beta&preserve-view=true&tabs=http#request
Please refer the below link also for reference: -
https://learn.microsoft.com/en-us/azure/active-directory/governance/entitlement-management-access-package-assignments#remove-an-assignment-programmatically

Related

Serum Error What is "Unable to simulate swap"?

I would like to swap using project-serum/serum-ts.
I prepared the following while reading readme.MD.
Use the latest version of Yarn etc.
Install the dependent modules according to readme.MD
Prepare the id.json file containing the wallet secret in ./config/solana/id.json
Put 0.01 SOL in the wallet on mainnet-beta.
After that, I tried to run node ./package/swap/example/swap.js, which is prepared for the sample.
This file -> https://github.com/project-serum/serum-ts/blob/master/packages/swap/examples/swap.js
I confirmed that it worked until line 26 _srmSwapPairs.
However, at line 29, I get the following error
Error: Unable to simulate swap
at Swap.estimate (/mnt/c/Users/username/Desktop/solana_test/serum-ts/packages/swap/lib/index.js:401:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async main (/mnt/c/Users/username/Desktop/solana_test/serum-ts/packages/swap/examples/swap.js:29:25)
My OS is Windows 10, but I am using WSL.
What could be the cause?
This is most likely failing because you're trying to simulate a swap from SRM to USDC on your wallet, but your wallet doesn't have enough SRM to complete the trade, or doesn't have the accounts to conduct the trade.
To learn more about the issue, you can hack the code to print out more information about the failure:
const resp = await this.program.provider.simulate(
tx,
signers,
params.options,
);
if (resp === undefined || resp.value.err || !resp.value.logs) {
console.error(resp); // get more information about the error
throw new Error('Unable to simulate swap');
}
You can make the changes at https://github.com/project-serum/serum-ts/blob/93946077cbacc4149a3372d9e6651bf4de18a255/packages/swap/src/index.ts#L535

How to properly configure MAIL_URL?

The follwoing smtp url giving me an error
process.env.MAIL_URL="smtp://mail_name#outlook.com:Password#smtp.outlook.com:457";
What am I doing wrong?
For starters, your issue is that your user name (and perhaps your password) contain a character that cannot be placed in a URL as-is, and therefore needs to be encoded.
I want to take this opportunity to provide a little more in-depth answer to the issue of configuring the MAIL_URL environment variable.
If you simply need a quick string that will work, do:
process.env.MAIL_URL="smtp://"+encodeURIComponent("mail_name#outlook.com")+":"+encodeURIComponent("Password")+"#smtp.outlook.com:457";
Also take into account that you may need to use smtps for secure connection, and if it uses TLS, your connection may fail.
I recommend to read the rest if you need anything more robust.
URL
A URL has the following structure:
scheme:[//[user[:password]#]host[:port]][/path][?query][#fragment]
The scheme would be either smtp or smtps (for secure connection), and in this scenario you will also set the user, password, host and (most likely) port.
Each of the parts needs to be encoded in a way that is suitable for use in a URL, but since hosts (domains) are normally already appropriate, you only need to make sure that your user name/password are encoded.
In EcmaScript, encodeURIComponent can be used for this.
MAIL_URL and node environment variables
Meteor checks the value of process.env.MAIL_URL when sending an email.
process.env is populated by node.js with the environment variables available to it on startup.
It is possible to add properties to it on runtime, so setting process.env.MAIL_URL before sending an email will work. However, you should do so wisely to prevent your secrets from leaking.
I would suggest 2 methods for setting it up, either using settings.json or using the environment variable itself.
using settings.json
Create a json file in your project. It is highly recommended not to commit it into source control with the rest of your code.
for example: config/development/settings.json
{
"smtp": {
"isSecure": true,
"userName": "your_username",
"password": "your_password",
"host": "smtp.gmail.com",
"port": 465
}
}
And somewhere in your server code:
Meteor.startup(function() {
if (Meteor.settings && Meteor.settings.smtp) {
const { userName, password, host, port, isSecure } = Meteor.settings.smtp;
const scheme = isSecure ? 'smtps' : 'smtp';
process.env.MAIL_URL = `${scheme}://${encodeURIComponent(userName)}:${encodeURIComponent(password)}#${host}:${port}`;
}
});
Then you can run Meteor with the --settings switch.
meteor run --settings config/development/settings.json
using an environment variable
You can set the environment variable to the encoded string. If you want a utility script (for zsh on *nix) that will convert it (depends on node):
mail_url.sh
#!/bin/zsh
alias urlencode='node -e "console.log(encodeURIComponent(process.argv[1]))"'
ENC_USER=`urlencode $2`
ENC_PASS=`urlencode $3`
MAIL_URL="$1://$ENC_USER:$ENC_PASS#$4"
echo $MAIL_URL
which can be used as follows:
$ chmod +x mail_url.sh
$ MAIL_SCHEME=smtps
$ MAIL_USER=foo#bar.baz
$ MAIL_PASSWORD=p#$$w0rd
$ MAIL_HOST=smtp.gmail.com:465
$ export MAIL_URL=$(./mail_url.sh $MAIL_SCHEME $MAIL_USER $MAIL_PASSWORD $MAIL_HOST)
$ echo $MAIL_URL
smtps://foo%40bar.baz:p%4015766w0rd#smtp.gmail.com:465

Commander.js display help when called with no commands

I'm using commander.js to write a simple node.js program that interacts with an API. All calls require the use of subcommands. For example:
apicommand get
Is called as follows:
program
.version('1.0.0')
.command('get [accountId]')
.description('retrieves account info for the specified account')
.option('-v, --verbose', 'display extended logging information')
.action(getAccount);
What I want to do now is display a default message when apicommand is called without any subcommands. Just like when you call git without a subcommand:
MacBook-Air:Desktop username$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
...
You can do something like this by checking what arguments were received and if nothing other than node and <app>.js then display the help text.
program
.version('1.0.0')
.command('get [accountId]')
.description('retrieves account info for the specified account')
.option('-v, --verbose', 'display extended logging information')
.action(getAccount)
.parse(process.argv)
if (process.argv.length < 3) {
program.help()
}
When you're trying to pass a command, it stores the commands in process.argv array.
You can add a conditon like at the end of your code like -:
if(process.argv.length <= 2)
console.log(program.help());
else
program.parse();
What I want to do now is display a default message when apicommand is called without any subcommands. Just like when you call git without a subcommand
The help is automatically displayed from Commander 5 onwards if you call without a subcommand.
(Disclosure: I am a maintainer of Commander.)

how to read terminal input in node.js?

I want to do some local node test before push the code to server.
how can I read terminal input as a input for my js script?
readline or something
I think there is no need to use third party library, if you just want to get command line params.
You can use process.argv property of process node core object.
just use process.argv & you are good to go.It returns an array in which by default there is 2 element, at 0 index Node execution directory & at 1 index working directory, so cmd line params start from 2nd index.
So in nutshell, you can access cmd line params using process.argv[2] onwards.
For commandline app you can use nicl. you can make call to your chat module or websocket or whatever based on your logic.
var nicl = require("nicl");
function main() {
nicl.printLine("Hello, what is your name?");
var name = nicl.readLine();
//call to websocket or any chat module
nicl.printLine("Great to meet you, " + name + "!");
process.exit(0);
}
nicl.run(main);

Elastic search and Firebase: Result limit change and weird query results

I have setup an elastic search instant, created a Firebase project and run flashlight on my localhost. When I query the Firebase database in the default path (search/request) I get 10 results created in the search/response path in my database instance on Firebase.
Can someone more experienced on this please explain:
How can I change the result limit to more than 10 results on Firebase?
(I tried tinkering with SearchQueue.jsusing the code in the bottom but i didn't manage to make it work.
Why the search results when the queries are performed without specifying index and type return the total number of entries on elastic server and therefore irrelevant results on Firebase?
I used postman for the ReST calls (PUT) on firebase and the JSON content was sent over to /search/request/
This json content worked in terms of results:
{ "index": "chatmessages", "type": "chat", "query": "georgebest"}
but this one did not:
{"query": "georgebest"}
Both returned a Status: 200 OK .
Let me add that using Sense and running the same query the results are totally correct. The issue occurs when flashlight is used.
Please note that I don't use any rules and I left the Firebase database open for testing purposes.
Let me know if any additional information is required..Thanks.
code snippet for 1):
SearchQueue.prototype = {
_process: function(snap) {
var dat = snap.val();
var key = snap.key;
if (this._assertValidSearch(key, dat)) {
// Perform (a very simple) ElasticSearch query
var searchProps = {
index: dat.index,
type: dat.type,
//added variables
size : dat.size,
from : dat.from
};
It looks like you were running into a bug fixed in the 0.2.0 release.
Note that in the latest release query was replaced by q or body to be inline with ES. (query still works for now)
A more useful sample is now included in the doc here.
{
"from" : 0,
"size" : 50,
"body": {
"query": {
"match": {
"_all": "foo"
}
}
}
}
Using q for the sql lite format also works:
{
"from" : 0,
"size" : 50,
"q": "foo"
}
I found out what was causing the issues in my case (probably also caused via some other means as Kato suggested above).
For the first issue:
I was running a previous version of node.js in my system and what I did was to update the node.js to version 6.9.1 and then upgrade npm to version 4.0.2 (using npm install npm#latest -g ) afterwards I reinstated all the required node_modules (npm install --save firebase and npm install --save elasticsearch) and voila! it worked!
The code I used for the size and from variables:
SearchQueue.prototype = {
_process: function(snap) {
var dat = snap.val();
var key = snap.key;
if (this._assertValidSearch(key, dat)) {
// Perform (a very simple) ElasticSearch query
var searchProps = {
index: dat.index,
type: dat.type,
//added variables
size : dat.size,
from : dat.from,
};
The content of the json file :
{ "index":"chatmessages","type" : "chat", "query":"some_query", "from":"0", "size":"20"}
For the second issue:
The results were not passing correctly to elastic server, returning "undefined" and a hit number of all results stored.
I used postman to send the JSON in the following URL firebase_address/search/request/some_object.json
but just for reference if you want to do it manually in firebase, you should create something like this:
Of course the way to go from here is with the latest version as suggested above!

Categories