How do I create a pre-op clearcase trigger that prevents delivery to a specific stream - clearcase-ucm

I have worked with ClearCase triggers in the past but it have been over ten years ago.
I want to make a pre-op trigger which prevents a delivery to a specific stream except for specific users.
I know I can use nusers to allow only certain users to bypass the trigger, but with the opkind do I specify deliver or deliver_start?
For identifying the specific stream, do I write a Perl script that checks for the name, or is there a way I can use the restriction-list or the inclusion-list?

This "Delivery preoperation trigger script" is an official example which could give you some clues on how to write your own (in Perl).
You can see in it how its gets the stream name
use Config;
my $PVOBTAG;
my $tempfile;
my $exit_value;
if ($Config{'osname'} eq 'MSWin32') {
$PVOBTAG = '\cyclone-pvob';
$tempfile = $ENV{TMP}."\\expreop.".$ENV{"CLEARCASE_PPID"}.".txt";
}
else {
$PVOBTAG = '';
}
my $STREAM = "stream:".$ENV{"CLEARCASE_STREAM"};
my $ATTYPE = "attype:deliver_in_progress\#$PVOBTAG";
print $STREAM."\n";
print $ATTYPE."\n";

Related

How to glob and check multiple files in InstallBuilder?

I'm making installer program using VMware InstallBuilder (previously named Bitrock InstallBuilder), and need to ensure the non-existence of some files in target directory. Here I describe its logic in Perl fake code:
sub validate_target_dir
{
my $target_dir = shift;
# find all candidate check files
foreach my $file ( glob( "$target_dir/*_vol0.dat" ) )
{
my $fname = basename($file);
# fail if has any data file other than myproduct
if ($fname ne "myproduct_vol0.dat") { return 0; }
}
return 1;
}
However I don't know how to implement similar logic in InstallBuilder, as its findFile action don't return multiple matching files (only the first one).
At current, I find a somewhat twisted way to do it: implement the function in a shell script. InstallBuilder allows you to unpack contents programmatically, so I can pack the script into the installer package and unpack&run it at needed time.
I still seek if there's possible way that purely implemented by InstallBuilder itself.

MS Bot Framework: Is there a way to cancel a prompt dialog? [duplicate]

The PromptDialog.Choice in the Bot Framework display the choice list which is working well. However, I would like to have an option to cancel/escape/exit the dialog with giving cancel/escape/exit optioin in the list. Is there anything in PromptDialog.Choice which can be overridden since i have not found any cancel option.
here is my code in c#..
PromptDialog.Choice(
context: context,
resume: ChoiceSelectAsync,
options: getSoftwareList(softwareItem),
prompt: "We have the following software items matching " + softwareItem + ". (1), (2), (3). Which one do you want?:",
retry: "I didn't understand. Please try again.",
promptStyle: PromptStyle.PerLine);
Example:
Bot: We have the following software items matching Photoshop. (1), (2), (3). Which one do you want
Version 1
Version 2
Version 3
What I want if user enter none of above or a command or number, cancel, exit, that bypasses the options above, without triggering the retry error message.
How do we do that?
There are two ways of achieving this:
Add cancel as an option as suggested. While this would definitely work, long term you will find repeating yourself a lot, plus that you will see the cancel option in the list of choices, what may not be desired.
A better approach would be to extend the current PromptChoice to add your exit/cancelation logic. The good news is that there is something already implemented that you could use as is or as the base to achieve your needs. Take a look to the CancelablePromptChoice included in the BotBuilder-Samples repository. Here is how to use it.
Just add the option "cancel" on the list and use a switch-case on the method that gets the user input, then call your main manu, or whatever you want to do on cancel
Current Prompt Choice does not work in that way to allows user select by number. I have override the ScoreMatch function in CancleablePromptChoice as below
public override Tuple<bool, int> ScoreMatch(T option, string input)
{
var trimmed = input.Trim();
var text = option.ToString();
// custom logic to allow users to select by number
int isInt;
if(int.TryParse(input,out isInt) && isInt <= promptOptions.Options.Count())
{
text = promptOptions.Options.ElementAt(isInt - 1).ToString();
trimmed = option.ToString().Equals(text) ? text :trimmed;
}
bool occurs = text.IndexOf(trimmed, StringComparison.CurrentCultureIgnoreCase) >= 0;
bool equals = text == trimmed;
return occurs ? Tuple.Create(equals, trimmed.Length) : null;
}
#Ezequiel Once again thank you!.

