public void AddCommand (WebServiceLogin login, int lane_id, string command, bool always_execute, bool nonfatal, int timeout, int sequence) { using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); DBCommand cmd = new DBCommand (); cmd.arguments = "-ex {0}"; cmd.filename = "bash"; cmd.command = command; cmd.lane_id = lane_id; cmd.alwaysexecute = always_execute; cmd.nonfatal = nonfatal; cmd.timeout = 60; if (sequence < 0) { cmd.sequence = sequence; } else { cmd.sequence = 10 * (int) (long) (db.ExecuteScalar ("SELECT Count(*) FROM Command WHERE lane_id = " + lane_id.ToString ())); } cmd.Save (db); } }
public void EditCommand (WebServiceLogin login, DBCommand command) { using (DB db = new DB ()) { VerifyUserInRole (db, login, Roles.Administrator); db.Audit (login, "WebServices.EditCommand (command: {0})", command); command.Save (db); } }
public void VerifyCommandIsForLane(DBCommand cmd, int lane_id) { if (cmd.lane_id != lane_id) { throw new UnauthorizedException ("You don't have the required permissions."); } }
public DBLane CloneLane (int lane_id, string new_name, bool copy_files) { DBLane result = null; DBLane master = DBLane_Extensions.Create (this, lane_id); if (this.LookupLane (new_name, false) != null) throw new Exception (string.Format ("The lane '{0}' already exists.", new_name)); try { using (IDbTransaction transaction = BeginTransaction ()) { result = new DBLane (); result.lane = new_name; result.max_revision = master.max_revision; result.min_revision = master.min_revision; result.repository = master.repository; result.source_control = master.source_control; result.parent_lane_id = master.parent_lane_id; result.enabled = master.enabled; result.Save (this); foreach (DBLanefile filemaster in master.GetFiles (this, null)) { int fid; if (copy_files) { DBLanefile clone = new DBLanefile (); clone.contents = filemaster.contents; clone.mime = filemaster.mime; clone.name = filemaster.name; clone.Save (this); fid = clone.id; } else { fid = filemaster.id; } DBLanefiles lane_files = new DBLanefiles (); lane_files.lane_id = result.id; lane_files.lanefile_id = fid; lane_files.Save (this); } foreach (DBCommand cmdmaster in GetCommands (master.id)) { DBCommand clone = new DBCommand (); clone.lane_id = result.id; clone.alwaysexecute = cmdmaster.alwaysexecute; clone.arguments = cmdmaster.arguments; clone.command = cmdmaster.command; clone.filename = cmdmaster.filename; clone.nonfatal = cmdmaster.nonfatal; clone.sequence = cmdmaster.sequence; clone.timeout = cmdmaster.timeout; clone.working_directory = cmdmaster.working_directory; clone.upload_files = cmdmaster.upload_files; clone.Save (this); } foreach (DBHostLaneView hostlanemaster in master.GetHosts (this)) { DBHostLane clone = new DBHostLane (); clone.enabled = false; clone.lane_id = result.id; clone.host_id = hostlanemaster.host_id; clone.Save (this); } foreach (DBEnvironmentVariable env in master.GetEnvironmentVariables (this)) { DBEnvironmentVariable clone = new DBEnvironmentVariable (); clone.host_id = env.host_id; clone.lane_id = result.id; clone.name = env.name; clone.value = env.value; clone.Save (this); } foreach (DBLaneNotification notification in master.GetNotifications (this)) { DBLaneNotification clone = new DBLaneNotification (); clone.lane_id = result.id; clone.notification_id = notification.notification_id; clone.Save (this); } foreach (var tag in master.GetTags (this)) { var clone = new DBLaneTag (); clone.lane_id = result.id; clone.tag = tag.tag; clone.Save (this); } transaction.Commit (); } } catch { result = null; throw; } return result; }
public void EditCommandInLane (WebServiceLogin login, DBCommand command, int lane_id) { using (DB db = new DB ()) { var lane = DBLane_Extensions.Create (db, lane_id); VerifyUserInRoles (db, login, lane.additional_roles, false); VerifyCommandIsForLane (command, lane_id); db.Audit (login, "WebServices.EditCommand (command: {0})", command); command.Save (db); } }