Documentation ¶
Overview ¶
Copyright 2020 Pantacor Ltd.
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.
Copyright 2020 Pantacor Ltd.
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.
Copyright 2020 Pantacor Ltd.
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.
Index ¶
- Constants
- Variables
- type App
- type Subscription
- type SubscriptionMgo
- func (i SubscriptionMgo) Cancel(ctx context.Context, issuer utils.Prn) error
- func (i SubscriptionMgo) GetHistory() []Subscription
- func (i SubscriptionMgo) GetID() string
- func (i SubscriptionMgo) GetIssuer() utils.Prn
- func (i SubscriptionMgo) GetPeriodEnd() time.Time
- func (i SubscriptionMgo) GetPeriodProgression() float64
- func (i SubscriptionMgo) GetPeriodStart() time.Time
- func (i SubscriptionMgo) GetPlan() utils.Prn
- func (i SubscriptionMgo) GetPrn() utils.Prn
- func (i SubscriptionMgo) GetProperty(key string) interface{}
- func (i SubscriptionMgo) GetService() utils.Prn
- func (i SubscriptionMgo) GetSubject() utils.Prn
- func (i SubscriptionMgo) GetTimeCreated() time.Time
- func (i SubscriptionMgo) GetTimeModified() time.Time
- func (i SubscriptionMgo) HasProperty(key string) bool
- func (i SubscriptionMgo) IsCancelled() bool
- func (i SubscriptionMgo) IsLocked() bool
- func (i SubscriptionMgo) Lock(ctx context.Context, issuer utils.Prn) error
- func (i SubscriptionMgo) UpdatePlan(ctx context.Context, issuer utils.Prn, plan utils.Prn, ...) error
- type SubscriptionPage
- type SubscriptionReq
- type SubscriptionService
Constants ¶
const ( // SubscriptionTypeCustom custom subscription SubscriptionTypeCustom = utils.Prn("prn::subscriptions:CUSTOM") // SubscriptionTypeCancelled canceled subscription SubscriptionTypeCancelled = utils.Prn("prn::subscriptions:CANCELLED") // SubscriptionTypeStripe stripe subscription SubscriptionTypeStripe = utils.Prn("prn::subscriptions:stripe") // SubscriptionTypeLocked locked subscription SubscriptionTypeLocked = utils.Prn("prn::subscriptions:LOCKED") // SubscriptionTypePrefix prefix for all subscription SubscriptionTypePrefix = utils.Prn("prn::subscriptions:") // SubscriptionTypeFree free subscription SubscriptionTypeFree = utils.Prn(SubscriptionTypePrefix + "FREE") // SubscriptionTypeVIP vip subscription SubscriptionTypeVIP = utils.Prn(SubscriptionTypePrefix + "VIP") )
Variables ¶
var ( // SubscriptionProperties define the subscriptions capabilities SubscriptionProperties = map[utils.Prn]interface{}{ SubscriptionTypeFree: map[string]interface{}{ "OBJECTS": "2GiB", "BANDWIDTH": "2GiB", "DEVICES": "25", }, SubscriptionTypeVIP: map[string]interface{}{ "OBJECTS": "20GiB", "BANDWIDTH": "10GiB", "DEVICES": "100", }, SubscriptionTypeLocked: nil, SubscriptionTypeCancelled: nil, SubscriptionTypeCustom: map[string]interface{}{ "OBJECTS": "0GiB", "BANDWIDTH": "0GiB", "DEVICES": "0", }, SubscriptionTypeStripe: map[string]interface{}{ "OBJECTS": "0GiB", "BANDWIDTH": "0GiB", "DEVICES": "0", }, } )
Functions ¶
This section is empty.
Types ¶
type App ¶
App subscription rest application
func New ¶
func New(jwtMiddleware *jwt.JWTMiddleware, subscriptionService SubscriptionService, mongoClient *mongo.Client) *App
New create a new subscription rest application
type Subscription ¶
type Subscription interface { GetID() string GetPrn() utils.Prn GetPlan() utils.Prn GetIssuer() utils.Prn GetSubject() utils.Prn GetService() utils.Prn GetTimeModified() time.Time GetTimeCreated() time.Time GetPeriodStart() time.Time GetPeriodEnd() time.Time GetPeriodProgression() float64 HasProperty(key string) bool GetProperty(key string) interface{} IsLocked() bool IsCancelled() bool GetHistory() []Subscription // UpdatePlan changes plan for subscription to plan PRN. If not nil, // attrs will overload the defaults that come with plan. UpdatePlan(ctx context.Context, issuer utils.Prn, plan utils.Prn, attrs map[string]interface{}) error Cancel(ctx context.Context, issuer utils.Prn) error Lock(ctx context.Context, issuer utils.Prn) error }
Subscription define a subscription interface
type SubscriptionMgo ¶
type SubscriptionMgo struct { // The ID for the subscription in mongo ID string `json:"id" bson:"_id"` // The Prn of the subscription Prn utils.Prn `json:"prn" bson:"prn"` // The Type of the subscription in PRN format Type utils.Prn `json:"type" bson:"type"` // the subject of a subscription (service consumer!) Subject utils.Prn `json:"subject" bson:"subject"` // the issuer of a subscription (service operator!) Issuer utils.Prn `json:"issuer" bson:"issuer"` // the service a subscription is valid for (e.g. prn::services:/pantahub-base) Service utils.Prn `json:"service" bson:"service"` // the time this subscription was modified. LastModified time.Time `json:"last-modified" bson:"last-modified"` // the time this subscription was modified. TimeCreated time.Time `json:"time-created" bson:"time-created"` // History log in cronological order (earliest first) . Max history is not implemented rightnow.. History []SubscriptionMgo `json:"history,omitempty" bson:"history,omitempty"` Attributes map[string]interface{} `json:"attr,omitempty" bson:"attr,omitempty"` // contains filtered or unexported fields }
SubscriptionMgo define Subscription mongo payload
func (SubscriptionMgo) GetHistory ¶
func (i SubscriptionMgo) GetHistory() []Subscription
GetHistory get the history of a subscription
func (SubscriptionMgo) GetIssuer ¶
func (i SubscriptionMgo) GetIssuer() utils.Prn
GetIssuer get subscription issuer
func (SubscriptionMgo) GetPeriodEnd ¶
func (i SubscriptionMgo) GetPeriodEnd() time.Time
GetPeriodEnd get when the current period end
func (SubscriptionMgo) GetPeriodProgression ¶
func (i SubscriptionMgo) GetPeriodProgression() float64
GetPeriodProgression get the progression of the current period
func (SubscriptionMgo) GetPeriodStart ¶
func (i SubscriptionMgo) GetPeriodStart() time.Time
GetPeriodStart get when the current period of the subscription started
func (SubscriptionMgo) GetPlan ¶
func (i SubscriptionMgo) GetPlan() utils.Prn
GetPlan get subscription type
func (SubscriptionMgo) GetPrn ¶
func (i SubscriptionMgo) GetPrn() utils.Prn
GetPrn get subscription PRN
func (SubscriptionMgo) GetProperty ¶
func (i SubscriptionMgo) GetProperty(key string) interface{}
GetProperty get a subscription property
func (SubscriptionMgo) GetService ¶
func (i SubscriptionMgo) GetService() utils.Prn
GetService get subscription service
func (SubscriptionMgo) GetSubject ¶
func (i SubscriptionMgo) GetSubject() utils.Prn
GetSubject get subscription subject
func (SubscriptionMgo) GetTimeCreated ¶
func (i SubscriptionMgo) GetTimeCreated() time.Time
GetTimeCreated Get the time when the subscription was created
func (SubscriptionMgo) GetTimeModified ¶
func (i SubscriptionMgo) GetTimeModified() time.Time
GetTimeModified last time the subscription was modified
func (SubscriptionMgo) HasProperty ¶
func (i SubscriptionMgo) HasProperty(key string) bool
HasProperty check if a subscription has a specific property
func (SubscriptionMgo) IsCancelled ¶
func (i SubscriptionMgo) IsCancelled() bool
IsCancelled check if the subscription is cancelled
func (SubscriptionMgo) IsLocked ¶
func (i SubscriptionMgo) IsLocked() bool
IsLocked check if the subscription is locked
type SubscriptionPage ¶
type SubscriptionPage struct { Start int Page int Size int Subs []Subscription }
SubscriptionPage pagination for subscription
type SubscriptionReq ¶
type SubscriptionReq struct { Subject utils.Prn `json:"subject"` Plan utils.Prn `json:"plan"` Attrs map[string]interface{} `json:"attrs"` }
SubscriptionReq subscription request
type SubscriptionService ¶
type SubscriptionService interface { // Delete Subscription Delete(pctx context.Context, sub Subscription) error New( pctx context.Context, Subject utils.Prn, Issuer utils.Prn, Type utils.Prn, schema map[string]interface{}) (Subscription, error) // Check if user prn is in admins set for this instance IsAdmin(user utils.Prn) bool // Load subscription by ID Load(pctx context.Context, ID string) (Subscription, error) // Load subscription by ID LoadBySubject(pctx context.Context, subject utils.Prn) (Subscription, error) // Load subscription by ID GetDefaultSubscription(subject utils.Prn) Subscription // List subscription by owning "subject" List(pctx context.Context, Subject utils.Prn, start, page int) (SubscriptionPage, error) // Save subscription Save(pctx context.Context, sub Subscription) error // Now time Now() time.Time }
SubscriptionService Interface offers primitives for loading, listing, saving and deleting of subscriptions.