Example #1
0
        public void getVaultObject(VaultObject vaultObject)
        {
            try {
                String tableName = tableNameFromPluginName(vaultObject.getPluginName());
                String query = "select id \"id\",";
                query += "objectName \"objectName\", xml \"xml\"";
                query += " from " + tableName;
                query += " where objectName = \"" + vaultObject.getObjectName() + "\"";

                // use passport info if present
                if (vaultObject.getPassport() != null) {
                    String username = vaultObject.getPassport().getUser().username;
                    query += " and passportUsername = \"" + username + "\"";
                } else {
                    query += " and passportUsername ISNULL";
                }

                debug(query);

                DataTable results = database.GetDataTable(query);
                // there should only ever be one copy of an object in the database
                DataRow row = results.Rows[0];
                vaultObject.fromDataRow(row);
            } catch (Exception e) {
                throw new VaultObjectNotFoundException();
            }
        }
Example #2
0
        public int getVaultObjectId(VaultObject vaultObject)
        {
            int id = -1;
            try {
                String tableName = tableNameFromPluginName(vaultObject.getPluginName());
                String query = "select id \"id\"";
                query += " from " + tableName;
                query += " where objectName = \"" + vaultObject.getObjectName() + "\"";

                // use passport info if present
                if (vaultObject.getPassport() != null) {
                    String username = vaultObject.getPassport().getUser().username;
                    query += " and passportUsername = \"" + username + "\"";
                } else {
                    query += " and passportUsername ISNULL";
                }
                debug(query);

                DataTable results = database.GetDataTable(query);
                // there should only ever be one copy of an object in the database
                DataRow row = results.Rows[0];
                id = Int32.Parse(row["id"].ToString());
            } catch (Exception e) {
                id = -1;
            }
            return id;
        }
Example #3
0
        //
        // API
        //
        public void store(VaultObject vaultObject)
        {
            try {
                String tableName = tableNameFromPluginName(vaultObject.getPluginName());
                createTable(tableName);

                Dictionary<string, string > dataDictionary = vaultObject.getDataDictionary();
                int id = this.getVaultObjectId(vaultObject);
                if (id == -1) {
                    System.Console.WriteLine("insert");
                    DateTime now = System.DateTime.Now;
                    dataDictionary["created"] = now.ToString();
                    dataDictionary["updated"] = now.ToString();
                    database.Insert(tableName, dataDictionary);
                } else {
                    System.Console.WriteLine("update");
                    DateTime now = System.DateTime.Now;
                    dataDictionary["updated"] = now.ToString();
                    String idString = tableName + ".id = " + id;
                    database.Update(tableName, dataDictionary, idString);
                }
                vaultObject.setId(this.getVaultObjectId(vaultObject));
            } catch (Exception e) {
                log(e.Message);
            }
        }