diff --git a/internal/products.go b/internal/products.go index e8bb873..5887271 100644 --- a/internal/products.go +++ b/internal/products.go @@ -184,13 +184,17 @@ func RequestProducts(data SUSEConnectData, credentials Credentials, } for _, regCode := range regCodes { - p, err := requestProductsFromRegCodeOrSystem(data, regCode, credentials, installed) - if err != nil { - var emptyProducts []Product - return emptyProducts, err + p, _err := requestProductsFromRegCodeOrSystem(data, regCode, credentials, installed) + if _err != nil { + err = _err + continue } products = append(products, p...) } - return products, nil + if len(products) > 0 { + err = nil + } + + return products, err } diff --git a/internal/subscriptions.go b/internal/subscriptions.go index e5cdc4a..0f86425 100644 --- a/internal/subscriptions.go +++ b/internal/subscriptions.go @@ -22,11 +22,13 @@ import ( "log" "net/http" "net/url" + "strings" ) // Subscription has all the information that we need for SLE subscriptions. type Subscription struct { RegCode string `json:"regcode"` + Status string `json:"status"` } // Request registration codes to the registration server. The `data` and the @@ -76,7 +78,11 @@ func requestRegcodes(data SUSEConnectData, credentials Credentials) ([]string, e } for _, subscription := range subscriptions { - codes = append(codes, subscription.RegCode) + if strings.ToUpper(subscription.Status) != "EXPIRED" { + codes = append(codes, subscription.RegCode) + } else { + loggedError(SubscriptionServerError, "Skipping regCode: %s -- expired.", subscription.RegCode) + } } return codes, err } diff --git a/internal/subscriptions_test.go b/internal/subscriptions_test.go index 4f82b6a..68b5d79 100644 --- a/internal/subscriptions_test.go +++ b/internal/subscriptions_test.go @@ -83,7 +83,7 @@ func TestValidSubscriptions(t *testing.T) { if err != nil { t.Fatal("Unexpected error when reading a valid JSON file") } - if len(subscriptions) != 1 { + if len(subscriptions) != 2 { t.Fatalf("Unexpected number of subscriptions found. Got %d, expected %d", len(subscriptions), 1) } subscriptionHelper(t, subscriptions[0]) @@ -147,6 +147,7 @@ func TestValidRequestForRegcodes(t *testing.T) { if err != nil { t.Fatal("It should've run just fine...") } + // This also tests that we're not including expired regcodes if len(codes) != 1 { t.Fatalf("Unexpected number of products found. Got %d, expected %d", len(codes), 1) } diff --git a/internal/testdata/subscriptions.json b/internal/testdata/subscriptions.json index 2c25469..3f2992f 100644 --- a/internal/testdata/subscriptions.json +++ b/internal/testdata/subscriptions.json @@ -14,5 +14,21 @@ "families": ["sles", "sled"], "systems": [{ "id": 117, "login": "login2", "password": "password2" }], "product_ids": [239, 238, 240] + }, + { + "id": 113, + "regcode": "35098ff7-expired", + "name": "Subscription 3", + "type": null, + "status": "EXPIRED", + "starts_at": "2010-05-14T09:13:26.589Z", + "expires_at": "2014-05-14T09:13:26.589Z", + "system_limit": 1, + "systems_count": 1, + "virtual_count": null, + "product_classes": ["7260"], + "families": ["sles", "sled"], + "systems": [{ "id": 117, "login": "login2", "password": "password2" }], + "product_ids": [239, 238, 240] } ]