-
Notifications
You must be signed in to change notification settings - Fork 110
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
Wire 1password SDK into Calamari #1252
base: main
Are you sure you want to change the base?
Conversation
@@ -117,10 +151,13 @@ class EnvironmentVariableAttribute : Attribute | |||
{ | |||
public string Name { get; } | |||
public string LastPassName { get; } |
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.
I suggest you to delete the LastPassName
, assuming you will replace that with the SecretReference
.
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.
that is a great idea - but may come in a latter PR - this PR is really dedicated go getting the "EnvironmentVariables.Get" converted to async
@@ -22,25 +29,25 @@ public enum ExternalVariable | |||
[EnvironmentVariable("Azure_OctopusAPITester_Certificate", "Azure - OctopusAPITester")] | |||
AzureSubscriptionCertificate, | |||
|
|||
[EnvironmentVariable("GitHub_OctopusAPITester_Username", "GitHub Test Account")] | |||
[EnvironmentVariable("GitHub_OctopusAPITester_Username", "GitHub Test Account", "op://Calamari Secrets for Tests/Github Octopus Api Tester Username")] |
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.
The Octopus 1P SDK is expecting a secret reference with 3 or 4 fields. This is composed of vault, secret item name, section (optional) and field name.
Example: op://Octopus Server Secrets for Tests/Azure - OctopusAPITester/password
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.
ButThese have been updated 🙇
But will be fully resolved in later PRs.
My only concern is the Secret References are missing the field name, otherwise looks very similar to the |
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.
No glaring issues to me, just some suggestions for you to consider.
Ping me when it's out of draft and I'll come through with the approval.
.Select(x => x.SecretReference) | ||
.Where(x => x is not null) | ||
.ToArray(); | ||
var loggerFactory = new LoggerFactory(); //.AddSerilog(Logger); |
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.
?
var loggerFactory = new LoggerFactory(); //.AddSerilog(Logger); | |
var loggerFactory = new LoggerFactory(); |
{ | ||
var allVariableAttributes = EnvironmentVariableAttribute.GetAll() | ||
.Select(x => x.SecretReference) | ||
.Where(x => x is not null) |
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.
nit and/or an impossible suggestion if this codebase doesn't support it.
WhereNotNull
does nullability better than .Where(x => x is not null)
for whatever reason so it's a good habit to use it everywhere.
.Where(x => x is not null) | |
.WhereNotNull() |
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.
WhereNotNull is an extension method we created - furthermore - this code has been removed.
.Where(x => x is not null) | ||
.ToArray(); | ||
var loggerFactory = new LoggerFactory(); //.AddSerilog(Logger); | ||
var microsoftLogger = loggerFactory.CreateLogger<SecretManagerClient>(); |
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.
Not really familar with how the logger should be set up, but this looks unusual at the very least.
Can I assume you've tested this and it works as expected?
Log.Warn($"The following environment variables could not be found: " + | ||
$"\n{string.Join("\n", missingVariables.Select(var => $" - {var.Name}\t\tSource: {var.LastPassName}"))}" + | ||
$"\n\nTests that rely on these variables are likely to fail."); | ||
Log.Warn($"The following environment variables could not be found: " + $"\n{string.Join("\n", missingVariables.Select(var => $" - {var.Name}\t\tSource: {var.LastPassName}"))}" + $"\n\nTests that rely on these variables are likely to fail."); |
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.
Classic auto-formatter.
I'm willing to bet there is some dotsettings configuration you could change (in the shared settings) that will keep these spread across lines.
IMO it's worth taking a peek at that, or failing that manually reverting this change to the more readable original.
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.
rolled back - haven't touched autoformatter at this stage.
{ | ||
throw new Exception($"Environment Variable `{attr.Name}` could not be found. The value can be found in the password store under `{attr.LastPassName}`"); | ||
return valueFromEnv; | ||
//throw new Exception($"Environment Variable `{attr.Name}` could not be found. The value can be found in the password store under `{attr.LastPassName}`"); |
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.
//throw new Exception($"Environment Variable `{attr.Name}` could not be found. The value can be found in the password store under `{attr.LastPassName}`"); |
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.
removed.
} | ||
} | ||
|
||
throw new Exception($"Unable to find `{attr.Name}` as either an Environment Variable, or a SecretReference. The value can be found in the password store under `{attr.LastPassName}`"); |
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.
This may be slightly misleading if SecretManageIsEnabled
is false? I think there is value in composing this message to say exactly what's happening, even if it only saves a single engineer a moment of debugging pain.
[EnvironmentVariable("GitHub_RateLimitingPersonalAccessToken", "GitHub test account PAT")] | ||
GitHubRateLimitingPersonalAccessToken, | ||
} | ||
|
||
public static class ExternalVariables | ||
{ | ||
static readonly bool SecretManagerIsEnabled = Convert.ToBoolean(Environment.GetEnvironmentVariable("CALAMARI__Tests__SecretManagerEnabled") ?? "True"); |
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.
You may want to stick with OCTOPUS__Tests__SecretManagerEnabled
. Maybe a benefit in consistency?
Overtaken by #1254, Will backport comments. |
overtaken by other PRs. |
@rain-on Can this be closed? |
This includes the following changes:
NOTE: the vault in 1password is not yet updated, thus all values will be taken from an env-var, not the vault.