how openstacksdk change current user password - passwords

I found the CLI or API request methods and they work for me, like this:
# source /etc/kolla/admin-openrc.sh
# openstack user password set --password newpsw --original-password oripsw
Or
# source /etc/kolla/admin-openrc.sh
# curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog \
-H "Content-Type: application/json" \
-d '{ "auth": { "identity": { "methods": ["password"], \
"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"}, \
"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } }, \
"scope": { "project": { "domain": { "name": "'"$OS_PROJECT_DOMAIN_NAME"'" }, \
"name": "'"$OS_PROJECT_NAME"'" } } }}'
< HTTP/1.1 201 CREATED
< Date: Mon, 18 Oct 2021 11:44:39 GMT
< Server: Apache
< Content-Length: 720
< X-Subject-Token: gAAAAABhbV4o9WvatToB4Z7dUhaNqyYqpwUt4T3wwOmnN2-YCioaSYZ-HpqdWNDvAq0pvnSe6qIuvoZXOIUjmxxUu03tWk2mp2TOJ_LTLECXOHqlQT22vqNvgJj_YTgOWbwHVlrrqbkcUWM4WDvbsD1HjM8xiEYidSNMzpw2LOHtO43cIN0nyvs
< Vary: X-Auth-Token
# export OS_TOKEN=gAAAAABhbV4o9WvatToB4Z7dUhaNqyYqpwUt4T3wwOmnN2-YCioaSYZ-HpqdWNDvAq0pvnSe6qIuvoZXOIUjmxxUu03tWk2mp2TOJ_LTLECXOHqlQT22vqNvgJj_YTgOWbwHVlrrqbkcUWM4WDvbsD1HjM8xiEYidSNMzpw2LOHtO43cIN0nyvs
# curl --header "Content-Type: application/json" --request POST --data '{"user":{"password":"123","original_password":"aaa"}}' http://10.32.17.172:5000/v3/users/e1c5cc75489f4e0cbb05c39d03b46097/password
The Change password for user method at the last of API request documentation.
But I need to achieve that by using openstacksdk in our project, I found the last method in the openstacksdk documentation -- update_user(user, **attrs), it seems the most like I look for. Unfortunately, the openstack.identity.v3.user instance doesn't have the original_password, and my code can't work:
import openstack
conn = openstack.connect(
region_name = 'RegionOne',
auth_url = 'http://10.32.17.172:35357/v3',
domain_name = 'Default',
project_name = 'admin',
username = 'admin',
password = '123'
)
user_args = {
"name":"admin",
"pasword":'aaa', # new password
"password_expires_at":None,
"links":{u'self': u'http://10.32.17.172:5000/v3/users/e1c5cc75489f4e0cbb05c39d03b46097'},
"enabled":True,
"domain_id":"default",
"original_password": "123",
}
conn.identity.update_user(user_args)
How could I implement change current user passord by openstacksdk? Thanks advance.

Solve by this:
import openstack
conn = openstack.connect(
...
)
user_args = {
"id":"e1c5cc75489f4e0cbb05c39d03b46097"
}
user = conn.identity.get_user(user_args)
user.description = "test_update_psw"
user.password="123456"
conn.identity.update_user(user)
Update the user's info should use the user object instead of the dictionary like the question's code.
Shame of my bad program language skill and lack of API documentation knowledge.
And thank you very very much for one people who called tanjin.

Related

how to set no-cache header in akka http httpRequest using request level client

i have a curl request like this
curl -X POST \
http://0.0.0.0:8080/auth/realms/nestle/authz/protection/uma-policy/b952ad68-d23b-46ab-a456-b8598f4ffb28 \
-H 'Authorization: Bearer '{token} \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"name": "Any people manager",
"description": "Allow access to any people manager",
"scopes": ["read-private"],
"roles": ["manager"]
}'
i want to convert it into the httpRequest
for that i am doing something like this
val uri: String = "http://0.0.0.0:8080/auth/realms/nestle/authz/protection/uma-policy/"+resourceID
val authorization = headers.Authorization(OAuth2BearerToken(pat))
val uri: String = "http://0.0.0.0:8080/auth/realms/nestle/authz/protection/uma-policy/" + resourceID
val authorization = headers.Authorization(OAuth2BearerToken(pat))
val jsonStr =
"""{
| "name": "Any people event-manager 2",
| "description": "Allow access to any people event manager",
| "scopes": ["read-private"],
| "roles": ["manager","interpret/event_manager"]
| }"""
val request = HttpRequest(HttpMethods.POST, uri, List(authorization), HttpEntity(ContentTypes.`application/json`, jsonStr.stripMargin.parseJson.toString()))
how can i set -H 'Cache-Control: no-cache' \ in the above code ?
-H 'Cache-Control: no-cache' is a header , so it should be in the 3rd parameter of HttpRequest
final class HttpRequest(
val method: HttpMethod,
val uri: Uri,
val headers: immutable.Seq[HttpHeader],
val entity: RequestEntity,
val protocol: HttpProtocol)
Try something like
val request = HttpRequest(
HttpMethods.POST,
uri,
List(authorization, `Cache-Control`(`no-cache`)),
HttpEntity(ContentTypes.`application/json`, jsonStr.stripMargin.parseJson.toString())
)

