Skip to content

Commit

Permalink
Merge pull request #4 from EIETS/fix/permission-issue
Browse files Browse the repository at this point in the history
fix: resolve permission issue related to #3
  • Loading branch information
HeZephyr authored Nov 28, 2024
2 parents 10b2d22 + af53672 commit 8182737
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collector

import (
"os"
"crypto/tls"
"encoding/json"
"errors"
Expand Down Expand Up @@ -200,12 +201,27 @@ func (e *Exporter) scrapeQueue() error {

// doRequest sends a GET request to the Bamboo API and returns the response body.
func (e *Exporter) doRequest(endpoint string) ([]byte, error) {
configData, err := os.ReadFile("config.json")
if err != nil {
return nil, fmt.Errorf("error reading config file: %w", err)
}

var config struct {
BambooUsername string `json:"bamboo_username"`
BambooPassword string `json:"bamboo_password"`
}
err = json.Unmarshal(configData, &config)
if err != nil {
return nil, fmt.Errorf("error unmarshaling config file: %w", err)
}

req, err := http.NewRequest("GET", e.URI+endpoint, nil)
if err != nil {
return nil, fmt.Errorf("error creating request: %w", err)
}

req.Header.Set("Accept", "application/json")
req.SetBasicAuth(config.BambooUsername, config.BambooPassword)
resp, err := e.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error performing request: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bamboo_username": "<your_username>",
"bamboo_password": "<your_password>"
}

0 comments on commit 8182737

Please sign in to comment.