Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the CheckExtendedSummaryEntitled API public #1292

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Import the CheckExtendedSummaryEntitled from jfrog-cli
  • Loading branch information
eyalbe4 committed Nov 3, 2024
commit 9db5d13c1d74696cac0295ec58851d8a272caa4d
48 changes: 45 additions & 3 deletions artifactory/utils/commandsummary/commandsummary.go
Original file line number Diff line number Diff line change
@@ -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.
@@ -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) {
Loading