Go, extract days out of byte array - string

I have a byte array containing the output of an Active Directory call. I want to parse this and extract the amount of days until my account expires. Now I'm wondering: what's the best way to extract 22-4-2016 11:05:26 (so the value after Password Expires)?
[]byte(`The request will be processed at a domain controller for domain local.nl.bol.com.
User name bla
Full Name bla bla
Comment
User's comment
Country code (null)
Account active Yes
Account expires Never
Password last set 13-3-2016 11:05:26
Password expires 22-4-2016 11:05:26
Password changeable 13-3-2016 11:05:26
Password required Yes
User may change password Yes
Workstations allowed All
Logon script bla.bat
User profile
Home directory
Last logon 31-3-2016 7:59:29
Logon hours allowed All
The command completed successfully.`)

Using strings.TrimSpace, strings.Index and referring to related stackoverflow answers, I got a working solution and please find working code below:-
package main
import (
"fmt"
"strings"
)
func CToGoString(c []byte) string {
n := -1
for i, b := range c {
if b == 0 {
break
}
n = i
}
return string(c[:n+1])
}
func main() {
s := []byte(`The request will be processed at a domain controller for domain local.nl.bol.com.
User name bla
Full Name bla bla
Comment
User's comment
Country code (null)
Account active Yes
Account expires Never
Password last set 13-3-2016 11:05:26
Password expires 22-4-2016 11:05:26
Password changeable 13-3-2016 11:05:26
Password required Yes
User may change password Yes
Workstations allowed All
Logon script bla.bat
User profile
Home directory
Last logon 31-3-2016 7:59:29
Logon hours allowed All
The command completed successfully.`)
d := CToGoString(s)
len := len("Password expires")
i := strings.Index(d, "Password expires")
j := strings.Index(d, "Password changeable")
chars := d[i+len:j]
fmt.Println(strings.TrimSpace(chars))
}
Have posted code to playground: http://play.golang.org/p/t0Xjd04-pi

You can do it by converting the []byte into a string and then using the strings package to find and extract the value and finally parsing it with time.Parse to convert the string to a time that you can work with.
package main
import (
"fmt"
"strings"
"time"
"log"
)
func main() {
line := data[strings.Index(data, "Password expires"):strings.Index(data, "Password changeable")]
date := strings.TrimSpace(strings.TrimPrefix(line, "Password expires"))
fmt.Println(date)
pDate, err := time.Parse("02-1-2006 03:04:05", date)
if err != nil {
log.Fatal(err)
}
fmt.Println(pDate)
}
var data = string([]byte(`The request will be processed at a domain controller for domain local.nl.bol.com.
User name bla
Full Name bla bla
Comment
User's comment
Country code (null)
Account active Yes
Account expires Never
Password last set 13-3-2016 11:05:26
Password expires 22-4-2016 11:05:26
Password changeable 13-3-2016 11:05:26
Password required Yes
User may change password Yes
Workstations allowed All
Logon script bla.bat
User profile
Home directory
Last logon 31-3-2016 7:59:29
Logon hours allowed All
The command completed successfully.`))
On the playground.

Related

Value of next element is entered in current element

I want to enter the "Password" element using Python (Selenium). The first element entered is User ID, next is Password element.
The problem is when i enter the "Password" after entered the User ID, the value for User ID has no problem. But, when value of Password is entered, it is entered in User ID field.
Eg:
User ID: Ain
Password: abc
System enter the password in User ID field.So, it will be shown like this,
User ID: Ainabc
Password: (blank)
Code trials:
filepath = "C:/Users/siti11074/Payroll Master/login_test.xlsx"#Config file
wb = load_workbook(filepath)
config_sheet = wb.get_sheet_by_name('Config')
b2=config_sheet['C3']
user_id = b2.value
b3=config_sheet ['C4']
password = b3.value
driver.find_element_by_id("USERID_I").send_keys(user_id)
time.sleep(2.0)
print("User ID is entered")
elem_pwd=driver.find_element_by_id("USERPWD_I")
ActionChains(driver).move_to_element(elem_pwd).send_keys(password).perform()
time.sleep(2.0)
print("Password is entered")
Expected Result:
System need to enter the User ID value in User ID field.
And for Password value in Password field.

