Skip to content

feat: pass access_token to coder_git_auth resource #6713

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

Merged
merged 1 commit into from
Mar 22, 2023
Merged

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Mar 21, 2023

This allows template authors to leverage git auth to perform custom actions, like clone repositories.

I mostly moved code around in this, there are actually very few changes. The increased lines is primarily due to hardening around refreshing the Git token, which I felt was important enough to become slightly abstracted.

This essentially enables:

data "coder_git_auth" "github" {
  id = "github"
}

resource "coder_agent" "dev" {
  env = {
    GITHUB_TOKEN: data.coder_git_auth.github.access_token,
  }
}

@kylecarbs kylecarbs requested a review from sreya March 21, 2023 22:17
@kylecarbs kylecarbs self-assigned this Mar 21, 2023
@kylecarbs kylecarbs force-pushed the accessgitauth branch 2 times, most recently from d1ecc81 to 08e9d55 Compare March 21, 2023 22:56
UserID: owner.ID,
})
if errors.Is(err, sql.ErrNoRows) {
continue
Copy link
Member

Choose a reason for hiding this comment

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

I assumed that git auth was required if a template specifies it based on not being able to create a workspace in dogfood until I set it up. Should this not fail the build early or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we might make this an option in the data source eventually, but the default should be to never fail builds.

This feature is mostly useful for a first-time clone anyways.

}
// We weren't able to find a matching config for the ID!
if config == nil {
continue
Copy link
Member

Choose a reason for hiding this comment

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

We should probably log and/or fail the build here.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I'll make it warn.

Comment on lines 19 to 20
repeated provisioner.VariableValue variable_values = 5;
provisioner.Provision.Metadata metadata = 6;
bytes state = 7;
repeated provisioner.GitAuthProvider git_auth_providers = 6;
Copy link
Member

Choose a reason for hiding this comment

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

these two lines have tabs instead of 8 spaces

This allows template authors to leverage git auth to perform
custom actions, like clone repositories.
@kylecarbs kylecarbs enabled auto-merge (squash) March 22, 2023 19:14
@kylecarbs kylecarbs merged commit df31636 into main Mar 22, 2023
@kylecarbs kylecarbs deleted the accessgitauth branch March 22, 2023 19:37
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants