From f86659251317c6963076f4e3c41c380a83322ba3 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 27 Dec 2019 21:19:32 -0500 Subject: [PATCH 1/3] add lock on storage --- src/go/storage/storage.go | 50 ++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/go/storage/storage.go b/src/go/storage/storage.go index 264c40d..9771d68 100644 --- a/src/go/storage/storage.go +++ b/src/go/storage/storage.go @@ -9,8 +9,8 @@ import ( "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "io/ioutil" - "time" - "strings" + "strings" + "time" ) // Collection the MongoDB Account collection @@ -39,6 +39,7 @@ func HandleError(e error, serv int) { } func main() { + var status bool type Config struct { MongoDB string `json:"mongoURL"` } @@ -52,11 +53,11 @@ func main() { ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) err = client.Connect(ctx) HandleError(err, 1) - err = client.Ping(context.TODO(), nil) - fmt.Printf("Connected to MongoDB [GO]\n") + err = client.Ping(context.TODO(), nil) + fmt.Printf("Connected to MongoDB [GO]\n") HandleError(err, 1) - Collection = client.Database("cloudservices").Collection("accounts") + Collection = client.Database("cloudservices").Collection("accounts") RedisClient = redis.NewClient(&redis.Options{ Addr: "localhost:6379", @@ -64,36 +65,41 @@ func main() { DB: 0, }) - _, err = RedisClient.Ping().Result() - fmt.Printf("Connected to Redis [GO]\n") + _, err = RedisClient.Ping().Result() + fmt.Printf("Connected to Redis [GO]\n") HandleError(err, 1) + status = false for { fmt.Printf("Calling handler func [GO]\n") - handler() - time.Sleep(1000000 * time.Millisecond) - } + if status == false { + handler(&status) + time.Sleep(1000000 * time.Millisecond) + } + } } -func handler() { +func handler(status* bool) { + *status = true cur, err := Collection.Find(context.TODO(), bson.D{}) HandleError(err, 0) for cur.Next(context.TODO()) { - go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String()) - fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String()) + go checkAccountSizeAndUpdate(cur.Current.Lookup("username").String(), cur.Current.Lookup("id").String()) + fmt.Printf("Checking account information for %s\n", cur.Current.Lookup("username").String()) time.Sleep(600000 * time.Millisecond) } + *status = false } func checkAccountSizeAndUpdate(username string, id string) { - var size float64 = 0 - var userHomeDirectory string = strings.Replace(strings.Join([]string{"/home/", string(username)}, ""), "\"", "", -1) - fmt.Println(userHomeDirectory) - sizeHome := DirSize(&userHomeDirectory) - size += sizeHome - sizeMail := DirSize(&userHomeDirectory) - size += sizeMail - RedisClient.Set("storage"+"-"+string(id), size, 0) - fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f\n", string(username), string(id), size) + var size float64 = 0 + var userHomeDirectory string = strings.Replace(strings.Join([]string{"/home/", string(username)}, ""), "\"", "", -1) + fmt.Println(userHomeDirectory) + sizeHome := DirSize(&userHomeDirectory) + size += sizeHome + sizeMail := DirSize(&userHomeDirectory) + size += sizeMail + RedisClient.Set("storage"+"-"+string(id), size, 0) + fmt.Printf("Set Call | Username: %v, ID: %v | Bytes: %f\n", string(username), string(id), size) } From 609079fc12e7206587378a882d6e61ece296942f Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 27 Dec 2019 21:54:54 -0500 Subject: [PATCH 2/3] rewrite build.sh --- build.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index a243591..8b38d4c 100644 --- a/build.sh +++ b/build.sh @@ -1,6 +1,5 @@ -echo "Library of Code sp-us | Cloud Services" -echo "TypeScript & Go" -echo "Building TS files" -yarn run build -echo "Building Go files" -go build -o dist/intervals/storage src/intervals/storage.go src/intervals/dirsize.go \ No newline at end of file +# This file builds the Go binaries. Hardcoded by LOC Engineering +go build -o dist/bin/storage src/go/storage/storage.go src/go/storage/dirsize.go +file dist/bin/storage +go build -o dist/bin/checkCertificate src/go/checkCertificate/checkCertificate.go +file dist/bin/checkCertificate From f229e4a8251852319029ab7363f4a18cb40fb346 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 27 Dec 2019 21:55:21 -0500 Subject: [PATCH 3/3] add parseCertificate typescript bindings --- src/functions/parseCertificate.ts | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/functions/parseCertificate.ts diff --git a/src/functions/parseCertificate.ts b/src/functions/parseCertificate.ts new file mode 100644 index 0000000..2f45301 --- /dev/null +++ b/src/functions/parseCertificate.ts @@ -0,0 +1,61 @@ +import { Client } from '..'; + +export interface Certificate { + subject: { + commonName: string, + emailAddress: string + organizationName: string, + organizationalUnitName: string, + countryName: string, + }, + issuer: { + commonName: string + emailAddress: null, + organizationName: string, + organizationalUnitName: string, + countryName: string, + }, + extensions: { + keyUsage: '[ Not implemented by executable ]', + extendedKeyUsage: string[], + certificatePolicies: string[], + }, + serial: string, + fingerPrint: string, + signatureAlgorithm: string, + publicKeyAlgorithm: string, + notBefore: Date, + notAfter: Date, +} + +export default async function parseCertificate(client: Client, pathToCertificate: string): Promise { + const result = await client.util.exec(`${__dirname}/../bin/checkCertificate ${pathToCertificate}`); + const parsedObject = JSON.parse(result); + return { + subject: { + commonName: parsedObject.RawParse.Subject.CommonName, + emailAddress: parsedObject.AbstractParse.EmailAddress, + organizationName: parsedObject.RawParse.Subject.Organization[0], + organizationalUnitName: parsedObject.RawParse.Subject.OrganizationalUnit[0], + countryName: parsedObject.RawParse.Subject.Country[0], + }, + issuer: { + commonName: parsedObject.RawParse.Issuer.CommonName, + emailAddress: null, + organizationName: parsedObject.RawParse.Issuer.Organization[0], + organizationalUnitName: parsedObject.RawParse.Issuer.OrganizationalUnit[0], + countryName: parsedObject.RawParse.Issuer.Country[0], + }, + extensions: { + keyUsage: '[ Not implemented by executable ]', + extendedKeyUsage: parsedObject.AbstractParse.ExtendedKeyUsage, + certificatePolicies: parsedObject.AbstractParse.PolicyIdentifiers, + }, + serial: parsedObject.AbstractParse.SerialNumber, + fingerPrint: parsedObject.AbstractParse.FingerPrint, + signatureAlgorithm: parsedObject.AbstractParse.SignatureAlgorithm, + publicKeyAlgorithm: parsedObject.AbstractParse.PublicKeyAlgorithm, + notBefore: new Date(parsedObject.RawParse.NotBefore), + notAfter: new Date(parsedObject.RawParse.NotAfter), + }; +}