Lotus Notes NAB - Adding a field

I have a project that I need to put an Internet Address and also add a new field called ShortName for all groups in the Notes NAB.
I am able to put the values and save the document , I tried with a doc.save and a computewithform. This is the Group form.
After the change, people in that group are no longer able to access the application.
Do you have an idea what I am doing wrong ?
User A is in group XYZ.
I added internetaddress xyz.com and a shortname text field xyzmigration
Application A is having an ACL with the group XYZ as editor. When User A tries to open the Application A, he get a not authorize. If I delete both values, User A is able to open the database.
Thanks for your help
$ServerAccess view validates Group documents and omits any Groups that has Shortname field present.
Normunds has the correct answer, but I want to add a suggestion: create a new group instead of modifying the existing group. I.e., if the group is "MyGroup", create a group named "MyGroup_Extended" and set it up with
Shortname = the value that you want
InternetAddress = the value that you want
Members = "MyGroup"
That way, you leave MyGroup untouched, but you still have a modified group document with the additional information added and the same member list.
And another thing: In order to make those groups that you already altered functional again, you should run a simple agent against all of the groups that does this:
FIELD ShortName := #DeleteField;
FIELD InternetAddress := #DeleteField;
After the help of some answers that I got here. I checked the view $ServerAccess. The selection formula is checking for a field Shortname and that is what was causing my problem. I will create another field name and we will be able to use this field instead of ShortName. allfields := #DocFields;
test1 := 0;
test2 := 0;
#For(i:=1; i < #Elements(allfields); i:=i+1; test1 := test1 + #If(#UpperCase(allfields[i]) = "LISTNAME";1;0));
#For(i:=1; i < #Elements(allfields); i:=i+1; test2:=test2 + #If(#UpperCase(allfields[i]) = "SHORTNAME";1;0));
SELECT (test1 < 2 & test2 = 0 &Type = "Group" & (#IsUnavailable ( GroupType)|GroupType="0" : "2":"3":"4")) & Form="Group" & #IsUnavailable($Conflict)
Thanks for your help.

Specflow: using same step definition for scenario and scenario outline

My feature file contains a 'scenario' test for a successful login and a 'Scenario Outline' test for testing multiple login details which should be unsuccessful.
#web
Scenario: Successful login
Given I have entered username 'tomsmith' and password 'SuperSecretPassword!' into the application
When I login
Then I should be informed that login was successful
#web
Scenario Outline: Unsuccessful login
Given I have entered username <username> and password <password> into the application
When I login
Then I should be informed that login was unsuccessful
Examples:
| testing | username | password |
| invalid combination 1 | test | test |
| special characters | $$$ | SuperSecretPassword! |
I would like both to use the same step definition (as they are just passing parameters)
My step definition is:
[Given(#"I have entered username '(.*)' and password '(.*)' into the application")]
public void GivenIHaveEnteredUsernameAndPasswordIntoTheApplication(string p0, string p1)
{
login = new LoginPage();
login.with(p0, p1);
}
The problem is that the scenario outline tests do not run, they return a 'Pending' error: Pending: No matching step definition found for one or more steps
and suggests the step definition should be:
[Given(#"I have entered test and test into the application")]
Can anyone help please?
you problem is on this line:
Given I have entered username <username> and password <password> into the application
it should be
Given I have entered username '<username>' and password '<password>' into the application
you just missed out the ' marks

SAS script to list all SAS server users from metadata

I need a way to import a list of all SAS users from SAS metadata into an Excel worksheet. I was considering doing this using the SAS plugin for Microsoft Office to create a dynamic data source the retrieves the list of users dynamically from the SAS server. If I am to do this I need to know how to do this in SAS code.
Does anyone know how I would write a SAS script to display a list of all users in SAS metadata, or if this is even possible?
I've been trying to find something online but haven't had any luck.
I have full administrator privileges, so no problem there.
Thanks!
Thanks to Joe in the comments I found the answer I need:
http://support.sas.com/documentation/cdl/en/lrmeta/63180/HTML/default/viewer.htm#p1k9zipe59ha2an1pq34gu143lay.htm
I used the very last example in this page, modified to do a PROC PRINT instead of exporting to an Excel sheet. In Enterprise Guide I created a new program as follows:
/*Connect to the metadata server using the metadata system options as
shown in the first example. */
data work.Identities;
/* The LENGTH statement defines the lengths of variables for function arguments. */
length IdentId IdentName DispName ExtLogin IntLogin DomainName $32
uri uri2 uri3 uri4 $256;
/* The LABEL statement assigns descriptive labels to variables. */
label
IdentId = "Identity Id"
IdentName = "Identity Name"
DispName = "Display Name"
ExtLogin = "External Login"
IntLogin = "Is Account Internal?"
DomainName = "Authentication Domain";
/* The CALL MISSING statement initializes the output variables to missing values. */
call missing(IdentId, IdentName, DispName, ExtLogin, IntLogin, DomainName,
uri, uri2, uri3, uri4);
n=1;
n2=1;
/* The METADATA_GETNOBJ function specifies to get the Person objects in the repository.
The n argument specifies to get the first person object that is returned.
The uri argument will return the actual uri of the Person object. The program prints an
informational message if no objects are found. */
rc=metadata_getnobj("omsobj:Person?#Id contains '.'",n,uri);
if rc<=0 then put "NOTE: rc=" rc
"There are no identities defined in this repository"
" or there was an error reading the repository.";
/* The DO statement specifies a group of statements to be executed as a unit.
The METADATA_GETATTR function gets the values of the Person object's Id, Name,
and DisplayName attributes. */
do while(rc>0);
objrc=metadata_getattr(uri,"Id",IdentId);
objrc=metadata_getattr(uri,"Name",IdentName);
objrc=metadata_getattr(uri,"DisplayName",DispName);
/* The METADATA_GETNASN function gets objects associated via the
InternalLoginInfo association. The InternalLoginInfo association returns
internal logins. The n2 argument specifies to return the first associated object
for that association name. The URI of the associated object is returned in
the uri2 variable. */
objrc=metadata_getnasn(uri,"InternalLoginInfo",n2,uri2);
/* If a Person does not have any internal logins, set their IntLogin
variable to 'No' Otherwise, set to 'Yes'. */
IntLogin="Yes";
DomainName="**None**";
if objrc<=0 then
do;
put "NOTE: There are no internal Logins defined for " IdentName +(-1)".";
IntLogin="No";
end;
/* The METADATA_GETNASN function gets objects associated via the Logins association.
The Logins association returns external logins. The n2 argument specifies to return
the first associated object for that association name. The URI of the associated
object is returned in the uri3 variable. */
objrc=metadata_getnasn(uri,"Logins",n2,uri3);
/* If a Person does not have any logins, set their ExtLogin
variable to '**None**' and output their name. */
if objrc<=0 then
do;
put "NOTE: There are no external Logins defined for " IdentName +(-1)".";
ExtLogin="**None**";
output;
end;
/* If a Person has many logins, loop through the list and retrieve the name of
each login. */
do while(objrc>0);
objrc=metadata_getattr(uri3,"UserID",ExtLogin);
/* If a Login is associated to an authentication domain, get the domain name. */
DomainName="**None**";
objrc2=metadata_getnasn(uri3,"Domain",1,uri4);
if objrc2 >0 then
do;
objrc2=metadata_getattr(uri4,"Name",DomainName);
end;
/*Output the record. */
output;
n2+1;
/* Retrieve the next Login's information */
objrc=metadata_getnasn(uri,"Logins",n2,uri3);
end; /*do while objrc*/
/* Retrieve the next Person's information */
n+1;
n2=1;
rc=metadata_getnobj("omsobj:Person?#Id contains '.'",n,uri);
end; /*do while rc*/
/* The KEEP statement specifies the variables to include in the output data set. */
keep IdentId IdentName DispName ExtLogin IntLogin DomainName;
run;
/* The PROC PRINT statement writes a basic listing of the data. */
proc print data=work.Identities label;
run;
/* The PROC EXPORT statement can be used to write the data to an Excel spreadsheet. */
/* Change DATA= to the data set name you specified above. */
/* Change OUTFILE= to an appropriate path for your system. */
/*
proc export data=work.Identities
dbms=EXCE
outfile="C:\temp\Identities.xls"
replace;
run;
*/
PROC PRINT DATA=work.Identities;
When this was executed it created a SAS Report. I exported that Report as a .srx file and then used the SAS Plugin for Microsoft Office to add the report into an Excel worksheet (the "Reports" button).
I then right-clicked on the cell where the report was added and clicked Properties, and then set it to automatically update whenever the document is opened.
It's a great way to review users as an administrator. Rather than having to check each system individually to see if a user exists (when they leave the company for example) I have a sheet for each of our SAS systems, a sheet for each of our Teradata systems (auto-updated using a query run through ODBC), and another sheet auto-updated from a separate spreadsheet that contains the list of our MicroStrategy users. It makes checking all systems as simple as a single Ctrl + F.
If you just want to extract the list of users in SAS you can compile this macro and run:
%mm_getusers(outds=myusers)
Disclaimer - I wrote it, and we use it in our commercial product (https://datacontroller.io) so users can see group memberships when applying permissions within the tool.

BDD: SpecFlow - Scenario Outline Behaviour Not As Expected

Using scenario outlines in SpecFlow, e.g.
Scenario Outline: Invalid Login Details
Given some pre-conditions...
When user "Larry" enters username <username> and password <password>
Then the message "Invalid Login Details" should be displayed
Examples:
|username|password|
|larry06 | |
|larry06 |^&*%*^$ |
|%^&&** |pass123 |
| |pass123 |
I expected that the "When" step would be evaluated as such:
public void WhenUserEntersUsernameAndPassword(String username, String password){}
And that the scenario would be run 4 times - for each row of the table, passing the values as required. That's not the case.
Instead, SpecFlow creates 1 of 4 required step definitions:
[When(#"""(.*)"" provides the following new username larry(.*) and password ")]
public void WhenUserEntersUsernameLarryAndPassword(string p0, int p1)
{
//TODO
}
And to get the remaining 3 to 'work' I need to manually write methods explicitly matching other values in the table.
I've since realised that I can just say:
When "Larry" enters username "<username>" and password "<password>"
And I get:
[When(#"""(.*)"" provides the following ""(.*)"" and ""(.*)""")]
public void WhenUserEntersUsernameAndPassword(string p0, string name, string pass)
{
//TODO
}
Perfect.
But all documentation seems to suggest I don't need "" and that should just work (e.g. https://github.com/cucumber/cucumber/wiki/Scenario-outlines). I note:
"Your step definitions will never have to match a placeholder. They will need to match the values that will replace the placeholder"
I just don't really see the value of writing separate step definitions for each line of the table.
Is this nuance specific to SpecFlow?
When "Larry" enters username <username> and password <password>
will match
[When(#"""(.*)"" enters username (.*) and password (.*)")]
public void WhenEntersUsernameAndPassword(string p0, string name, string pass)
{
//TODO
}
so the documentation is fine.
The problem you experienced is that the auto generation of step text doesn't anticipate what regexs to insert without the "..." - which I guess it must be using as an indicator that you are passing interchangable strings - matchable with "(.*)", but if you don't want the quotes, you can still manually correct it just fine.

Resources