How to send API request with "/" and "*" characters in endpoint - rest

im using the github API via Python in order to create branch protection rules for a github repo. Im using the requests library
https://docs.github.com/rest/reference/repos#get-branch-protection
And one of the rules i have to do need the "/" and the "" characters in them, for example: "/test/" or "test/" and the API does not work and gives a message not found because it thinks that the "/" and the "*" characters are not part of the branch name, but part of the API endpoint itself.
https://api.github.com/repos/OWNER/REPO/branches/test/*/protection
https://i.stack.imgur.com/Qh4F8.png
I have tried to encode the "/" and "*" characters using requests.utils.quote(branch, safe='') but the result is the same either way
https://i.stack.imgur.com/ANOY1.png
How can i solve this or get around this issue? Thank you

Related

Azure Front Door route to app service subdirectory

I have an Azure Front Door environment that I would like to use to route a domain to an app service sub directory. But im having some issues setting it up
Domain: portal.example.com
Back End Pool: App Service - xxx.azurewebsites.net
I would like portal.example.com to route to xxxx.azurewbesites.net/portal
But for some reason im not able to do that and getting errors if i try to have it redirect with the slash " / "
"The domain and subdomains can be between 1 to 63 alphanumeric characters, must start and end with an alphanumeric character, and additionally can contain the '-' character in between. The top level domain must be between 2 to 61 alphabetical characters."
I have tried creating a routing rule and also tried using rule engine configuration.
seems there will be wrong route configuration. I have tried to replicate the same scenario.
Step1:
Created a front door environment with backend endpoint as
*****.azurewebsites.net
Step2:
Applying rule configuration to update route rule as
if request URL is "portal.example.com" then route the traffic to xxxx.azurewbesites.net/portal
refer this tutorial for more information. Found another similar post for reference.

Azure Media Servicdes: client.Assets.CreatOrUpdateAsync results in error: The resource Type is invalid

Based on the docs here: https://learn.microsoft.com/en-us/azure/media-services/latest/stream-files-tutorial-with-api
I've created a media services client and am attempting to create the new asset that will have the video file uploaded into it.
When I do this using the infromation provided on the API Access tab of the media service in question, the line: client.Assets.CreateOrUpdateAsync fails with "The resource type is invalid."
Anyone have any idea as to what is causing that and how to fix it? The sample is woefully out of date with credential management and the author is completely non-responsive for over a year.
So I found what this error actually means for anyone that hits this with the same problem:
It's the asset name. It has to conform to Windows file naming standards otherwise you'll get this unhelpful error.
Of course the error message should be updated to "invalid asset name, please ensure that it conforms to windows file naming conventions" but that's a separate bug report to Microsoft.
I just cloned the repo again myself, went to the portal and grabbed the JSON from the API Access blade and replaced the appsettings.json file (hit save), then hit F5 and it is running fine.
Can you try to clean that folder and re-clone the github project again.
git clone https://github.com/Azure-Samples/media-services-v3-dotnet-tutorials.git
Re-grab your credentials and replace them.
Make sure you open vscode from the "UploadEncodeAndStreamFile" folder as well. Seems to be working for me.
Not sure why you would be seeing "resource type is invalid" actually. That sounds like something is named wrong in your appsettings.json file.
Also watch out for Asset Naming conventions, there are character limitations and lengths to be aware of - see here.
https://learn.microsoft.com/en-us/azure/media-services/latest/media-services-apis-overview#naming-conventions
Naming conventions
Azure Media Services v3 resource names (for example, Assets, Jobs, Transforms) are subject to Azure Resource Manager naming constraints. In accordance with Azure Resource Manager, the resource names are always unique. Thus, you can use any unique identifier strings (for example, GUIDs) for your resource names.
Media Services resource names can't include: '<', '>', '%', '&', ':', '', '?', '/', '*', '+', '.', the single quote character, or any control characters. All other characters are allowed. The max length of a resource name is 260 characters.

Github create or update file fails with 422 invalid Base64 encoding for MIME 64 encoding

