Could not subscribe to salesforce with API_VERSION 48 from restforce - ruby-on-rails-5

I am currently subscribing for 2 topics one for Account and another for Contacts. I am successfully able to subscribe to both topics with api_version 26 (default version used by restforce), but I don't get events for delete actions with this api_version.
Gems used:
gem 'cookiejar', git: 'https://github.com/MissionCapital/cookiejar.git'
gem 'faye', '0.8.9'
gem 'restforce', '~> 4.2.2'
code:
#client = Restforce.new(username: ENV['SF_USERNAME'],
password: ENV['SF_PASSWORD'],
security_token: ENV['SF_SECURITY_TOKEN'],
client_id: ENV['SF_CLIENT_ID'],
client_secret: ENV['SF_SECRET_ID'])
PushTopic
#client.create!('PushTopic',
ApiVersion: '48.0',
Name: ENV['CONTACT_PUSH_TOPIC_NAME'],
Description: 'all contact records',
NotifyForOperations: 'All',
NotifyForFields: 'All',
Query: 'select Id, FirstName, LastName, Title, Email, Phone, MobilePhone, OtherPhone, AccountId, OwnerId, IsDeleted from Contact')
This results in the client being in version with 26.0 of the salesforce.
NOW, change to salesforce api_verison 48.0
#client = Restforce.new(username: ENV['SF_USERNAME'],
password: ENV['SF_PASSWORD'],
security_token: ENV['SF_SECURITY_TOKEN'],
client_id: ENV['SF_CLIENT_ID'],
client_secret: ENV['SF_SECRET_ID'],
api_version: '48.0')
Pushtopic
#client.create!('PushTopic',
ApiVersion: '48.0',
Name: ENV['CONTACT_PUSH_TOPIC_NAME'],
Description: 'all contact records',
NotifyForOperationCreate: 'true',
NotifyForOperationUpdate: 'true',
NotifyForOperationDelete: 'true',
NotifyForOperationUndelete: 'true',
NotifyForFields: 'All',
Query: 'select Id, FirstName, LastName, Title, Email, Phone, MobilePhone, AccountId, OwnerId, IsDeleted from Contact')
For this client, it doesn't receive any events. not for any actions (create, update, or delete).
Issue filed on Github. link: https://github.com/restforce/restforce/issues/537

Answer: We need to use replay for working with higher versions. It doesn't subscribe without replay.
EM.run do
#client.subscription "/topic/topicName", replay: -2 do |message|
puts message["sobject"]
end
end

Related

Explain this with example

HP#LAPTOP-ASEAM8KR MINGW64 ~/Desktop/udemy_laravel/blog
$ php artisan tinker
Psy Shell v0.11.2 (PHP 8.1.4 — cli) by Justin Hileman
$posts = App\Models\Post::create([ 'user_id'=> 0, 'title'=>"this is a cat", 'content'=>"cat is a pet animal" ]);
Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert i
nto posts (title, content, updated_at, created_at) values (this is a cat, cat is a pet animal, 2022-05-11 20:43:23, 2022-05-11 20:43:23
))'
$posts = App\Models\Post::insert([ 'user_id'=> 0, 'title'=>"this is a cat", 'content'=>"cat is a pet animal" ]);
but this command insert the data in the database file post table without add user_id in the fillable property. How can possible? please explain......i am only change after the scope resolution operator insert in the place of create.

Output only certain values from nvarchar column using select statement

