Add metadata URLs

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2023-08-22 15:08:58 +00:00
parent 1268507ce6
commit e53c271337
4 changed files with 13 additions and 8 deletions

View file

@ -55,14 +55,17 @@ func (a *APIController) JITCredentialsFileHandler(w http.ResponseWriter, r *http
return return
} }
data, err := a.r.GetJITConfigFile(ctx, fileName) dotFileName := fmt.Sprintf(".%s", fileName)
data, err := a.r.GetJITConfigFile(ctx, dotFileName)
if err != nil { if err != nil {
log.Printf("getting JIT config file: %s", err)
handleError(w, err) handleError(w, err)
return return
} }
// Note the leading dot in the filename // 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-Disposition", name)
w.Header().Set("Content-Type", "octet-stream") w.Header().Set("Content-Type", "octet-stream")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(data))) w.Header().Set("Content-Length", fmt.Sprintf("%d", len(data)))

View file

@ -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")
metadataRouter.Handle("/credentials/{fileName}", http.HandlerFunc(han.JITCredentialsFileHandler)).Methods("GET", "OPTIONS") metadataRouter.Handle("/credentials/{fileName}", http.HandlerFunc(han.JITCredentialsFileHandler)).Methods("GET", "OPTIONS")
// Systemd files // Systemd files
metadataRouter.Handle("/systemd/service-name/", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS") metadataRouter.Handle("/system/service-name/", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/service-name/", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS") metadataRouter.Handle("/system/service-name", http.HandlerFunc(han.SystemdServiceNameHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/runner-service/", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS") metadataRouter.Handle("/systemd/unit-file/", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/systemd/runner-service", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS") metadataRouter.Handle("/systemd/unit-file", http.HandlerFunc(han.SystemdUnitFileHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/system/cert-bundle/", http.HandlerFunc(han.RootCertificateBundleHandler)).Methods("GET", "OPTIONS") metadataRouter.Handle("/system/cert-bundle/", http.HandlerFunc(han.RootCertificateBundleHandler)).Methods("GET", "OPTIONS")
metadataRouter.Handle("/system/cert-bundle", http.HandlerFunc(han.RootCertificateBundleHandler)).Methods("GET", "OPTIONS") metadataRouter.Handle("/system/cert-bundle", http.HandlerFunc(han.RootCertificateBundleHandler)).Methods("GET", "OPTIONS")

View file

@ -53,11 +53,13 @@ func validateInstanceState(ctx context.Context) (params.Instance, error) {
func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) { func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) {
instance, err := validateInstanceState(ctx) instance, err := validateInstanceState(ctx)
if err != nil { if err != nil {
log.Printf("failed to get instance params: %s", err)
return "", runnerErrors.ErrUnauthorized return "", runnerErrors.ErrUnauthorized
} }
pool, err := r.store.GetPoolByID(r.ctx, instance.PoolID) pool, err := r.store.GetPoolByID(r.ctx, instance.PoolID)
if err != nil { if err != nil {
log.Printf("failed to get pool: %s", err)
return "", errors.Wrap(err, "fetching pool") return "", errors.Wrap(err, "fetching pool")
} }
@ -113,7 +115,7 @@ func (r *Runner) GetJITConfigFile(ctx context.Context, file string) ([]byte, err
jitConfig := instance.JitConfiguration jitConfig := instance.JitConfiguration
contents, ok := jitConfig[file] contents, ok := jitConfig[file]
if !ok { 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) decoded, err := base64.StdEncoding.DecodeString(contents)

2
vendor/modules.txt vendored
View file

@ -439,5 +439,5 @@ gorm.io/gorm/logger
gorm.io/gorm/migrator gorm.io/gorm/migrator
gorm.io/gorm/schema gorm.io/gorm/schema
gorm.io/gorm/utils gorm.io/gorm/utils
# github.com/cloudbase/garm-provider-common => /home/ubuntu/garm-provider-common
# github.com/google/go-github/v54 => github.com/gabriel-samfira/go-github/v54 v54.0.0-20230821112832-bbb536ee5a3a # github.com/google/go-github/v54 => github.com/gabriel-samfira/go-github/v54 v54.0.0-20230821112832-bbb536ee5a3a
# github.com/cloudbase/garm-provider-common => /home/ubuntu/garm-provider-common