Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up Azure Functions sample for publishing #531

Merged
merged 12 commits into from
Nov 7, 2024

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Nov 5, 2024

This PR fixes up a couple of issues with the Azure Functions sample that make it unpublishable:

  • Enable external HTTP access on the Blazor front-end resource
  • Configure the appropriate roles to support Blob triggers on the Azure Functions host
  • Allow anonymous access to blobs in the storage account to support UI display in the Blazor front-end
  • Reference SkiaSharp.NativeAssets.Linux.NoDependencies package to support running SkiaSharp in Linux containers on ACA

@bradygaster
Copy link
Member

cloned and tried deploying - worked like a champ. ship it.

@DamianEdwards
Copy link
Member

Adding back WithHostStorage() is leading to the test issue WRT resource(s) being removed after waiting for them has started. I'll take a look at the test to see if I can refactor it to handle it.

@captainsafia
Copy link
Member Author

Adding back WithHostStorage() is leading to the test issue WRT resource(s) being removed after waiting for them has started. I'll take a look at the test to see if I can refactor it to handle it.

Yes, as soon I saw the failing CI I realized I opened that can of worms again 😭. Let me know if you'd like any help or to split up the changes in this PR.

@DamianEdwards
Copy link
Member

Wow, that worked 😮

@captainsafia
Copy link
Member Author

Wow, that worked 😮

Should we kick CI a couple of times to sanity check?

@DamianEdwards
Copy link
Member

Should we kick CI a couple of times to sanity check?

Yeah I don't even think the logic I added is being hit but instead it's working because now Start and Wait are awaited sequentially now. I previously had to start them in parallel based on discussions I had with @davidfowl but I can't remember the details and it's seemingly passing now anyway.

return Results.NotFound();
}

var properties = (await blobClient.GetPropertiesAsync(cancellationToken: cancellationToken)).Value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangerous assumption.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah not sure what you're referring to here.

Copy link
Member

@IEvangelist IEvangelist Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping an await in parathesis assumes that it returns a non-null value and when you access it with .Value, you're saying that you assume for certain that the call to .GetPropertiesAsync will happily return. It's cleaner/safer to get the response, check for null and then access the .Value.

IMO every time I see anything that does (await SomethingAsync()).SomeProp, I think of that as a code smell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what we have nullable ref types for though, and Value isn't marked as nullable, so this should be fine. There's literally nothing of value on the object returned from GetPropertiesAsync other than the Value member.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the return value nullable @DamianEdwards ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, and if it were I'd get a compiler message complaining about how I'm using properties afterwards. The doc comment for Value says it will throw upon access only if the entire response is declared as a nullable response, which it isn't here.

Copy link
Member Author

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

construct.Add(storageAccount.CreateRoleAssignment(StorageBuiltInRole.StorageAccountContributor, construct.PrincipalTypeParameter, construct.PrincipalIdParameter));
construct.Add(storageAccount.CreateRoleAssignment(StorageBuiltInRole.StorageBlobDataOwner, construct.PrincipalTypeParameter, construct.PrincipalIdParameter));
// Ensure that public access to blobs is disabled
storageAccount.AllowBlobPublicAccess = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is false so we could remove this but I think there's value in the explicitness for this sample.

Copy link
Member

@DamianEdwards DamianEdwards Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wasn't actually sure as the doc comments are kinda confusing. I interpreted this to mean it defaulted to true?
image

@DamianEdwards DamianEdwards merged commit d51ab30 into main Nov 7, 2024
3 checks passed
@DamianEdwards DamianEdwards deleted the safia/fix-func-publish branch November 7, 2024 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants