Skip to content

Commit

Permalink
Add metadata URLs
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Aug 23, 2023
1 parent 99b2b7c commit ce3cc9c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
7 changes: 5 additions & 2 deletions apiserver/controllers/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ func (a *APIController) JITCredentialsFileHandler(w http.ResponseWriter, r *http
return
}

data, err := a.r.GetJITConfigFile(ctx, fileName)
dotFileName := fmt.Sprintf(".%s", fileName)

data, err := a.r.GetJITConfigFile(ctx, dotFileName)
if err != nil {
log.Printf("getting JIT config file: %s", err)
handleError(w, err)
return
}

// Note the leading dot in the filename
name := fmt.Sprintf("attachment; filename=.%s", fileName)
name := fmt.Sprintf("attachment; filename=%s", dotFileName)
w.Header().Set("Content-Disposition", name)
w.Header().Set("Content-Type", "octet-stream")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(data)))
Expand Down
8 changes: 4 additions & 4 deletions apiserver/routers/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func NewAPIRouter(han *controllers.APIController, logWriter io.Writer, authMiddl
metadataRouter.Handle("/credentials/{fileName}/", http.HandlerFunc(han.JITCredentialsFileHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/credentials/{fileName}", http.HandlerFunc(han.JITCredentialsFileHandler)).Methods("GET", "OPTIONS")
// Systemd files
metadataRouter.Handle("/systemd/service-name/", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/service-name/", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/runner-service/", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/runner-service", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/system/service-name/", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/system/service-name", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/unit-file/", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/unit-file", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS")

// Login
authRouter := apiSubRouter.PathPrefix("/auth").Subrouter()
Expand Down
4 changes: 3 additions & 1 deletion runner/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ func validateInstanceState(ctx context.Context) (params.Instance, error) {
func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) {
instance, err := validateInstanceState(ctx)
if err != nil {
log.Printf("failed to get instance params: %s", err)
return "", runnerErrors.ErrUnauthorized
}

pool, err := r.store.GetPoolByID(r.ctx, instance.PoolID)
if err != nil {
log.Printf("failed to get pool: %s", err)
return "", errors.Wrap(err, "fetching pool")
}

Expand Down Expand Up @@ -113,7 +115,7 @@ func (r *Runner) GetJITConfigFile(ctx context.Context, file string) ([]byte, err
jitConfig := instance.JitConfiguration
contents, ok := jitConfig[file]
if !ok {
return nil, fmt.Errorf("file not found: %w", runnerErrors.ErrNotFound)
return nil, errors.Wrap(runnerErrors.ErrNotFound, "retrieving file")
}

decoded, err := base64.StdEncoding.DecodeString(contents)
Expand Down

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

0 comments on commit ce3cc9c

Please sign in to comment.