-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow use of CloudQuery registry with docker plugins (#235)
This change allows Docker plugins to use the CloudQuery registry, meaning that configs can now be written like: ``` path: cloudquery/typeform version: v1.2.3 ``` instead of ``` registry: docker path: docker.cloudquery.io/cloudquery/source-typeform:v1.2.3 ``` The `docker` registry can still be used if preferred, either with or without the `docker.cloudquery.io` path.
- Loading branch information
1 parent
8339927
commit 58ec077
Showing
7 changed files
with
153 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package managedplugin | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
cloudquery_api "github.com/cloudquery/cloudquery-api-go" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
func getHubClient(logger zerolog.Logger, ops HubDownloadOptions) (*cloudquery_api.ClientWithResponses, error) { | ||
c, err := cloudquery_api.NewClientWithResponses(APIBaseURL(), | ||
cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { | ||
if ops.AuthToken != "" { | ||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", ops.AuthToken)) | ||
} | ||
logger.Debug().Interface("ops", ops).Msg(fmt.Sprintf("Requesting %s %s", req.Method, req.URL)) | ||
return nil | ||
})) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Hub API client: %w", err) | ||
} | ||
return c, nil | ||
} | ||
|
||
func isDockerPlugin(ctx context.Context, c *cloudquery_api.ClientWithResponses, ops HubDownloadOptions) (bool, error) { | ||
p, err := c.GetPluginVersionWithResponse(ctx, ops.PluginTeam, cloudquery_api.PluginKind(ops.PluginKind), ops.PluginName, ops.PluginVersion) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to get plugin information: %w", err) | ||
} | ||
if p.StatusCode() != http.StatusOK { | ||
return false, fmt.Errorf("failed to get plugin information: %s", p.Status()) | ||
} | ||
if p.JSON200 == nil { | ||
return false, fmt.Errorf("failed to get plugin information: response body is empty") | ||
} | ||
return p.JSON200.PackageType == "docker", nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters