merge-requests/2/merge
Bsian 2019-12-28 03:12:22 +00:00
commit 9a47286889
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
3 changed files with 94 additions and 28 deletions

View File

@ -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
# 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

View File

@ -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<Certificate> {
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),
};
}

View File

@ -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)
}