Getting Windows domain username in correct case (to match Active Directory)

How can I sensibly get a Windows 7 user's username, but in the case that it's stored in the Active Directory domain (such as BillyBird), not using whatever case the user happened to type it when logging in (probably billybird, but could even be something like bILlYbIRd)?
This is in Perl, but since it's interacting with the operating system, solutions in other languages may be translatable.
I've tried these and they don't work; they all return the username in the case it was typed by the user when logging in*:
getlogin
Win32::LoginName
$ENV{USERNAME}
Win32::OLE->new('WScript.Network')->UserName
Win32API::Net::UserGetInfo
I have come up with a couple of bad ways of getting the right value. I'll post those as answers and hope that somebody else has a better one. Thanks.
* At least they do some of the time. For some users it alternates each time they log in between giving the as-typed and the as-AD values, but in all cases the above methods all agree with each other and %USERNAME%.
This gets the right value, but involves fetching the list of all domain users over the network and iterating over them looking for a case-insensitive match, which seems excessive just for returning something about the current user:
use v5.16;
use Win32::NetAdmin qw<GetDomainController GetUsers FILTER_NORMAL_ACCOUNT>;
my $comparable_username = fc getlogin;
GetDomainController('', '', my $domain_controller);
GetUsers($domain_controller, FILTER_NORMAL_ACCOUNT, \my #all_username);
my $username;
for (#all_username)
{
if (fc eq $comparable_username)
{
$username = $_;
last;
}
}
Here's my thought about using wmic put into practice
use strict;
use warnings 'all';
say username();
sub username {
for ( `wmic useraccount get name` ) {
return $1 if /\A($ENV{USERNAME})\s*\z/i;
}
return;
}
Update
To prevent wmic from fetching the full user name list, you can use the LIKE operator in a WHERE cal
sub username {
my #user = `wmic UserAccount WHERE ( name LIKE '$ENV{username}' ) GET name`;
return unless $user[1] =~ /\S/;
$user[1] =~ s/\s+\z//r;
}
This is a possible solution; it gets the username in the right case:
use IPC::System::Simple qw<capturex>;
my $username;
foreach (capturex qw<NET USER /DOMAIN>, getlogin)
{
if (/^User name\s*(\S+)$/)
{
$username = $1;
last;
}
}
However it involves running an external system command to parse its output (which is relatively slow), and relies on that output always being in English. An alternative solution that used an API for directly looking up whatever the NET USER command is doing would be superior to this one.

pc.removeStream(stream) not implemented Firefox + WebRTC

How can I remove a MediaStream from a peer connection in Firefox? The API says that the method pc.removeStream(stream) exists but when I use it, I receive the error: "removeStream not implemented"
I checked a solution here but I didn't understand the usage of the replaceTrack() function. I wan't to replace one audio track with another, and I can't figure out how to make it work ..
my understanding is Firefox is yet to implement adding/ removing streams from an PeerConnection, but you can add/ remove tracks( RTCRtpSender in this case) from within a single mediastream, so when you look at jib's answer takes all the tracks from input mediastream, checks if peerconnection's mediastream contains those tracks, removes them if present:
function removeTrack(pc, stream){
pc.getSenders().forEach(function(sender){
stream.getTracks.forEach(function(track){
if(track == sender.track){
pc.removeTrack(sender);
}
})
});
}
or basically you can just his polyfill:
window.mozRTCPeerConnection.prototype.removeStream = function(stream) {
this.getSenders().forEach(sender =>
stream.getTracks().includes(sender.track) && this.removeTrack(sender));
}

Validate file extensions in Apex

End user can upload files in a Visualforce page. In the backend I need to create a list of allowed file extensions, and restrict the user to that list. How do I create the extensions list and validate it? Any help is very much appreciated.
You don't need apex for that?
<apex:inputFile> has accept parameter which you can use. Bear in mind this will check contentType, not extension (which is bit more proper way to do it).
If you still want the validation in apex - probably something like this?
String fileName = 'foobar.xls';
Set<String> acceptedExtensions = new Set<String> {'.doc','.txt', '.jpg'};
Boolean found = false;
for(String s : acceptedExtensions){
if(found = fileName.endsWith(s)){ // yes, there's only one "=", I do want assignment here
break;
}
}
if(!found){ // after the whole loop it's still false?
ApexPages.addMessage(...);
}

Resources