Add an API to a specific project inside a SwaggerHub organisation - swaggerhub

It's easy to upload an API to an organisation via SwaggerHub CLI:
swaggerhub api:create OWNER/API_NAME/[VERSION]
But I need to upload an API under some project inside an organisation.
In all examples from https://github.com/SmartBear/swaggerhub-cli
there is no "project" variable.

SwaggerHub CLI does not support projects yet. There's an existing feature request for that.
You can, however, use SwaggerHub Registry API to add your uploaded API to a specific project.
curl -X PUT https://api.swaggerhub.com/projects/ORG_NAME/PROJECT_NAME/apis/API_NAME -H "Authorization: YOUR_API_KEY"
If you use self-hosted SwaggerHub On-Premise, the request would be as follows and requires v. 1.26 or later. Add the -k flag if your instance uses a self-signed or privately signed certificate.
curl -X PUT http(s)://YOUR_SERVER/v1/projects/ORG_NAME/PROJECT_NAME/apis/API_NAME -H "Authorization: YOUR_API_KEY"

Related

Unable to use Chrome Web Store Publish API due to force 2-Factor verification

Until recently I have been releasing Chrome Extension using Chrome Web Store Publish API. (Automated release process)
const response = execSync(`\
curl -X PUT -F 'data=#${process.env.ZIP_FILE}' https://www.googleapis.com/upload/chromewebstore/v1.1/items/${extensionId} \
-H "Authorization: Bearer ${accessToken}" \
-H "x-goog-api-version: 2"
`);
Due to the latest set of policy changes to limit extensions abuse and improve the security of the Chrome Web Store, this includes requiring 2FA for Chrome Web Store developers, I am not able to publish chrome ext anymore.
Is there any way how to release chrome ext using Chrome Web Store Publish API without requiring 2-Factor verification?
No, but to clarify the developer account just needs to have two factor authentication enabled. You will still be able to publish extensions through an automated script, but 2FA needs to be setup first.

Unable to register a tenant with X.509 based authentication in Hono

I am following this guide in order to authenticate devices with certificates, but when i run the following command i get 404 NOT FOUND (i am using the Hono sandbox):
curl -i -H 'Content-Type: application/json' -H 'Expect:' --data-binary #tenant.json https://hono.eclipse.org:28443/tenant
I also tried replacing hono.eclipse.org with hono.eclipseprojects.io since i read that the domain name will be deprecated.
I was wondering if the guide is up to date or something changed on the new releases of Hono.
Indeed, Hono's example registry (as used by the sandbox) implements and exposes the Device Registry Management API now. The tenant management endpoint URL to post to in order to create a tenant is
https://hono.eclipseprojects.io:28443/v1/tenants/{your_desired_tenant_id}
Also make sure to check the payload format with the API spec.
You might want to take a look at Hono's Getting Started guide which also illustrates how to register a tenant, device and credentials.

What do I need to add to my web request for GCP Cloud Function Security?

My HTTP Cloud Function is working fine, but it is public. After testing it out I used the GCP console to restrict it to a particular user (ie my own Google account) and, as I expected, I get 403 when I send requests to it. This is good. But I don't know what I need to add to my request for it to get past Google's security. I assume it wants to check a header for a token and verify it against the IAM, but I haven't found any examples yet.
There's a lot of information about using Cloudflare for this, and also someone has done some clever work building an OAuth check inside their cloud function. But clearly Google is already doing a security check for me (this may be new functionality) and I would rather use that than build my own. To be specific then, I went into the permissions section of my Cloud Function and added a member to the 'Cloud Functions Invoker' role. I can add AllUsers as a member and the CF becomes public, take it out and I'm back to 403 responses. So the security is definitely working. I just need a way to identify the caller.
Does anyone know how to add the right keys or whatever to the request?
Some more reading and I found the answer here
The answer is that CFs are, indeed, doing OAuth so my request needs to look something like this:
curl https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME \
-H "Authorization: bearer $(gcloud auth print-identity-token)"
That's using the gcloud command to pull the JWT down and put it in the header. To actually make it work I needed to create a service account and download its key (to the file referred to below). I then added that to the CF (in permissions) and then used
gcloud auth activate-service-account --key-file=sa-cf.json
to make that my currently active account so that the token printed was for that account. Beware when doing this because the tokens quickly expire so if you're pasting them into Postman (as I was) it won't work if you leave it any time before sending the request.
Hope this helps someone else.

Use project deploy token to access gitlab api

I want to read some files in one project existing in gitlab from the application via gitlab API. I create deploy token in the project through
settings -> Repository -> Deploy Tokens.
I then try
/api/v4/projects/MY_ID?private_token=MY_TOKEN
and
/api/v4/projects/MY_ID?access_token=MY_TOKEN
, and none of them work - Both return 401
Can't this deploy token use as an authentication token, and I have to create a new user to achieve it?
But the documentation describes that this deploy token is used for accessing this project, or?
You need to use a Personal Access Token not a Deploy Token. These are created from:
profile -> settings -> access tokens
And in the API request the ID you pass is the Project ID, eg:
curl "https://your-host/api/v4/projects/<project-id>?private_token=<your-private-token>"
To find the Project ID either go to the project page or query all projects you have access to, eg:
curl "https://your-host/api/v4/projects?private_token=<your-private-token>"
Cheers
S

GitHub API - private or forked repositories not listing nor comparing

In my GitHub account I have a few public repositories that I created plus several private repositories forked from repositories in my organization.
My problems are
a) GET /user/repos is only listing the public personally created repositories regardless of the 'type' parameter
b) COMPARE calls on the forked repositories is returning 404
I'm logging in using Oauth 2.
Is there something that I am missing?
Thanks
If I understand correctly, the situation you're describing is as follows:
You belong to an organization. (Let's call it "#your-organization".)
#your-organization has at least one private repository. (Let's call it "your-organization/private-repo".)
You have a fork of that repository in your personal account (e.g., gulliver-smith/private-repo).
You're using an OAuth token to authenticate with the GitHub API.
When you access GET /user/repos, the response does not include your fork (e.g., gulliver-smith/private-repo).
When you access GET /repos/gulliver-smith/private-repo/compare/:base...:head, you get a 404.
If that's right, there are a few things you'll want to verify:
Ensure that your OAuth token has repo scope. If your token does not have repo scope, you'll observe the behavior described above. To verify the scopes associated with your token, look at the X-OAuth-Scopes response header.
$ curl -I https://api.github.com/ -H "Authorization: token REDACTED" | grep ^X-OAuth-Scopes
X-OAuth-Scopes: admin:org, admin:public_key, delete_repo, gist, notifications, repo, user
If you're using a token that belongs to an OAuth application, the organization may have third-party application restrictions enabled. If so, you can ask the organization's administrators to approve the OAuth application so that the app can access the organization's repositories on your behalf.

Resources