How do you specify the sourceBranch for a Run of Pipelines via the REST API?

I've been trying to run a pipeline for a particular branch of the repository I'm using.
In the UI, there is a convenient option, but I don't understand what to try in the request.
No matter what I do I always run from master.
How do I change that? I tried filling out the repository parameters but to no avail: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0#repositoryresourceparameters
Here is an example request:
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"previewRun": true,
"resources": {
"repositories": {
"refName": "refs/heads/<redacted>"
}
},
"runParameters":
{
"namespace" : "<redacted>",
"image" : "<redacted>",
"tag" : "<redacted>",
"package" : "<redacted>",
"version" : "8.4.4"
}
}'
From your screenshot, it seems that you are using the YAML pipeline.
I have tested your example , and the root cause of this issue is that the request body(data-raw) has some issues.
You could try my sample
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"stagesToSkip":[],
"resources":
{
"repositories":
{
"self":{"refName":"refs/heads/{Branchname}"}
}
},
"templateParameters":
{
"namespace":"{value}",
"image":"{value}",
"tag":"{value}",
"package":"{value}",
"version":"{value}"
},
"variables":{}
}'
Result:
For Http Request (you can test it with Postman)
1. Get pipeline api url like this
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1
Source: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1
Fill in your organization, project and pipelineId.
(all of this can be found in the link when you open your pipeline definition in Azure DevOps)
2. Add Basic Auth headers
key: Authorization, value:"Basic [your azure Person Access Token from Azure Dev Ops with Access to Pipeline goes here]"
Should look like this
"Basic OndzNWdz43FKfjdi98hjKDJFH8kkg9854HJKHF9D8RFEHui4387lkNXE="
And set content type to application/json
like this
key: Content-Type, value: application/json
3. Put this JSON Into Raw Body
{
"templateParameters":{
"inputName":"johnsmith"
},
"resources":{
"repositories":{
"self":{
"refName":"refs/heads/feature/#JIRATask01_Blabla"
}
}
},
"variables":{
}
}
Replace refName value with branch you want to run the pipeline for.
If you have multiple repo pipeline look into this topic (but i haven't tested that solution):
Azure DevOps API to Trigger Multi Repo changing branches

How to include my user as a member in a Group type identity in Sandbox?

In Sandbox, the logged-in user needs to be a member of a group to register data products or apps.
How can I add my user to a group?
You, as user, are an identity of type Person. A Group is also a type of identity in Platform of Trust.
A Person must be linked to a Group with MemberOf type of link.
Using Identity API, you can create a Group type identity and connect your own user identity to the group with a MemberOf type link.
To create a group, run the following cURL command:
curl -i -X POST \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9eyJzY29w...DVs5aaf" \
-H "Content-Type: application/json" \
-d \
"{
"context": "https://standards.oftrust.net/v2/Context/Identity/Group/",
"type": "Group",
"data": {
"name": "Company Oy"
}
}" "https://api-sandbox.oftrust.net/identities/v1"
On Success, you'll get the following response including the ID of the created group.
Next, you need to link your user identity to the created group identity with a MemberOf type link.
option1: This post in StackOverflow discusses how to obtain the current logged-in user's ID.
OR,
option2:
Start with getting your user ID (you need to be logged-in into the Sandbox) using /me end
point of Login API
Request:
curl -i -X GET \
-H "Authorization: Bearer eyJ0eXAi...hdEsJLNGV2YA" \
"https://api-sandbox.oftrust.net/me"
Response:
HTTP/1.0 200
{
"#context": "https://standards.oftrust.net/v2/Context/Identity/LegalParty/Person/",
"#type": "Person",
"#id": "33237067-14c3-4801-9e50-bf08406406e2",
"email": "user#example.com",
"role": "developer",
"firstName": "Anna",
"lastName": "Bar"
}
Then make a POST request to Identity API with Identity IDs of your user and the created group as parameters:
curl -i --request POST \
--url https://api-sandbox.oftrust.net/identities/v1/{fromIdentityId}/link/{toIdentityId} \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9eyJzY29w...DVs5aaf' \
--header 'content-type: application/json' \
--data '{
"context": "https://standards.oftrust.net/v2/Context/Link/Role/MemberOf/",
"type": "MemberOf"
}'
Remember to set the parameters as the following:
fromIdentityId = ID of your own user
toIdentityID = ID of the created group above.
On success, you should receive the following response:
HTTP/1.0 201
{
"#context": "https://standards.oftrust.net/v2/Context/Link/Role/MemberOf/",
"#type": "MemberOf",
"#id": "be7a2c57-03d8-46f4-aaf0-2b1ca118ef5c",
"from": "8ac7494b-b7bc-4a63-a253-4b9b1887b262",
"to": "a6b5a74e-bd98-4c9b-9561-932877258833",
"data": {},
"metadata": {
"createdAt": "2019-09-12T09:49:24+00:00",
"createdBy": "33237067-e72c-4f26-b78b-9f9e234b2e7d",
"updatedAt": "2019-09-12T09:49:24+00:00",
"updatedBy": "33237067-e72c-4f26-b78b-9f9e234b2e7d"
}
}
Now you will bee able to use the created group to register data products and apps in Platform of Trust.
Alternatively, you can use world-sandbox.oftrust.net to create your group identity using the UI. Simply save the group ID that appears in the S-alert.
Checkout Identity API documentation here.
You can also use our Insomnia Workspace and Guide to execute chain request to create a Group.

