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

Wire 1password SDK into Calamari #1252

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Wire 1password SDK into Calamari #1252

wants to merge 4 commits into from

Conversation

rain-on
Copy link
Collaborator

@rain-on rain-on commented May 6, 2024

This includes the following changes:

  • introduces Octopus.1password.sdk as a dependency of Calamari.Testing
  • Updates ExternalVariables.Get to fetch a secret from 1password if no env-var is avilable
  • Adds "secret reference to the externalVariables documented in our ticket"

NOTE: the vault in 1password is not yet updated, thus all values will be taken from an env-var, not the vault.

@@ -117,10 +151,13 @@ class EnvironmentVariableAttribute : Attribute
{
public string Name { get; }
public string LastPassName { get; }
Copy link
Contributor

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.

Copy link
Collaborator Author

@rain-on rain-on May 8, 2024

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")]
Copy link
Contributor

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

Copy link
Collaborator Author

@rain-on rain-on May 8, 2024

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.

@akirayamamoto
Copy link
Contributor

akirayamamoto commented May 6, 2024

My only concern is the Secret References are missing the field name, otherwise looks very similar to the OctopusDeploy repository from the top of my head.

Copy link
Contributor

@eddymoulton eddymoulton left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Suggested change
var loggerFactory = new LoggerFactory(); //.AddSerilog(Logger);
var loggerFactory = new LoggerFactory();

{
var allVariableAttributes = EnvironmentVariableAttribute.GetAll()
.Select(x => x.SecretReference)
.Where(x => x is not null)
Copy link
Contributor

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.

Suggested change
.Where(x => x is not null)
.WhereNotNull()

Copy link
Collaborator Author

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>();
Copy link
Contributor

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.");
Copy link
Contributor

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.

Copy link
Collaborator Author

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}`");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//throw new Exception($"Environment Variable `{attr.Name}` could not be found. The value can be found in the password store under `{attr.LastPassName}`");

Copy link
Collaborator Author

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}`");
Copy link
Contributor

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");
Copy link
Contributor

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?

@rain-on
Copy link
Collaborator Author

rain-on commented May 8, 2024

Overtaken by #1254, Will backport comments.

@rain-on
Copy link
Collaborator Author

rain-on commented May 10, 2024

overtaken by other PRs.

@APErebus
Copy link
Contributor

@rain-on Can this be closed?

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