Skip to content

Commit

Permalink
readme updates, use config keys, cleanup compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dagbay-rh committed Aug 23, 2023
1 parent 06d2e77 commit 5a340c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Entitlements Service

Entitlements service serves as a proxy to various backend redhat IT services. It performs the following functions:
Entitlements service serves as a proxy to various backend Red Hat IT services. It performs the following functions:
* `/subscriptions`: query IT for a list of subscriptions that a user is entitled to
* `/compliance`: query IT for user compliance checks
* `/seats`: query AMS from OCM to read, assign, and delete user subscriptions (a seat is considered an openshift subscription assignable to a user)
* `/seats`: query AMS from OCM to read, assign, and delete user subscriptions (a seat is considered an Openshift subscription assignable to a user)

## SKU/Bundle changes
- The `/bundles/bundles.example.yml` file in this repo is for **local testing only**
Expand Down
21 changes: 9 additions & 12 deletions bundle_sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand All @@ -14,7 +14,6 @@ import (
"time"

"github.com/RedHatInsights/entitlements-api-go/config"
cfg "github.com/RedHatInsights/entitlements-api-go/config"
t "github.com/RedHatInsights/entitlements-api-go/types"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
Expand All @@ -26,7 +25,7 @@ func assertEq(test []string, ans []string) bool {
}

// getClient sets up the http client for the subscriptions API
func getClient(cfg *cfg.EntitlementsConfig) *http.Client {
func getClient(cfg *config.EntitlementsConfig) *http.Client {

tlsConfig := &tls.Config{
Certificates: []tls.Certificate{*cfg.Certs},
Expand Down Expand Up @@ -60,7 +59,7 @@ func getCurrent(client *http.Client, url string) (t.SubModel, error) {
}
defer resp.Body.Close()

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return t.SubModel{}, err
}
Expand All @@ -74,7 +73,7 @@ func getCurrent(client *http.Client, url string) (t.SubModel, error) {
}

func getUpdates(cfg *viper.Viper) ([]t.Bundle, error) {
bundlesYaml, err := ioutil.ReadFile(cfg.GetString("BUNDLE_INFO_YAML"))
bundlesYaml, err := os.ReadFile(cfg.GetString(config.Keys.BundleInfoYaml))
if err != nil {
return []t.Bundle{}, err
}
Expand All @@ -90,7 +89,7 @@ func getUpdates(cfg *viper.Viper) ([]t.Bundle, error) {
}

func postUpdates(cfg *viper.Viper, client *http.Client, data []byte) error {
url := fmt.Sprintf("%s%s%s", cfg.GetString("SUBS_HOST"), cfg.GetString("SUB_API_BASE_PATH"), "features/")
url := fmt.Sprintf("%s%s%s", cfg.GetString(config.Keys.SubsHost), cfg.GetString(config.Keys.SubAPIBasePath), "features/")
req, err := client.Post(url, "application/json", strings.NewReader(string(data)))
if err != nil {
return err
Expand All @@ -102,17 +101,17 @@ func postUpdates(cfg *viper.Viper, client *http.Client, data []byte) error {
}

func main() {
c := cfg.GetConfig()
c := config.GetConfig()
client := getClient(c)
options := c.Options
runSync := options.GetBool(cfg.Keys.RunBundleSync)
runSync := options.GetBool(config.Keys.RunBundleSync)

if !runSync {
fmt.Println("Bundle sync disabled")
return
}

endpoints := strings.Split(c.Options.GetString(cfg.Keys.Features), ",")
endpoints := strings.Split(c.Options.GetString(config.Keys.Features), ",")
for _, endpoint := range endpoints {
skus := make(map[string][]string)
current_skus := make(map[string][]string)
Expand All @@ -133,9 +132,7 @@ func main() {
}
for _, v := range sku_updates {
if v.Name == endpoint {
for _, sku := range v.Skus {
skus[endpoint] = append(skus[endpoint], sku)
}
skus[endpoint] = append(skus[endpoint], v.Skus...)
}
}

Expand Down

0 comments on commit 5a340c9

Please sign in to comment.