how to add `maximumBillingTier` to query

here is is in the docs, but where do I add it to the query?
curl -X POST \
-H "Authorization: Bearer <your_oauth2_token>" -H "Content-Length: 8" \
-H "Content-Type: application/json" \
'https://www.googleapis.com/bigquery/v2/projects/my-project/queries' \
-d "{
timeoutMs: 600000,
queryParameters: [],
query:
'SELECT * FROM [my-project:Views.TEST_11]',
maxResults: 0,
kind: 'bigquery#queryRequest'
}
"
is it part of the body?
-d "{
...
..
maximumBillingTier: '2',
"
it does not seem to be part of the QueryRequest body
You are trying to use jobs.query API; however, this uses the object QueryRequest which doesn't have the maximumBillingTier option, to use this option you should to use the jobs.insert API instead.
The body for jobs.insert should look like this:
{
"configuration": {
"query": {
"query": "Select * from mydataset.mytable",
"maximumBillingTier": 1
}
}
}

Segment.io HTTP API not collecting events

The documentation and help for this particular Segment.io is limited and sparse, so I hope it's OK to ask in here.
I have just set up a Segment.io workspace and a HTTP API source
Per the docs, I sent some POST requests (with Postman) to the https://api.segment.io/v1/track and https://api.segment.io/v1/page endpoints. The requests were structured like this:
curl -X POST \
https://api.segment.io/v1/track \
-H 'Accept: */*' \
-H 'Authorization: My4w3s0m3k3y' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Host: api.segment.io' \
-H 'Postman-Token: 474d7fbe-15af-43d2-b629-61e15945e662,2c3d5fbe-2c09-4fe6-b7ea-a04e3221201b' \
-H 'User-Agent: PostmanRuntime/7.11.0' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 117' \
-d '{
"userId": "abc123",
"event": "My tests",
"properties": {
"name": "test 1"
}
}'
which all returned a 200 response and the following message:
{
"success": true
}
However, when I got to my dashboard, no events have been recorded.
The debugger is also empty
What am I missing here?
It looks like your write key isn't base64 encoded. When you encode your write key, remember to add the : at the end of it, before it's encoded.
Also, for the Authorization key:value, be sure to add Basic before the encoded write key. So your Authorization key:value would look like:
Authorization: Basic {encoded write key}
An example from the segment documentation:
In practice that means taking a Segment source Write Key,'abc123', as the username, adding a colon, and then the password field is left empty. After base64 encoding 'abc123:' becomes 'YWJjMTIzOg=='; and this is passed in the authorization header like so: 'Authorization: Basic YWJjMTIzOg=='.
I have been dealing with the same issue.
I found the solution as Todd said.
You should add a header Authorization: Basic + base64 encoding write key.
So, you look for the Segment source setting and get the write key.
After that, i have used an online base64 encoding tool to encode my write key.
Finally, you should add this header (Authorization) with 'Basic' and the encoded write key.
You should be able to see the tracked event in the Debugging panel in Segment web page.
I hope this helps!
You can try this code
const { promisify } = require("util");
var Analytics = require("analytics-node");
var analytics = new Analytics("xxxxxxxxxxxxxxxxxxxxxxx", {
flushAt: 1,
});
const [identify, track] = [
analytics.identify.bind(analytics),
analytics.track.bind(analytics),
].map(promisify);
console.log("user id: ", req.body.event.app_user_id);
let app_user_id = req.body.event.app_user_id;
let period_type = req.body.event.period_type;
let expiration_at_ms = req.body.event.expiration_at_ms;
let ret = "Initial";
try {
await identify({
userId: app_user_id,
traits: {
period_type: period_type,
expiration_at_ms: expiration_at_ms,
},
});
ret = "Done : Sengment done";
} catch (err) {
console.log("err: ", err);
ret = "Error : " + err;
}
return {
rafsan: ret,
};
Try to clear your browser's cache or use a different browser. I had the same problem and worked for me.
Hope this helps.