models

package
v0.0.0-...-bc0b533 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2016 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatusMap map[string]string
)

Functions

func GeneratePem

func GeneratePem(privateKey *rsa.PrivateKey) (string, error)

Generate private key in pem format..

func RegisterModel

func RegisterModel(snaphyModel ...interface{})

Types

type Application

type Application struct {
	Id          int
	Name        string               `orm:"unique"`
	Status      string               `orm:"default(active)"`
	Added       time.Time            `orm:"auto_now_add;type(datetime)"`
	LastUpdated time.Time            `orm:"auto_now;type(datetime)"`
	Owner       *User                `orm:"null;rel(fk)"`
	TokenInfo   []*TokenHelper       `orm:"null;reverse(many)"`
	Settings    *ApplicationSettings `orm:"rel(one); null"` // OneToOne relation
}

func (*Application) Activate

func (app *Application) Activate() (num int64, err error)

Deactivate a user account...

func (*Application) Create

func (app *Application) Create() error

Used for creating an application....

func (*Application) Deactivate

func (app *Application) Deactivate() (num int64, err error)

Deactivate a user account...

func (*Application) Delete

func (app *Application) Delete() (num int64, err error)

Only delete a user by ID

func (*Application) FetchAppSettings

func (app *Application) FetchAppSettings() (num int64, err error)

func (*Application) FetchAppTokens

func (app *Application) FetchAppTokens() (num int64, err error)

func (*Application) GetApp

func (app *Application) GetApp() (err error)

Get the application listed whose application id is given..

type ApplicationSettings

type ApplicationSettings struct {
	Id             int
	ExpiryDuration int          //Time in seconds after which it token will expired..
	Added          time.Time    `orm:"auto_now_add;type(datetime)"`
	LastUpdated    time.Time    `orm:"auto_now;type(datetime)"`
	Application    *Application `orm:"reverse(one)"` // Reverse relationship (optional)
}

type GraphApp

type GraphApp struct {
	Name string
	Id   int
}

Writing node model definitons..

func (*GraphApp) AddUniqueConstraint

func (app *GraphApp) AddUniqueConstraint() (err error)

func (*GraphApp) Create

func (app *GraphApp) Create() (err error)

Will merge if node already exists.

func (*GraphApp) CreateIfNotExist

func (app *GraphApp) CreateIfNotExist() (err error)

Will return an error if the node already exists..

func (*GraphApp) Delete

func (app *GraphApp) Delete() (err error)

DELETE ALL DATA INCLUDING ITS NODE TO.. TODO WARNING WHEN PREPARING GRAPHQL END POINT ADD A WEEK TIME AFTER WHICH THIS DATABASE WILL GET DELETED. TODO DEACTIVATE APP WITHIN THIS TIME AND PERMANENTLY DELETE AFTER ONE WEEK TODO ALSO SEND AN EMAIL WARNING DELETING OF DATA.

func (*GraphApp) Exist

func (app *GraphApp) Exist() (exist bool, err error)

Create App in graphDb first find if any global application name is present..

func (*GraphApp) Get

func (app *GraphApp) Get() (exist bool, err error)

Check if app is present of the same name and id..

func (*GraphApp) Read

func (app *GraphApp) Read() (err error)

Read data and populate..app

func (*GraphApp) ReadAll

func (app *GraphApp) ReadAll(appList []*interface{}) (err error)

func (*GraphApp) Update

func (app *GraphApp) Update(err error)

Only name can be updated..throw error if already exists..

type Group

type Group struct {
	Id        string //uuid unique identifier..
	Name      string
	AppId     int
	RealmName string
}

func (*Group) AddUniqueConstraint

func (group *Group) AddUniqueConstraint() (err error)

func (*Group) Create

func (group *Group) Create() (err error)

Create and Merge if exists..

func (*Group) CreateIfNotExist

func (group *Group) CreateIfNotExist() (err error)

Throw error if not exist..

func (*Group) Delete

func (group *Group) Delete() (err error)

func (*Group) Exist

func (group *Group) Exist() (exist bool, err error)

Adding methods for nodeRealm

func (*Group) Read

