This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handleActivitySubscription(snapshot, counter) { | |
const initialLoad = counter === 1; | |
snapshot.docChanges().forEach(function(change) { | |
if (initialLoad) { | |
doSomething(change.doc.data()); | |
} else { | |
doSomethingElse(change.doc.data()); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE apps ( | |
id SERIAL PRIMARY KEY, | |
name character varying, | |
public_key character varying, | |
encrypted_secret_key character varying, | |
created_at timestamp without time zone NOT NULL, | |
updated_at timestamp without time zone NOT NULL | |
); | |
-- enhance query performance and enforce uniqueness | |
CREATE UNIQUE INDEX apps_public_key ON apps(public_key text_ops); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"crypto/rand" | |
) | |
func NewRandomKey() []byte { | |
key := make([]byte, 32) | |
if _, err := rand.Read(key); err != nil { | |
// really, what are you gonna do if randomness failed? | |
panic(err) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"crypto/aes" | |
"crypto/cipher" | |
"crypto/rand" | |
"encoding/hex" | |
"os" | |
) | |
// Decrypt will return the original value of the encrypted string | |
func Decrypt(encryptedKey []byte) ([]byte, error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"crypto/aes" | |
"crypto/cipher" | |
"crypto/rand" | |
"encoding/hex" | |
"os" | |
) | |
// Encrypt will encrypt a raw string to | |
// an encrypted value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cmd | |
import ( | |
"fmt" | |
"os" | |
"github.com/spf13/cobra" | |
) | |
var rootCmd = &cobra.Command{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cmd | |
import ( | |
"fmt" | |
"github.com/omnisyle/goliauth" | |
"github.com/spf13/cobra" | |
) | |
func keyCmd() *cobra.Command { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createApp(cmd *cobra.Command, args []string) { | |
appName := args[0] | |
keyPair := app.CreateApp(appName, db) | |
printResult(keyPair) | |
} | |
func getApp(cmd *cobra.Command, args []string) { | |
publicKey := args[0] | |
keyPair := app.GetApp(publicKey, db) | |
printResult(keyPair) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app | |
import ( | |
"fmt" | |
"github.com/omnisyle/goliauth" | |
) | |
func CreateApp(name, dbURL string) *App { | |
publicKey := goliauth.NewRandomKey() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app | |
import ( | |
"encoding/hex" | |
"fmt" | |
"github.com/omnisyle/goliauth" | |
) | |
func GetApp(publicKey, dbURL string) *App { |