| 20 | ) |
| 21 | |
| 22 | func NewClient(token string, opts ...cloudquery_api.ClientOption) (*cloudquery_api.ClientWithResponses, error) { |
| 23 | requestEditorOpt := cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { |
| 24 | req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) |
| 25 | return nil |
| 26 | }) |
| 27 | |
| 28 | clientOpts := append([]cloudquery_api.ClientOption{requestEditorOpt}, opts...) |
| 29 | |
| 30 | c, err := cloudquery_api.NewClientWithResponses( |
| 31 | env.GetEnvOrDefault(envAPIURL, defaultAPIURL), |
| 32 | clientOpts..., |
| 33 | ) |
| 34 | if err != nil { |
| 35 | return nil, fmt.Errorf("failed to create api client: %w", err) |
| 36 | } |
| 37 | return c, nil |
| 38 | } |
| 39 | |
| 40 | func NewAnonymousClient() (*cloudquery_api.ClientWithResponses, error) { |
| 41 | c, err := cloudquery_api.NewClientWithResponses(env.GetEnvOrDefault(envAPIURL, defaultAPIURL)) |