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

bug fixes in robot account in ground control and fixing unauthorized error while pulling the images #69

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"fmt"

runtime "container-registry.com/harbor-satellite/cmd/container_runtime"
"container-registry.com/harbor-satellite/internal/config"
Expand All @@ -10,6 +11,7 @@ import (
"container-registry.com/harbor-satellite/internal/server"
"container-registry.com/harbor-satellite/internal/utils"
"container-registry.com/harbor-satellite/logger"
"container-registry.com/harbor-satellite/registry"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -95,6 +97,13 @@ func handleRegistrySetup(g *errgroup.Group, log *zerolog.Logger, cancel context.
}
} else {
log.Info().Msg("Launching default registry")
var defaultZotConfig registry.DefaultZotConfig
err := registry.ReadConfig(config.GetZotConfigPath(), &defaultZotConfig)
if err != nil {
return fmt.Errorf("error reading config: %w", err)
}
defaultZotURL := defaultZotConfig.GetLocalRegistryURL()
config.SetRemoteRegistryURL(defaultZotURL)
g.Go(func() error {
if err := utils.LaunchDefaultZotRegistry(); err != nil {
log.Error().Err(err).Msg("Error launching default registry")
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
]
},
"environment_variables": {
"ground_control_url": "",
"ground_control_url": "http://127.0.0.1:8080",
Mehul-Kumar-27 marked this conversation as resolved.
Show resolved Hide resolved
"log_level": "info",
"use_unsecure": true,
"zot_config_path": "./registry/config.json",
Expand Down
28 changes: 28 additions & 0 deletions ground-control/internal/database/groups.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 34 additions & 3 deletions ground-control/internal/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ func (s *Server) registerSatelliteHandler(w http.ResponseWriter, r *http.Request
}

if len(req.Name) < 1 {
log.Println("name should be atleast one character long.")
log.Println("name should be at least one character long.")
err := &AppError{
Message: fmt.Sprintf("Error: name should be atleast one character long."),
Message: "Error: name should be at least one character long.",
Code: http.StatusBadRequest,
}
HandleAppError(w, err)
Expand All @@ -184,7 +184,7 @@ func (s *Server) registerSatelliteHandler(w http.ResponseWriter, r *http.Request

if roboPresent {
err := &AppError{
Message: fmt.Sprintf("Error: Robot Account name already present. Try with different name"),
Message: "Error: Robot Account name already present. Try with different name",
Code: http.StatusBadRequest,
}
HandleAppError(w, err)
Expand Down Expand Up @@ -324,6 +324,37 @@ func (s *Server) registerSatelliteHandler(w http.ResponseWriter, r *http.Request
return
}

// Give permission to the robot account for the projects present in the group list
// fetch all the projects
for i := range *req.Groups {
projects, err := q.GetProjectsOfGroup(r.Context(), (*req.Groups)[i])
if err != nil {
log.Println(err)
err := &AppError{
Message: fmt.Sprintf("Error: fetching projects of group %v", err.Error()),
Code: http.StatusInternalServerError,
}
HandleAppError(w, err)
tx.Rollback()
return
}
project := projects[0]

// give permission to the robot account for all the projects present in this group
_, err = utils.UpdateRobotProjects(r.Context(), project, strconv.FormatInt(rbt.ID, 10))
if err != nil {
log.Println(err)
err := &AppError{
Message: fmt.Sprintf("Error: updating robot account %v", err.Error()),
Code: http.StatusInternalServerError,
}
HandleAppError(w, err)
tx.Rollback()
return
}

}
Mehul-Kumar-27 marked this conversation as resolved.
Show resolved Hide resolved

// Add token to DB
token, err := GenerateRandomToken(32)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions ground-control/sql/queries/groups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ WHERE group_name = $1;
-- name: DeleteGroup :exec
DELETE FROM groups
WHERE id = $1;

-- name: GetProjectsOfGroup :many
SELECT projects FROM groups
WHERE group_name = $1;
Mehul-Kumar-27 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions internal/state/state_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func (f *FetchAndReplicateStateProcess) UpdateFetchProcessConfigFromZtr(username
f.authConfig.SourceRegistryUserName = username
f.authConfig.SourceRegistryPassword = password
f.authConfig.SourceRegistry = utils.FormatRegistryURL(sourceRegistryURL)
f.Replicator = NewBasicReplicator(f.authConfig.SourceRegistryUserName, f.authConfig.SourceRegistryPassword, f.authConfig.SourceRegistry, f.authConfig.RemoteRegistryURL, f.authConfig.RemoteRegistryUserName, f.authConfig.RemoteRegistryPassword, f.authConfig.UseUnsecure)

// The states contain all the states that this satellite needs to track thus we would have to add the new states to the state map
// also we would have to remove the states that are not in the new states
Expand Down
7 changes: 0 additions & 7 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ func HandleOwnRegistry() error {

// LaunchDefaultZotRegistry launches the default Zot registry using the Zot config path
func LaunchDefaultZotRegistry() error {
var defaultZotConfig registry.DefaultZotConfig
err := registry.ReadConfig(config.GetZotConfigPath(), &defaultZotConfig)
if err != nil {
return fmt.Errorf("error reading config: %w", err)
}
defaultZotURL := defaultZotConfig.GetLocalRegistryURL()
config.SetRemoteRegistryURL(defaultZotURL)
launch, err := registry.LaunchRegistry(config.GetZotConfigPath())
if !launch {
return fmt.Errorf("error launching registry: %w", err)
Expand Down
Loading