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

Add deployment environment API endpoint #2412

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Conversation

dotNomad
Copy link
Collaborator

This PR adds a new endpoint for our binary GET /api/deployments/$NAME/environment which will either:

  • Fail in a myriad of different ways
  • Give an array of strings with the names of the environment variables on Connect (see the API Docs)

I kept all of the errors bubbling up since the frontend can handle this by ignoring them for the most part and leaving better Connect Content error handling to other, more pointed features.

The plan is to capture these errors and assume that the environment is [] if something goes awry.

Intent

Part of #2365

Type of Change

    • Bug Fix
    • New Feature
    • Breaking Change
    • Documentation
    • Refactor
    • Tooling

Approach

The approach was to fetch everything that is necessary to call the Connect API and fail on the different cases that can happen before calling the API.

Then if we call the API pass through any errors.

Automated Tests

There are automated tests for the new endpoint.

Directions for Reviewers

The API can be tested directly using just run. There are tests for the various error states:

  • If the deployment record with the given name doesn't exist -> 404
  • If the deployment record exists, but is in error and cannot be decoded -> 400
  • If the deployment record exists, but hasn't been deployed -> 400
  • If the deployment record exists, but there is no credential for the given Server URL -> 400
  • Pass through errors from the Connect API
    • For example if authentication fails, or the content has been deleted
  • A few InternalErrors for unexpected cases

@@ -166,6 +166,10 @@ func RouterHandlerFunc(base util.AbsolutePath, lister accounts.AccountList, log
r.Handle(ToPath("deployments", "{name}"), DeleteDeploymentHandlerFunc(base, log)).
Methods(http.MethodDelete)

// GET /api/deployments/$NAME/environment
r.Handle(ToPath("deployments", "{name}", "environment"), GetDeploymentEnvironmentHandlerFunc(base, log, lister)).
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unsure about the name here. Maybe we should be more direct about this being the Connect Content environment?

This is on the deployment resource which implies this is the content, and not the configuration's environment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it makes sense as you have it 👍

Comment on lines +38 to +41
// If the deployment file is in error return a 400
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("deployment %s is invalid: %s", name, err)))
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

Many of these error responses can be sent as specific agent errors, like in post_deployment.go. I'm guessing those changes are scoped to a future PR, when bridging the frontend, but wanted to confirm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is exactly right. I kept it generic for now, and figured we would add agent errors when they were needed by the agent

Copy link
Collaborator

@marcosnav marcosnav left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -166,6 +166,10 @@ func RouterHandlerFunc(base util.AbsolutePath, lister accounts.AccountList, log
r.Handle(ToPath("deployments", "{name}"), DeleteDeploymentHandlerFunc(base, log)).
Methods(http.MethodDelete)

// GET /api/deployments/$NAME/environment
r.Handle(ToPath("deployments", "{name}", "environment"), GetDeploymentEnvironmentHandlerFunc(base, log, lister)).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it makes sense as you have it 👍

@dotNomad dotNomad merged commit b723c69 into main Oct 31, 2024
14 checks passed
@dotNomad dotNomad deleted the dotnomad/connect-env branch October 31, 2024 00:38
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.

2 participants