I have a SQL database that's filled with all kind of logging information, including full Description of Windows Event Logs. This Description is a nvarchar column which consists of information that looks like this:
An account failed to log on.
Subject:
Security ID: S-1-5-18
Account Name: XXX-XXX01$
Account Domain: XXX
Logon ID: 0x3E7
Logon Type: 8
Account For Which Logon Failed:
Security ID: S-1-0-0
Account Name: username
Account Domain: domain
Failure Information:
Failure Reason: Unknown user name or bad password.
Status: 0xC000006D
Sub Status: 0xC0000064
Process Information:
Caller Process ID: 0x1111
Caller Process Name: C:\Windows\System32\inetsrv\w3wp.exe
Network Information:
Workstation Name: XXX-XXX04
Source Network Address: XXX.XXX.XXX.XXX
I would like to only retrieve the values after "Account Name:" and "Account Domain:" under "Account For Which Logon Failed:" using a select statement so I can use that in Excel and/or Power BI.
Is this possible?
I guess the provided sample is the content og one column / one string. In this case I would suggest to use a combination of charindex and xml.nodes.
Following an example:
DECLARE #x NVARCHAR(max) = 'An account failed to log on.
Subject:
Security ID: S-1-5-18
Account Name: XXX-XXX01$
Account Domain: XXX
Logon ID: 0x3E7
Logon Type: 8
Account For Which Logon Failed:
Security ID: S-1-0-0
Account Name: username
Account Domain: domain
Failure Information:
Failure Reason: Unknown user name or bad password.
Status: 0xC000006D
Sub Status: 0xC0000064
Process Information:
Caller Process ID: 0x1111
Caller Process Name: C:\Windows\System32\inetsrv\w3wp.exe
Network Information:
Workstation Name: XXX-XXX04
Source Network Address: XXX.XXX.XXX.XXX';
DECLARE #idxLogonFailed bigint = charindex('Account For Which Logon Failed:'+char(13)+char(10), #x);
DECLARE #idxFailureInfo bigint = charindex('Failure Information:'+char(13)+char(10), #x);
DECLARE #logonFailedLen int = #idxFailureInfo-#idxLogonFailed;
DECLARE #logonFailedSubstr NVARCHAR(1000) = SUBSTRING(#x, #idxLogonFailed, #logonFailedLen);
DECLARE #newLineIdx INT = charindex(char(13)+char(10), #logonFailedSubstr);
DECLARE #xXml xml = CAST(REPLACE('<a><b>' + REPLACE(#logonFailedSubstr, char(13)+char(10), '</b><b>') + '</b></a>', '<b></b>', '') AS XML);
WITH cte AS(
SELECT TRIM(T.r.value('.', 'VARCHAR(1000)')) AS x
FROM #xXml.nodes('/a/b') as T(r)
),
cteSplit AS(
SELECT *, TRIM(LEFT(x, CHARINDEX(':', x)-1)) AS description, TRIM(RIGHT(x, LEN(x)-CHARINDEX(':', x))) AS val
FROM cte
WHERE CHARINDEX(':', x) > -1
)
SELECT description, val
FROM cteSplit
WHERE description IN ('Account Name','Account Domain')

Is there a way to quit the current function based on a condition but not end the program

I have 2 class methods. One method 'accountExistance()' checks if an account already exists by finding a duplicate username in a database and the other method 'customerDetails()' writes the user registration details to the database. My customerDetails() method calls the 'accountExistance() method and if there is a duplicate username, which is checked within 'accountExistance' method, I return False and back in the initial method, if the return value is False 'sys.exit()' occurs.
The problem lies because I would rather not quit the program as its running a tkinter gui, allowing the user to change the registration details. Rather, is there a way of instead of quitting I can cancel the execution where it is and not submit duplicate values to a database.
To note, customerDetails() is called from another file upon the user pressing registration where stringVars() from entry boxes are fed into the class method. Also, the indentation appearance is not formatted properly on here but I have produced a minimal example for logic, and have cut out some lines of code.
class Database():
def __init__(self):
Database.phoneNumber = ""
def accountExistance(email, phoneNumber):
conn=sqlite3.connect("system.db")
cur=conn.cursor()
emailExist = cur.execute("SELECT count(email) FROM customerDetails WHERE email = ?", (email,)).fetchall()
conn.commit()
print(emailExist)
phoneExist = cur.execute("SELECT count(phone) FROM customerDetails WHERE phone = ?", (phoneNumber,)).fetchall()
print(phoneExist)
conn.commit()
if emailExist or phoneExist != 0 :
tk.messagebox.showinfo("Error", "This email and/or phone number is associated with an account")
return False
sys.exit()
#else:
#return True
#INSERT SIGN UP DETAILS
def customerDetails(forename, surname, dob, address, city,
county, postcode, phone, email, password,verified, gender):
print(forename, surname, dob, address, city, county, postcode,
postcode, phone, email, password, verified, gender)
test = Database.accountExistance(email, phone)
if test == False:
sys.exit()
age = 0
conn=sqlite3.connect("system.db")
cur=conn.cursor()
cur.execute("INSERT INTO customerDetails VALUES
(NULL,?,?,?,?,?,?,?,?,?,?,?,?,?)",(forename, surname, dob, address, city,
county, postcode, phone, email, password, verified, age, gender))
conn.commit()
conn.close()
Just change your condition to the following:
test = Database.accountExistance(email, phone)
if test == False:
return # Stops the execution of the function
Also, if test is necessarily either True or False, you can check its value directly:
if not test:
is the same as
if test == False:

