github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/getrepository.go (about)

     1  package services
     2  
     3  import (
     4  	"encoding/json"
     5  	"errors"
     6  	"net/http"
     7  
     8  	rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient"
     9  	"github.com/cobalt77/jfrog-client-go/auth"
    10  	clientutils "github.com/cobalt77/jfrog-client-go/utils"
    11  	"github.com/cobalt77/jfrog-client-go/utils/errorutils"
    12  	"github.com/cobalt77/jfrog-client-go/utils/log"
    13  )
    14  
    15  type GetRepositoryService struct {
    16  	client     *rthttpclient.ArtifactoryHttpClient
    17  	ArtDetails auth.ServiceDetails
    18  }
    19  
    20  func NewGetRepositoryService(client *rthttpclient.ArtifactoryHttpClient) *GetRepositoryService {
    21  	return &GetRepositoryService{client: client}
    22  }
    23  
    24  func (grs *GetRepositoryService) Get(repoKey string) (*RepositoryDetails, error) {
    25  	httpClientsDetails := grs.ArtDetails.CreateHttpClientDetails()
    26  	log.Info("Getting repository '" + repoKey + "' details ...")
    27  	repoDetails := &RepositoryDetails{}
    28  	resp, body, _, err := grs.client.SendGet(grs.ArtDetails.GetUrl()+"api/repositories/"+repoKey, true, &httpClientsDetails)
    29  	if err != nil {
    30  		return &RepositoryDetails{}, err
    31  	}
    32  	if resp.StatusCode != http.StatusOK {
    33  		return &RepositoryDetails{}, errorutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + clientutils.IndentJson(body)))
    34  	}
    35  	if err := json.Unmarshal(body, &repoDetails); err != nil {
    36  		return repoDetails, errorutils.CheckError(err)
    37  	}
    38  	log.Debug("Artifactory response:", resp.Status)
    39  	log.Info("Done getting repository details.")
    40  	return repoDetails, nil
    41  }
    42  
    43  type RepositoryDetails struct {
    44  	Key         string
    45  	Rclass      string
    46  	Description string
    47  	Url         string
    48  	PackageType string
    49  }