func (group *Group) Read() (err error)

func (*Group) ReadAll

func (group *Group) ReadAll(groupListInterface []*interface{}) (err error)

func (*Group) Update

func (group *Group) Update() (err error)

type Realm

type Realm struct {
	Name  string //Must be unique among the app
	AppId int
	Id    string //uuid unique identifier..
}

func (*Realm) AddUniqueConstraint

func (realm *Realm) AddUniqueConstraint() (err error)

func (*Realm) Create

func (realm *Realm) Create() (err error)

Merge if exist also create relationship with app..dont create realm without relationship

func (*Realm) CreateIfNotExist

func (realm *Realm) CreateIfNotExist() (err error)

Throw error if not exist..

func (*Realm) CreateTag

func (realm *Realm) CreateTag(tag *TokenTag) (err error)

func (*Realm) Delete

func (realm *Realm) Delete() (err error)

func (*Realm) Exist

func (realm *Realm) Exist() (exist bool, err error)

Adding methods for nodeRealm

func (*Realm) Read

func (realm *Realm) Read() (err error)

Return the realm value

func (*Realm) ReadAll

func (realm *Realm) ReadAll(realmListInterface []*interface{}) (err error)

func (*Realm) Update

func (realm *Realm) Update() (err error)

Update realm name..

type RelIdentity

type RelIdentity struct {
	// contains filtered or unexported fields
}

Writing relationship struct..

type Token

type Token struct {
	IAT    int64  //Issued at
	ISS    int64  //User Identity
	EXP    int64  //Expiry Time
	JTI    string //Unique string identifies a token
	GRP    string //Group
	REALM  string //realm name
	KID    string //AppId its not applicationID but AppId in TokenHelper file to track application.....
	STATUS string //Status showing the token is invalid or what.
}

func (*Token) AddTag

func (token *Token) AddTag(tokenTag *TokenTag) (err error)

Add a tag to token with relationship..

func (*Token) AddUniqueConstraint

func (token *Token) AddUniqueConstraint() (err error)

func (*Token) CheckIfTokenValid

func (token *Token) CheckIfTokenValid(tokenHelper *TokenHelper) (ok bool, err error)

Complete method for checking if the token is valid or not.. Required a parsed token..

func (*Token) CheckTokenExpiry

func (token *Token) CheckTokenExpiry() (ok bool, err error)

This doesn't checks if the main Application is Active or not. Check if token is expired or present in the node or status is invalid or what not ... TRUE IF TOKEN IS VALID AND FALSE IF NOT

func (*Token) Create

func (token *Token) Create() (err error)

Will simply add token data to graph database with depedencies.. token does not support merge create. It will create only if token doesnot exist and will throw an error if it exist..

func (*Token) CreateIfNotExist

func (token *Token) CreateIfNotExist() (err error)

Throw error if not exist..

func (*Token) Delete

func (token *Token) Delete(err error)

Delete the token by JTI value..

func (*Token) Exist

func (token *Token) Exist() (exist bool, err error)

Check if token exist by checking JTI value

func (*Token) GenerateLoginToken

func (token *Token) GenerateLoginToken(previousToken *Token) (err error)

func (*Token) GenerateSignature

func (token *Token) GenerateSignature(tokenHelper *TokenHelper, realm *Realm, group *Group, tag *TokenTag, userIdentity string) (tokenString string, err error)

Create first time Token and Generate Signature.. Generate Signature for the token and Also add tokens to graph Database..

func (*Token) GetTokenHelper

func (token *Token) GetTokenHelper(appId string) (tokenHelper *TokenHelper, err error)

func (*Token) LookUpKey

func (token *Token) LookUpKey(appId string, tokenHelper *TokenHelper) (publicKey []byte, err error)

Find the public key with the provided data..

func (*Token) Read

func (token *Token) Read() (err error)

Read the token by token JTI token..

func (*Token) ReadAll

func (token *Token) ReadAll(tokenTagListInterface []*interface{}) (err error)

Find the token from the database and populate the data.. Provide the nodeToken with jwt field or by userIdentity.

func (*Token) RefreshToken