Parse a single attribute in SQL

I have a description attribute which has all the below information.
Subject:
Security ID: SXXX
Account Name: GXXX$
Account Domain: GGGG
Security ID: SXXX0
Account Name: NETWORK
Account Domain: AUTHORITY
Workstation Name:
I am trying to parse this attribute and get the different parts of it and store it in a separate column. For example, Subject goes into a separate column, Security ID goes into a separate column and so on.
Any help would be appreciated.
Try below as an example of using Regular expression functions in BigQuery
SELECT
REGEXP_EXTRACT(description, 'Subject:([\\s\\S\\w\\W]*?)Security ID:') AS subject,
REGEXP_EXTRACT(description, 'Security ID:([\\s\\S\\w\\W]*?)Account Name:') AS securityId_1,
REGEXP_EXTRACT(description, 'Account Name:([\\s\\S\\w\\W]*?)Account Domain:') AS accountName_1,
REGEXP_EXTRACT(description, 'Account Domain:([\\s\\S\\w\\W]*?)Security ID:') AS accountDomain_1,
REGEXP_EXTRACT(description, 'Account Domain:[\\s\\S\\w\\W]*?Security ID:([\\s\\S\\w\\W]*?)Account Name:') AS securityId_2,
REGEXP_EXTRACT(description, 'Security ID:[\\s\\S\\w\\W]*Account Name:([\\s\\S\\w\\W]*?)Account Domain:') AS accountName_2,
REGEXP_EXTRACT(description, 'Account Name:[\\s\\S\\w\\W]*Account Domain:([\\s\\S\\w\\W]*)') AS accountDomain_2,
FROM
(SELECT ' Subject: Test1
Security ID: SXXX
Account Name: GXXX$
Account Domain: GGGG
Security ID: SXXX0
Account Name: NETWORK
Account Domain: AUTHORITY' AS description
),
(SELECT 'Subject: Test2 Security ID: SXXX Account Name: GXXX$ Account Domain: GGGG Security ID: SXXX0 Account Name: NETWORK Account Domain: AUTHORITY ' AS description)

What're the purposes of these special characters in SQL injection?

$sel1 = mysql_query ("SELECT ID, name, locale, lastlogin, gender,
FROM USERS_TABLE
WHERE (name = '$user' OR email = '$user') AND pass = '$pass'");
$chk = mysql_fetch_array($sel1);
if (found one record)
then {allow the user to login}`
The question is that try to login with username admin');#", then you will find that you logged in as the user admin!
Question asks what each special character purpose in sql injection.
,
)
;
#
"
Thanks!
This value:
admin');#
would terminate the SQL statement after the string "admin" and treat everything after as a comment. So this:
SELECT ID, name, locale, lastlogin, gender,
FROM USERS_TABLE
WHERE (name = '$user' OR email = '$user') AND pass = '$pass'
essentially becomes this:
SELECT ID, name, locale, lastlogin, gender,
FROM USERS_TABLE
WHERE (name = 'admin')
A record is found and the system happily continues on its way, having logged the user in as 'admin' because the query successfully found that record.