-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update handlers and registry adapters
Signed-off-by: bupd <[email protected]>
- Loading branch information
Showing
14 changed files
with
128 additions
and
250 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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,66 @@ | ||
package reg | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type AppError struct { | ||
Message string `json:"message"` | ||
Code int `json:"code"` | ||
} | ||
type Image struct { | ||
Digest string | ||
Name string | ||
} | ||
|
||
type TagListResponse struct { | ||
Name string `json:"name"` | ||
Tags []string `json:"tags"` | ||
} | ||
|
||
func FetchRepos(username, password, url string) ([]string, error) { | ||
// Sample Data | ||
// username := "admin" | ||
// password := "Harbor12345" | ||
// url := "https://demo.goharbor.io" | ||
|
||
url = url + "/v2/_catalog?n=1000" | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create request: %v", err) | ||
} | ||
|
||
// Encode credentials for Basic Authentication | ||
auth := base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) | ||
req.Header.Set("Authorization", "Basic "+auth) | ||
|
||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to make request: %v", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Check the response status code | ||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("failed to fetch catalog: %s", resp.Status) | ||
} | ||
|
||
// Read the response body and decode JSON | ||
var result map[string][]string | ||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal JSON response: %w", err) | ||
} | ||
|
||
// Extract the list of repositories | ||
repos, ok := result["repositories"] | ||
if !ok { | ||
return nil, fmt.Errorf("repositories not found in response") | ||
} | ||
|
||
return repos, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.