-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactoring the routes and adding groups to the router * simpligying the harbor config * fixing running test cases using dagger run command * adding absolute path flag in test case to configure the path to the c… * adding utils for simplification * fixing the logger contex error and coderabbit fixes * making the secure push compulsory until specified * coderabbit review * fixing the test cases * adding running tests in github workflow
- Loading branch information
1 parent
02ba374
commit 72219c0
Showing
21 changed files
with
844 additions
and
283 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
HARBOR_USERNAME=admin | ||
HARBOR_PASSWORD=Harbor12345 | ||
ZOT_URL="127.0.0.1:8585" | ||
TOKEN="" | ||
TOKEN="" | ||
ENV=dev | ||
USE_UNSECURE=true |
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 |
---|---|---|
|
@@ -28,3 +28,4 @@ dist/ | |
.DS_Store | ||
zot/cache.db | ||
secrets.txt | ||
__debug_bin1949266242 |
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,166 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/joho/godotenv" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var AppConfig *Config | ||
|
||
type Config struct { | ||
log_level string | ||
own_registry bool | ||
own_registry_adr string | ||
own_registry_port string | ||
zot_config_path string | ||
input string | ||
zot_url string | ||
registry string | ||
repository string | ||
user_input string | ||
scheme string | ||
api_version string | ||
image string | ||
harbor_password string | ||
harbor_username string | ||
env string | ||
use_unsecure bool | ||
} | ||
|
||
func GetLogLevel() string { | ||
return AppConfig.log_level | ||
} | ||
|
||
func GetOwnRegistry() bool { | ||
return AppConfig.own_registry | ||
} | ||
|
||
func GetOwnRegistryAdr() string { | ||
return AppConfig.own_registry_adr | ||
} | ||
|
||
func GetOwnRegistryPort() string { | ||
return AppConfig.own_registry_port | ||
} | ||
|
||
func GetZotConfigPath() string { | ||
return AppConfig.zot_config_path | ||
} | ||
|
||
func GetInput() string { | ||
return AppConfig.input | ||
} | ||
|
||
func SetZotURL(url string) { | ||
AppConfig.zot_url = url | ||
} | ||
|
||
func GetZotURL() string { | ||
return AppConfig.zot_url | ||
} | ||
|
||
func SetRegistry(registry string) { | ||
AppConfig.registry = registry | ||
} | ||
|
||
func GetRegistry() string { | ||
return AppConfig.registry | ||
} | ||
|
||
func SetRepository(repository string) { | ||
AppConfig.repository = repository | ||
} | ||
|
||
func GetRepository() string { | ||
return AppConfig.repository | ||
} | ||
|
||
func SetUserInput(user_input string) { | ||
AppConfig.user_input = user_input | ||
} | ||
|
||
func GetUserInput() string { | ||
return AppConfig.user_input | ||
} | ||
|
||
func SetScheme(scheme string) { | ||
AppConfig.scheme = scheme | ||
} | ||
|
||
func GetScheme() string { | ||
return AppConfig.scheme | ||
} | ||
|
||
func SetAPIVersion(api_version string) { | ||
AppConfig.api_version = api_version | ||
} | ||
|
||
func GetAPIVersion() string { | ||
return AppConfig.api_version | ||
} | ||
|
||
func SetImage(image string) { | ||
AppConfig.image = image | ||
} | ||
|
||
func GetImage() string { | ||
return AppConfig.image | ||
} | ||
|
||
func UseUnsecure() bool { | ||
return AppConfig.use_unsecure | ||
} | ||
|
||
func GetHarborPassword() string { | ||
return AppConfig.harbor_password | ||
} | ||
|
||
func GetHarborUsername() string { | ||
return AppConfig.harbor_username | ||
} | ||
|
||
func LoadConfig() (*Config, error) { | ||
viper.SetConfigName("config") | ||
viper.SetConfigType("toml") | ||
viper.AddConfigPath(".") | ||
if err := viper.ReadInConfig(); err != nil { | ||
return nil, fmt.Errorf("error reading config file at path '%s': %w", viper.ConfigFileUsed(), err) | ||
} | ||
|
||
// Load environment and start satellite | ||
if err := godotenv.Load(); err != nil { | ||
return &Config{}, fmt.Errorf("error loading .env file: %w", err) | ||
} | ||
var use_unsecure bool | ||
if os.Getenv("USE_UNSECURE") == "true" { | ||
use_unsecure = true | ||
} else { | ||
use_unsecure = false | ||
} | ||
|
||
return &Config{ | ||
log_level: viper.GetString("log_level"), | ||
own_registry: viper.GetBool("bring_own_registry"), | ||
own_registry_adr: viper.GetString("own_registry_adr"), | ||
own_registry_port: viper.GetString("own_registry_port"), | ||
zot_config_path: viper.GetString("zotConfigPath"), | ||
input: viper.GetString("url_or_file"), | ||
harbor_password: os.Getenv("HARBOR_PASSWORD"), | ||
harbor_username: os.Getenv("HARBOR_USERNAME"), | ||
env: os.Getenv("ENV"), | ||
zot_url: os.Getenv("ZOT_URL"), | ||
use_unsecure: use_unsecure, | ||
}, nil | ||
} | ||
|
||
func InitConfig() error { | ||
var err error | ||
AppConfig, err = LoadConfig() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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,34 @@ | ||
package satellite | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"container-registry.com/harbor-satellite/internal/server" | ||
) | ||
|
||
type SatelliteRegistrar struct{} | ||
|
||
type SatelliteResponse struct { | ||
Success bool `json:"success"` | ||
Message string `json:"message"` | ||
StatusCode int `json:"status_code"` | ||
} | ||
|
||
func (sr *SatelliteRegistrar) RegisterRoutes(router server.Router) { | ||
satelliteGroup := router.Group("/satellite") | ||
satelliteGroup.HandleFunc("/ping", sr.Ping) | ||
} | ||
|
||
func (sr *SatelliteRegistrar) Ping(w http.ResponseWriter, r *http.Request) { | ||
response := SatelliteResponse{ | ||
Success: true, | ||
Message: "Ping satellite successful", | ||
StatusCode: http.StatusOK, | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
if err := json.NewEncoder(w).Encode(response); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
} |
Oops, something went wrong.