-
Notifications
You must be signed in to change notification settings - Fork 13
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
[RND-698] Postgresql insert/get #340
Conversation
Requires Postgres with a "MeadowlarkNet" database, and hardcoded postgres/abcdefgh1! credentials (Gave up on getting .env loading working) |
appSettings file is the way to go for .NET applications. There are also methods for reading environment variables to override the appSettings file. reference |
public static class Db | ||
{ | ||
// TODO: Get .env loading working | ||
private static readonly string connectionString = "Server=localhost;Port=5432;User Id=postgres;Password=abcdefgh1!;Database=MeadowlarkNet;"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll end up using a very different pattern for injecting connectionStrings, likely using Admin API 2.0 as our inspiration.
{ | ||
// Note: ProjectName and ResourceName have been validated against the ApiSchema, so SQL injection is not a concern here | ||
string schemaName = resourceInfo.ProjectName.Value.Replace("-", ""); | ||
string tableName = resourceInfo.ResourceName.Value.Replace("-", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to have an in-depth conversation as a team and community about whether to build the tables in MetaEd, deploy at runtime this way, or have a C# app with this same type of code that can run at deploy time.
|
||
var commandText = $@" INSERT INTO {schemaName}.{tableName} | ||
(document_uuid, project_name, resource_name, resource_version, is_descriptor, edfi_doc) | ||
VALUES ($1, $2, $3, $4, $5, $6)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good and makes sense. We'll need to make sure we have some robust injection attempts in unit testing.
* Simple only-once guard for a function with no parameters | ||
*/ | ||
public static Action Once(Action fn){ | ||
var called = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want to lock this for thread safety.
@@ -9,7 +9,8 @@ | |||
<ItemGroup> | |||
<PackageReference Include="JsonSchema.Net" Version="5.5.0" /> | |||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | |||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> | |||
<PackageReference Include="DotNetEnv" Version="3.0.0" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove, since .env
loading is not in use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot about my own comment when merging, oh well.
<ItemGroup> | ||
<None Include=".env"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove, since .env
loading is not in use.
No description provided.