func (token *Token) RefreshToken(previousToken *Token) (err error)

func (*Token) Update

func (token *Token) Update(err error)

Only update status..

func (*Token) VerifyAndParse

func (loginToken *Token) VerifyAndParse(tokenString string) (valid bool, err error)

Parses the token value..And also validates the algorithm.. Return invalid if any error occures..

func (*Token) VerifyHash

func (token *Token) VerifyHash(tokenString string) (ok bool, err error)

Verify the token before parsing .. the token just checks if the tokens ia a valid one. NOTE: This method just verify the encryption of algorithm and remains silent about expiry of tokens or token not present in the graph.

type TokenHelper

type TokenHelper struct {
	Id          int
	PublicKey   string `orm:"unique;size(2050)"` //Used to decrypt
	PrivateKey  string `orm:"unique;size(2050)"` //Used to envrypt
	HashType    string
	AppSecret   string       `orm:"unique"`
	AppId       string       `orm:"unique"`
	Application *Application `orm:"rel(fk)"`
	Status      string       `orm:"default(active)"`
	Added       time.Time    `orm:"auto_now_add;type(datetime)"`
	LastUpdated time.Time    `orm:"auto_now;type(datetime)"`
}

func (*TokenHelper) CheckAppStatus

func (token *TokenHelper) CheckAppStatus() (ok bool, err error)

Check if app status is expired or not

func (*TokenHelper) Create

func (token *TokenHelper) Create() (id int64, err error)

Used for creating a token.. Only Application

func (*TokenHelper) Delete

func (token *TokenHelper) Delete() (num int64, err error)

Only delete a token by ID

func (*TokenHelper) DownloadPrivateKey

func (token *TokenHelper) DownloadPrivateKey() (err error)

func (*TokenHelper) DownloadPublicKey

func (token *TokenHelper) DownloadPublicKey() (err error)

func (*TokenHelper) FetchTokenHelperApp

func (token *TokenHelper) FetchTokenHelperApp() (num int64, err error)

func (*TokenHelper) GetToken

func (token *TokenHelper) GetToken() (err error)

Method for generating token.. Get token

type TokenTag

type TokenTag struct {
	Id        string //UUID unique identifier..
	AppId     int
	RealmName string
	Name      string //unique among a particular realm and application.
}

func (*TokenTag) AddUniqueConstraint

func (tokenTag *TokenTag) AddUniqueConstraint() (err error)

func (*TokenTag) Create

func (tokenTag *TokenTag) Create() (err error)

func (*TokenTag) CreateIfNotExist

func (tokenTag *TokenTag) CreateIfNotExist() (err error)

func (*TokenTag) Delete

func (tokenTag *TokenTag) Delete() (err error)

func (*TokenTag) Exist

func (tokenTag *TokenTag) Exist() (exist bool, err error)

func (*TokenTag) Read

func (tokenTag *TokenTag) Read() (err error)

func (*TokenTag) ReadAll

func (tokenTag *TokenTag) ReadAll(tokenTagListInterface []*interface{}) (err error)

func (*TokenTag) Update

func (tokenTag *TokenTag) Update() (err error)

type User

type User struct {
	Id          int
	FirstName   string
	LastName    string
	Email       string
	Status      string         `orm:"default(active)"`
	Added       time.Time      `orm:"auto_now_add;type(datetime)"`
	LastUpdated time.Time      `orm:"auto_now;type(datetime)"`
	Apps        []*Application `orm:"null;reverse(many)"`
}

func (*User) Activate

func (user *User) Activate() (int64, error)

Deactivate a user account...

func (*User) Create

func (user *User) Create() (id int64, err error)

Used for registering a user....

func (*User) Deactivate

func (user *User) Deactivate() (int64, error)

Deactivate a user account...

func (*User) Delete

func (user *User) Delete() (num int64, err error)

Only delete a user by ID

func (*User) FetchApps

func (user *User) FetchApps() (num int64, err error)

func (*User) GetCustomUser

func (user *User) GetCustomUser(key string) (err error)

Get user..

func (*User) GetUser

func (user *User) GetUser() (err error)

Get user..

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL