Authenticator
Warning
This content is part of the legacy version of Waypoint that is no longer actively maintained. For additional information on the new vision of Waypoint, check out this blog post and the HCP Waypoint documentation.
https://pkg.go.dev/github.com/hashicorp/waypoint-plugin-sdk/component#Authenticator
The Authenticator component is executed when the waypoint init command is called, Authenticator is enabled by implementing two interfaces, ValidateAuthFunc and AuthFunc. Typically you implement Authenticator along with another Component, for example you have a Platform component which deploys a waypoint application to Google Cloud Run. You could implement the Authenticator component to check that the GCP credentials are valid.
The interface definition which you implement is shown below.
ValidateAuthFunc is called when you run waypoint init, this is where you would implement logic which checks that the plugin has the correct requirements in order to perform its work.
The signature for the function you return from AuthFunc has a single output parameter which is an error. If a non-nil error is returned then Waypoint calls the AuthFunc method. An example implementation of VaultAuthFunc can be found in the example below.
AuthFunc is only called when ValidateAuthFunc returns an error, this is where you would implement any prompts to the user to authenticate or where you can attempt to authenticate.
The signature for an AuthFunc has two output parameters, *component.AuthResult and an error. If authentication succeeds you return an AuthResult message which has Authenticated set to true &component.AuthResult{Authenticated: true}, and for failed authentication set this to false. If an error occurs during the authentication process you can return this as the second output parameter.
A simple example of an AuthFunc implementation can be seen below.