-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from gabriel-samfira/add-ca-cert-bundle-metadata
Add root CA bundle metadata URL
- Loading branch information
Showing
9 changed files
with
183 additions
and
17 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
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,52 @@ | ||
// Copyright 2023 Cloudbase Solutions SRL | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. You may obtain | ||
// a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package controllers | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func (a *APIController) InstanceGithubRegistrationTokenHandler(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
||
token, err := a.r.GetInstanceGithubRegistrationToken(ctx) | ||
if err != nil { | ||
handleError(w, err) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
if _, err := w.Write([]byte(token)); err != nil { | ||
log.Printf("failed to encode response: %q", err) | ||
} | ||
} | ||
|
||
func (a *APIController) RootCertificateBundleHandler(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
||
bundle, err := a.r.GetRootCertificateBundle(ctx) | ||
if err != nil { | ||
handleError(w, err) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
if err := json.NewEncoder(w).Encode(bundle); err != nil { | ||
log.Printf("failed to encode response: %q", err) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package runner | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
runnerErrors "github.com/cloudbase/garm-provider-common/errors" | ||
"github.com/cloudbase/garm/auth" | ||
"github.com/cloudbase/garm/params" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func (r *Runner) GetRootCertificateBundle(ctx context.Context) (params.CertificateBundle, error) { | ||
instance, err := auth.InstanceParams(ctx) | ||
if err != nil { | ||
log.Printf("failed to get instance params: %s", err) | ||
return params.CertificateBundle{}, runnerErrors.ErrUnauthorized | ||
} | ||
|
||
poolMgr, err := r.getPoolManagerFromInstance(ctx, instance) | ||
if err != nil { | ||
return params.CertificateBundle{}, errors.Wrap(err, "fetching pool manager for instance") | ||
} | ||
|
||
bundle, err := poolMgr.RootCABundle() | ||
if err != nil { | ||
log.Printf("failed to get root CA bundle: %s", err) | ||
// The root CA bundle is invalid. Return an empty bundle to the runner and log the event. | ||
return params.CertificateBundle{ | ||
RootCertificates: make(map[string][]byte), | ||
}, nil | ||
} | ||
return bundle, 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