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

Token Management Add/Remove/List/Update #1611

Merged
merged 26 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,684 changes: 1,443 additions & 241 deletions astro-client-core/api.gen.go

Large diffs are not rendered by default.

165 changes: 165 additions & 0 deletions astro-client-core/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 27 additions & 3 deletions astro-client-iam-core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package astroiamcore

import (
"bytes"
httpContext "context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"runtime"

"github.com/astronomer/astro-cli/context"
"github.com/astronomer/astro-cli/pkg/httputil"

astrocore "github.com/astronomer/astro-cli/astro-client-core"
"github.com/astronomer/astro-cli/version"
)

var (
Expand All @@ -24,7 +27,7 @@ type CoreClient = ClientWithResponsesInterface

func NewIamCoreClient(c *httputil.HTTPClient) *ClientWithResponses {
// we append base url in request editor, so set to an empty string here
cl, _ := NewClientWithResponses("", WithHTTPClient(c.HTTPClient), WithRequestEditorFn(astrocore.CoreRequestEditor))
cl, _ := NewClientWithResponses("", WithHTTPClient(c.HTTPClient), WithRequestEditorFn(CoreRequestEditor))
return cl
}

Expand All @@ -39,3 +42,24 @@ func NormalizeAPIError(httpResp *http.Response, body []byte) error {
}
return nil
}

func CoreRequestEditor(ctx httpContext.Context, req *http.Request) error {
currentCtx, err := context.GetCurrentContext()
if err != nil {
return nil
}
os := runtime.GOOS
arch := runtime.GOARCH
baseURL := currentCtx.GetPublicRESTAPIURL("iam/v1beta1")
requestURL, err := url.Parse(baseURL + req.URL.String())
if err != nil {
return fmt.Errorf("%w, %s", ErrorBaseURL, baseURL)
}
req.URL = requestURL
req.Header.Add("authorization", currentCtx.Token)
req.Header.Add("x-astro-client-identifier", "cli")
req.Header.Add("x-astro-client-version", version.CurrVersion)
req.Header.Add("x-client-os-identifier", os+"-"+arch)
req.Header.Add("User-Agent", fmt.Sprintf("astro-cli/%s", version.CurrVersion))

Choose a reason for hiding this comment

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

Should we add a request header for the API version as well? We do want to get to v1 so tracking API versions in the client could help with this effort. @vandyliu @fredzhy what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

API version is already handled on core API side so we don't need that info from the clients

return nil
}
Loading