Using Information via Microsoft.Azure.Management.Fluent I'm trying to get to information about Web Jobs. I'm able to use it to get information about Web Apps, Service Buses, Resource Groups, App Services, etc.
But I haven't been able to find a way to get to the Web Job level. In Azure the Web Jobs are located at the level
https://ms.portal.azure.com/#resource/subscriptions/{SubId}/resourceGroups/{ApServiceName}/providers/Microsoft.Web/sites/{ApServiceName}/webJobs
Using Microsoft.Azure.Management.Fluent I haven't been able to find a way to get to the Web Jobs level. Is this possible via the Microsoft.Azure.Management.Fluent?
Is this possible via the Microsoft.Azure.Management.Fluent?
Based on my exerpience, No. According to Azure SDK source code, it seems that there is no way to get the WebJob level.
If we want to get WebJob level, Azure supplies the WebJob API for us to operate on WebJob. About authorization for the WebJob API, we could refer to the this blog.
I had a need to execute some management API code for WebJobs and found that it is now possible, although it's not easy to find it in the API documentation.
You can do it by installing the Microsoft.Azure.Management.AppService.Fluent package (I think it's also possible to do it the non-fluent management SDK too, although I didn't try this).
Getting access to the methods for managing a WebJob can be done like this:
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
class MyWebJobsManagementClass
{
public async Task DoSomeWebJobsManagement()
{
var jobs = await Azure
.Authenticate() // See the docs for how to authenticate with this SDK
.WithSubscription("your-subscription-id")
.AppServices
.Inner
.WebApps
.ListWebJobsWithHttpMessagesAsync("resource-group-name", "app-service-name")
}
}
It's through the non-obvious AppServices.Inner that you can get a reference to an IWebAppsOperations instance which then lets you perform quite a few operations on the WebJobs, including starting and stopping them.
Authentication Side note
If you're looking for a way to authenticate with Azure.Identity, instead of the file based credentials approach they used to use with these older SDKs, then there is a way to achieve this even though it's not supported "out-the-box".
There's a GitHub repo which contains an example of how to achieve this. I think it's by one of the developers on the Microsoft team, but isn't officially supported by Microsoft. There is no NuGet package for it and they recommend just copying the bits you need.
I actually found that the code in that sample repo was overly complex for my needs and in my case that all I needed was this. Note, I've copied this from my F# project without testing it, so I might have made a mistake in the conversion to C#, but hopefully it's close enough that you get the idea.
class AzureIdentityFluentCredentialAdapter : AzureCredentials
{
public AzureIdentityFluentCredentialAdapter(string tenantId)
: base(default(DeviceCredentialInformation), tenantId, AzureEnvironment.AzureGlobalCloud)
{
}
public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var creds = DefaultAzureCredential() // Use the new Azure.Identity library to get access tokens
var accessToken = await creds.GetTokenAsync(
new TokenRequestContent(new [] { "https://management.azure.com/.default" }),
cancellationToken);
return await TokenCredentials(accessToken.Token)
.ProcessHttpRequestAsync(request, cancellationToken);
}
}
This example doesn't do any token caching, but for my purposes I wasn't too bothered about this. It's also hardcoded the scope that I request the token for because I knew I was only going to be using this with the Azure management API.
Related
I've been having trouble with this for a while and now I really need help.
This is the code I am currently using to bind a custom subdomain to Azure and everything is working just fine:
var appService = await azure.AppServices.WebApps.GetByIdAsync(
"subscription-id");
await appService.Update().DefineHostnameBinding()
.WithThirdPartyDomain("mydomain.net")
.WithSubDomain("www")
.WithDnsRecordType(CustomHostNameDnsRecordType.CName)
.Attach()
.ApplyAsync();
So what will be the way to bind just mydomain.net except that CustomHostNameDnsRecordType.CName should be changed with CustomHostNameDnsRecordType.A because Azure does not support CNAME records for root domains?
I cannot skip the WithSubDomain(string) method. Tried passing and null/empty string/space or just . but the response from Azure for null is Object reference not set to an instance and for the others is Bad Request.
P.S. I know that I am using an old SDK which is in maintenance mode but the new ones are still in beta or even alpha and there is still no support for App Services so I have to stick with that.
#DeepDave-MT pointed me to the correct answer in a comment under my question even though it's ridiculous. I am now quite sure I will go with this fluent API because there are too many things that are bothering me, almost no documentation, bad error handling and so on. Anyway, this is how to add a root domain in Azure using the so called fluent management API:
await appService.Update().DefineHostnameBinding()
.WithThirdPartyDomain("mydomain.net")
.WithSubDomain("#")
.WithDnsRecordType(CustomHostNameDnsRecordType.A)
.Attach()
.ApplyAsync();
P.S. I don't know why I don't have the habit to check for issues in GitHub.
I've been trying for days on this and think that the issue is somewhere with my developer account but thought I'd ask for advice here first before digging in there.
I have followed the documentation and multiple tutorials and this should work it seems but no matter what call I make using Tweetinvi to Twitter I get "Forbidden" which when looking at the twitter codes means my authorization is correct but that I am asking for something that I don't have access to, but I am just trying to send a test tweet to see if the program works, which according to Twitter's documentation I should have full access to. Here's the code that I took from Tweetinvi's Tutorial on how to make a "Hello World" tweet but it just doesn't work cuz it returns "Forbidden".
static async Task Main(string[] args)
{
var userClient = new TwitterClient("APIKey", "sAPIKey", "AccessToken", "sAccessToken");
var tweet = await userClient.Tweets.PublishTweetAsync("This is a test tweet");
Console.WriteLine(tweet);
}
It's not just the send tweet function either, if I try to pull any information at all it says it's forbidden so I feel the issue is on Twitter side not my code but I am just trying to learn it as a hobby and have no idea. Just was told Tweetinvi would make everything take 5 minutes and now I am at three days of trying to figure this out. Any help in figuring this out would be nice and greatly appreciated.
Twitter's latest API release [Nov 15th 2021] has an entry level of access called "Essential" that provides access to the v2 API, because this should be the base for most new apps. If you need access to v2 and also to the legacy v1.1 APIs in the same app, you will need "Elevated" access, which is also available for free. The PublishTweetAsync method you are calling in the code in this question is trying to hit the v1.1 Tweet statuses/update endpoint, so your app will need Elevated access in order to make it work.
So I was thinking about learning about app development for android. I know you use kotlin however, I also want to start working with .NET and C# is there a possibility for my first app that I create a basic login and register form in the app using Kotlin and connect it to a .NET REST API? Is that a thing I am sure you are just using the URL for the API call?
Sure! Using Retrofit, the Android app could be connected to the RESTful APIs that is available using the latest technology by Microsoft and the open source community; ASP.NET Core Web API 5.
A complete guide to do so:
http://codingsonata.com/a-complete-tutorial-to-connect-android-with-asp-net-core-web-api/
yes it is possible, there are plenty of libraries that are able to help you with that, like Retrofit or Volley
Yes. It's a very common way to consume API for data processing purposes in android-based applications.
If you have learnt on how to consume API with Android Application (built using JAVA), it's pretty much the same.
if you have never used JAVA to create android applications that consume API, don't worry because the process you need to do is very simple, moreover there are already many collections of libraries that you can use for this purpose. You can try to look on several library such as Retrofit and OkHttp.
Let me show you a a simple example of using OkHttp to pass data from android to API. This simple example is quoted from this article
private val client = OkHttpClient()
fun run() {
val formBody = FormBody.Builder()
.add("search", "Jurassic Park") /*The parameters*/
.build()
val request = Request.Builder()
.url("https://en.wikipedia.org/w/index.php") /*API URL*/
.post(formBody)
.build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
println(response.body!!.string())
}
}
I hope this answer can be helpful for you. If you need more assistance, don't hesitate to contact.
If you are using API, you use URL and model of your data.
I recommend Retrofit as a library for connecting to any API. A good example is here, check out this and I think you will be well prepared to write Kotlin code.
Firstly, you need to define retrofit client, with your URL:
retrofit = new Retrofit.Builder()
.baseUrl("https://reqres.in")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
then you need to map your API as an interface, for example if you have an endpoint https://reqres.in/api/users? you must define them like this:
#GET("/api/users?")
Call<UserList> doGetUserList(#Query("page") String page);
For creating .NET Core API, especially with user registration you must check some of tutorials, I recommend to be familiar with EF Identity (other).
Good morning.
I am a bit confused about these two repositories(graphql-dotnet/graphql-dotnet/ and graphql-dotnet/server/).
https://github.com/graphql-dotnet/graphql-dotnet/ and
https://github.com/graphql-dotnet/server
They are both under the same organization and there is some overlap of contributors, but I'm a bit lost about deciding which one to use.
I would like to build a dotnet 5 application that hosts a graphql endpoint. In a nutshell that is my goal.
I noticed that the graphql-dotnet/server/repository has inbuilt some helpers such as.
serviceCollection
.AddGraphQL((options, provider) =>
{
options.EnableMetrics = HostEnvironment.IsDevelopment();
var logger = provider.GetRequiredService<ILogger<Startup>>();
options.UnhandledExceptionDelegate = ctx => logger.LogError("{Error} occurred", ctx.OriginalException.Message);
})
.AddSystemTextJson()
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = HostEnvironment.IsDevelopment())
.AddWebSockets()
.AddDataLoader()
.AddGraphTypes(typeof(ApplicationSchema))
Which allows my DI to be setup nice and easy. Its counterpart, the graphql-dotnet/graphql-dotnet/ does not.
So my question is "which one should I use exclusivly? Which one is recomended, by secondary goals are to add jwt authentication and finally federation support. But those two are far down the line.
One of my coworkers went ahead and used graphql-dotnet/graphql-dotnet/ and his server application has a lot more configuration than the documentation of graphql-dotnet/server/ so how do I know which one do I use?
Can any one recommend any documentation that highlights the difference between the two of them?
The main graphql-dotnet repo is the "core" library of GraphQL components. The server repo contains ASP.NET specific extensions. It uses the core library. If you use the server project, you are also using the core library.
GraphQL itself can be used with any protocol, it is not required to be used with HTTP or JSON. So the core library does not have any HTTP or ASP.NET dependencies.
If you are using ASP.NET, then the server project is the quickest way to get started. If you want to use Subscriptions, then the server project provides that functionality.
If you don't need subscriptions and if you want a bit more control over how the framework handles the HTTP request, then it would be easier to write your own controller or middleware.
Using JWT authentication is handled by ASP.NET and can be used in either scenario. Federation can also be used in either scenario.
I'm creating a new AWS user using the SDK. I'm able to create it, and retrieve the Access and Secret keys just fine. But I also want to attach an existing policy to the new user, presumably with this command
http://docs.aws.amazon.com/IAM/latest/APIReference/API_AttachUserPolicy.html
Does this method exist somewhere within the .NET SDK? I can't find it after a maddening amount of searching.
You're looking for AmazonIdentityManagementServiceClient.AttachUserPolicy.
Signature:
public virtual AttachUserPolicyResponse AttachUserPolicy(AttachUserPolicyRequest request)
Request:
Amazon.IdentityManagement.Model.AttachUserPolicyRequest
Response:
Amazon.IdentityManagement.Model.AttachUserPolicyResponse
There's also an async version, if you're interested.