Skip to content

Commit

Permalink
Import the CheckExtendedSummaryEntitled from jfrog-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Nov 3, 2024
1 parent 5f175e0 commit 9db5d13
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions artifactory/utils/commandsummary/commandsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/http/httpclient"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"github.com/jfrog/jfrog-client-go/utils/log"
"os"
"path/filepath"
"strings"
)

// To create a new command summary, the user must implement this interface.
Expand Down Expand Up @@ -272,6 +277,43 @@ func UnmarshalFromFilePath(dataFile string, target any) (err error) {
return
}

func CheckExtendedSummaryEntitled(serverUrl string) (bool, error) {
// Parse and validate the URL
parsedUrl, err := url.Parse(serverUrl)
if err != nil || !parsedUrl.IsAbs() {
return false, fmt.Errorf("invalid server URL: %s", serverUrl)
}

// Construct the full URL
fullUrl := fmt.Sprintf("%sui/api/v1/system/auth/screen/footer", parsedUrl.String())

client, err := httpclient.ClientBuilder().SetRetries(3).Build()
if err != nil {
return false, errorutils.CheckError(err)
}

resp, body, _, err := client.SendGet(fullUrl, false, httputils.HttpClientDetails{}, "")
if err != nil {
fmt.Println("Error making HTTP request:", err)
return false, err
}

if resp.StatusCode != http.StatusOK {
fmt.Println("Non-OK HTTP status:", resp.StatusCode)
return false, nil
}

var result struct {
PlatformId string `json:"platformId"`
}

if err := json.Unmarshal(body, &result); err != nil {
return false, errorutils.CheckError(err)
}
entitled := strings.Contains(strings.ToLower(result.PlatformId), "enterprise")
return entitled, nil
}

// Converts the given data into a byte array.
// Handle specific conversion cases
func convertDataToBytes(data interface{}) ([]byte, error) {
Expand Down

0 comments on commit 9db5d13

Please sign in to comment.