https://developer.github.com/enterprise/2.18/v3/repos/contents/#create-or-update-a-file
I am trying to call the above API using github-api library. The API fails with 422, invalid Base 64 encoding.
The library uses MIME type encoding. If I change to Base64.encodeToString(content), github api accepts it.
My question is:
Does github not accept MIME type 64 encoding?
I need to add a header of some kind to say it is not plain 64 but MIME type(which breaks into chunks of 76 characters)?
It could be linked to github-api/github-api issue 638:
When we invoke org/kohsuke/github/GHContentBuilder.java#commit() with content length > 57
The API fails with 422, invalid Base 64 encoding
If we have a content 1234567890123456789012345678901234567890123456789012345678 of length 58.
I was able to fix this issue locally by using Base64.getEncoder().encodeToString()
This is however linked to a recent change.
Note that "GitHub Rest API V3 'Other Authentication Methods'" includes:
The API supports Basic Authentication as defined in RFC2617 with a few slight differences.
The main difference is that the RFC requires unauthenticated requests to be answered with 401 Unauthorized responses.
In many places, this would disclose the existence of user data. Instead, the GitHub API responds with 404 Not Found.
This may cause problems for HTTP libraries that assume a 401 Unauthorized response. The solution is to manually craft the Authorization header.
So a MIME encoding might nit be supported by github-api/github-api because of those RFC2617 requirements which are not followed.
Liam Newman from CloudBees comments:
The change you linked (#631 'Remove dependency on apache commons-codec') hasn't been publish in a release yet - if you're you using v1.101 it doesn't have this change.
I'm pretty sure I specifically used the MIME encoding because the non-MIME produced an error. Also, if you look at what comes back from GitHub it is MIME encoded.
See "Decoding base64 while using GitHub API to Download a File"

How to read Azure Service Bus Topic Name contains / in it. eg: xxx/t000 in PowerShell

I am using PowerShell to read the Azure Service Bus Topics. The topic name contains some special characters in it. Eg. Topic name is xxx/t000.
When I use:
Get-AzureRmServiceBusSubscription -ResourceGroup 'rg_name' -NamespaceName 'sbname' -TopicName "xxx/t000"
I am getting error:
Operation returned an invalid Status code "Not Found"
So I am predicting the issue with the / in the topic name.
Can someone help me on how to read the topic name which contains "/" in it?
Try putting the topic name in single quotes.
-TopicName 'xxx/t000'
This problem is related to Azure Resource Manager, which doesn't support resource names that have "/". You should be able to reference the topic by replacing '/' with '~'.
Here's a good behind the scenes description about this subject on MSDN: https://blogs.msdn.microsoft.com/servicebus/2017/06/21/azure-service-bus-azure-resource-manager-and-this-character/
On the Service Bus side we will convert "/" to "~" when interfacing
with ARM, but retain the slashes in our back-end so things continue to
work the way they are supposed to.

WSO2 Enterprise Store 1.0.0: setting hostname

In WSO2 Enterprise Store 1.0.0 there is a mix about the hostname used to make connections.
You can set HostName and MgtHostName in carbon.xml. But there are files with fixed names, like
sso-idp-config.xml: (AssertionConsumerService) https://localhost:9443/store/acs
jaggeryapps\store\controllers\ login.jag: (postUrl) "https://" + process.getProperty('carbon.local.ip') + ":" ...
localhost breaks every remote connection. IP address breaks SAML authentication and is not consistent with 3rd party certificates.
Is there an easy way to set the hostname all over the ES?
I tried this scenario only by updating AssertionConsumerService within sso-idp-config.xml and it works for me.
So you have to only update AssertionConsumerService within sso-idp-config.xml.
To work properly, the full list of files I had to modify is:
repository\conf\sso-idp-config.xml
repository\deployment\server\jaggeryapps\publisher\controllers\login.jag
repository\deployment\server\jaggeryapps\publisher\controllers\logout.jag
repository\deployment\server\jaggeryapps\social\controllers\login.jag
repository\deployment\server\jaggeryapps\social\controllers\logout.jag
repository\deployment\server\jaggeryapps\store\controllers\login.jag
repository\deployment\server\jaggeryapps\store\controllers\logout.jag
repository\deployment\server\jaggeryapps\store\themes\store\js\asset.js
login/logout files use the IP address (a bad choice when working with third-party certificates. It also breaks SAML authentication).
I lost a lot of time locating files with IP and localhost references. I think it should be reviewed and documented in future versions of the product.