1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
package api
import (
"context"
"net/url"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/api"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/gitlab"
)
const (
VerifyProjectAccessAPIPath = "/api/v4/internal/kubernetes/verify_project_access"
)
func VerifyProjectAccess(ctx context.Context, client gitlab.ClientInterface, agentToken api.AgentToken, projectID string, opts ...gitlab.DoOption) (bool, error) {
err := client.Do(ctx,
joinOpts(opts,
gitlab.WithPath(VerifyProjectAccessAPIPath),
gitlab.WithQuery(url.Values{
ProjectIDQueryParam: []string{projectID},
}),
gitlab.WithAgentToken(agentToken),
gitlab.WithResponseHandler(gitlab.NoContentResponseHandler()),
gitlab.WithJWT(true),
)...,
)
if err == nil {
return true, nil
}
if gitlab.IsForbidden(err) || gitlab.IsUnauthorized(err) || gitlab.IsNotFound(err) {
return false, nil
}
return false, err
}
|