-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into centralized-config-implementation
- Loading branch information
Showing
17 changed files
with
384 additions
and
38 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
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,17 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/jfrog/jfrog-client-go/auth" | ||
) | ||
|
||
type metadataDetails struct { | ||
auth.CommonConfigFields | ||
} | ||
|
||
func NewMetadataDetails() auth.ServiceDetails { | ||
return &metadataDetails{} | ||
} | ||
|
||
func (rt *metadataDetails) GetVersion() (string, error) { | ||
panic("Failed: Method is not implemented") | ||
} |
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,45 @@ | ||
package metadata | ||
|
||
import ( | ||
"github.com/jfrog/jfrog-client-go/config" | ||
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient" | ||
"github.com/jfrog/jfrog-client-go/metadata/services" | ||
) | ||
|
||
type Manager interface { | ||
GraphqlQuery(query []byte) ([]byte, error) | ||
} | ||
|
||
type metadataManager struct { | ||
client *jfroghttpclient.JfrogHttpClient | ||
config config.Config | ||
} | ||
|
||
func NewManager(config config.Config) (Manager, error) { | ||
details := config.GetServiceDetails() | ||
var err error | ||
manager := &metadataManager{config: config} | ||
manager.client, err = jfroghttpclient.JfrogClientBuilder(). | ||
SetCertificatesPath(config.GetCertificatesPath()). | ||
SetInsecureTls(config.IsInsecureTls()). | ||
SetClientCertPath(details.GetClientCertPath()). | ||
SetClientCertKeyPath(details.GetClientCertKeyPath()). | ||
AppendPreRequestInterceptor(details.RunPreRequestFunctions). | ||
SetContext(config.GetContext()). | ||
SetDialTimeout(config.GetDialTimeout()). | ||
SetOverallRequestTimeout(config.GetOverallRequestTimeout()). | ||
SetRetries(config.GetHttpRetries()). | ||
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()). | ||
Build() | ||
|
||
return manager, err | ||
} | ||
|
||
func (mm *metadataManager) Client() *jfroghttpclient.JfrogHttpClient { | ||
return mm.client | ||
} | ||
|
||
func (mm *metadataManager) GraphqlQuery(query []byte) ([]byte, error) { | ||
metadataService := services.NewMetadataService(mm.config.GetServiceDetails(), mm.client) | ||
return metadataService.Query(query) | ||
} |
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,45 @@ | ||
package services | ||
|
||
import ( | ||
"fmt" | ||
rtUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" | ||
"github.com/jfrog/jfrog-client-go/auth" | ||
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient" | ||
"github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
const queryUrl = "api/v1/query" | ||
|
||
type Service interface { | ||
Query(query []byte) ([]byte, error) | ||
} | ||
|
||
type metadataService struct { | ||
client *jfroghttpclient.JfrogHttpClient | ||
serviceDetails *auth.ServiceDetails | ||
} | ||
|
||
func NewMetadataService(serviceDetails auth.ServiceDetails, client *jfroghttpclient.JfrogHttpClient) Service { | ||
return &metadataService{serviceDetails: &serviceDetails, client: client} | ||
} | ||
|
||
func (m *metadataService) GetMetadataDetails() auth.ServiceDetails { | ||
return *m.serviceDetails | ||
} | ||
|
||
func (m *metadataService) Query(query []byte) ([]byte, error) { | ||
graphqlUrl, err := url.Parse(m.GetMetadataDetails().GetUrl() + queryUrl) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse URL: %w", err) | ||
} | ||
httpClientDetails := m.GetMetadataDetails().CreateHttpClientDetails() | ||
rtUtils.SetContentType("application/json", &httpClientDetails.Headers) | ||
|
||
resp, body, err := m.client.SendPost(graphqlUrl.String(), query, &httpClientDetails) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
return body, errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK) | ||
} |
Oops, something went wrong.