@@ -21,6 +21,9 @@ var ACCAPI = "https://accapi.appbase.io/"
2121// TimeValidity to be obtained from ACCAPI
2222var TimeValidity int64
2323
24+ // Tier is the value of the user's plan
25+ var Tier * Plan
26+
2427// MaxErrorTime before showing errors if invalid trial / plan in hours
2528var MaxErrorTime int64 = 24 // in hrs
2629
@@ -65,7 +68,7 @@ type ArcInstanceDetails struct {
6568 TrialValidity int64 `json:"trial_validity"`
6669 ArcID string `json:"arc_id"`
6770 CreatedAt int64 `json:"created_at"`
68- Tier string `json:"tier"`
71+ Tier * Plan `json:"tier"`
6972 TierValidity int64 `json:"tier_validity"`
7073 TimeValidity int64 `json:"time_validity"`
7174 Metadata map [string ]interface {} `json:"metadata"`
@@ -88,6 +91,18 @@ func BillingMiddleware(next http.Handler) http.Handler {
8891 })
8992}
9093
94+ // Returns the arc instance by ID
95+ func getArcInstanceByID (arcID string , arcInstances []ArcInstanceDetails ) ArcInstanceDetails {
96+ var arcInstance ArcInstanceDetails
97+ for _ , instance := range arcInstances {
98+ if instance .ArcID == arcID {
99+ arcInstance = instance
100+ break
101+ }
102+ }
103+ return arcInstance
104+ }
105+
91106func getArcInstance (arcID string ) (ArcInstance , error ) {
92107 arcInstance := ArcInstance {}
93108 response := ArcInstanceResponse {}
@@ -109,8 +124,10 @@ func getArcInstance(arcID string) (ArcInstance, error) {
109124 }
110125 err = json .Unmarshal (body , & response )
111126 if len (response .ArcInstances ) != 0 {
112- arcInstance .SubscriptionID = response .ArcInstances [0 ].SubscriptionID
113- TimeValidity = response .ArcInstances [0 ].TimeValidity
127+ arcInstanceByID := getArcInstanceByID (arcID , response .ArcInstances )
128+ arcInstance .SubscriptionID = arcInstanceByID .SubscriptionID
129+ TimeValidity = arcInstanceByID .TimeValidity
130+ Tier = arcInstanceByID .Tier
114131 } else {
115132 return arcInstance , errors .New ("No valid instance found for the provided ARC_ID" )
116133 }
@@ -148,7 +165,10 @@ func getArcClusterInstance(clusterID string) (ArcInstance, error) {
148165 return arcInstance , err
149166 }
150167 if len (response .ArcInstances ) != 0 {
151- arcInstance .SubscriptionID = response .ArcInstances [0 ].SubscriptionID
168+ arcInstanceByID := getArcInstanceByID (clusterID , response .ArcInstances )
169+ arcInstance .SubscriptionID = arcInstanceByID .SubscriptionID
170+ TimeValidity = arcInstanceByID .TimeValidity
171+ Tier = arcInstanceByID .Tier
152172 } else {
153173 return arcInstance , errors .New ("No valid instance found for the provided CLUSTER_ID" )
154174 }
@@ -307,7 +327,7 @@ func ReportHostedArcUsage() {
307327 usageBody .Quantity = NodeCount
308328 response , err1 := reportClusterUsageRequest (usageBody )
309329 if err1 != nil {
310- log .Println ("Please contact support@appbase.io with your ARC_ID or registered e-mail address. Usage is not getting reported: " , err1 )
330+ log .Println ("Please contact support@appbase.io with your CLUSTER_ID or registered e-mail address. Usage is not getting reported: " , err1 )
311331 }
312332
313333 // TimeValidity = response.TimeValidity
0 commit comments