protected override void Execute(CodeActivityContext context) { Int32 _timeout = TimeoutMS.Get(context); CallWithTimeout(new Action(() => { try { string credName = CredentialName.Get(context); IntPtr credPtr = new IntPtr(); WReadCred(credName, CRED_TYPE.GENERIC, CRED_PERSIST.LOCAL_MACHINE, out credPtr); if (credPtr.ToInt32() == 0) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "凭证不存在"); return; } Credential lRawCredential = (Credential)Marshal.PtrToStructure(credPtr, typeof(Credential)); SecureString securePassWord = new SecureString(); foreach (char c in lRawCredential.CredentialBlob) { securePassWord.AppendChar(c); } UserName.Set(context, lRawCredential.UserName); PassWord.Set(context, securePassWord); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "读取凭证执行过程出错", e.Message); } }), _timeout); }
private void FormCredential_Load(object sender, EventArgs e) { txtCredName.Text = CredentialName.ToUnsecureString(); txtUserID.Text = UserID.ToUnsecureString(); txtPassword.Text = Password.ToUnsecureString(); txtLink.Text = Link.ToUnsecureString(); }
protected override object EvaluateScalar(IVariableFunctionContext context) { var name = Inedo.Extensibility.Credentials.CredentialName.TryParse(this.CredentialName); if (name == null) { throw new ExecutionFailureException(true, $"The specified credential name \"{this.CredentialName}\" is invalid."); } // need to resolve credential type name if it's not specified with the scope resolution operator if (name.TypeName == null) { var types = (from c in SDK.GetCredentials() where string.Equals(c.Name, name.Name, StringComparison.OrdinalIgnoreCase) select c.LegacyResourceCredentialTypeName).ToHashSet(StringComparer.OrdinalIgnoreCase); if (types.Count == 0) { throw new ExecutionFailureException(true, $"There are no credentials named \"{name.Name}\" found in the system."); } if (types.Count > 1) { throw new ExecutionFailureException(true, $"There are multiple credential types with the name \"{name.Name}\" found in the system. Use the scope resolution operator (i.e. ::) to specify a type, for example: UsernamePassword::{name.Name}"); } name = new CredentialName(types.First(), name.Name); } var credential = ResourceCredentials.TryCreate(name.TypeName, name.Name, environmentId: context.EnvironmentId, applicationId: context.ProjectId, inheritFromParent: true); if (credential == null) { throw new ExecutionFailureException($"Could not find a {name.TypeName} Resource Credentials named \"{name.Name}\"; this error may occur if you renamed a credential, or the application or environment in context does not match any existing credentials. To resolve, edit this item, property, or operation's configuration, ensure a valid credential for the application/environment in context is selected, and then save."); } if (!(credential is JenkinsLegacyCredentials)) { throw new ExecutionFailureException($"Resource Credential \"{name.Name}\" is not a Jenkins Credential."); } var jenkins = (JenkinsLegacyCredentials)credential; UriBuilder uri = new UriBuilder(jenkins.ServerUrl) { Path = JenkinsClient.GetPath(this.JobName, this.BranchName, this.BuildNumber) }; return(uri.ToString()); }
public static ResourceCredentials TryGetCredentials(this IHasCredentials obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } var name = CredentialName.TryParse(obj.CredentialName); if (name == null) { return(null); } var credentialInfo = RompDb.GetCredentialsByName(name.TypeName, name.Name); if (credentialInfo == null) { return(null); } return(Factory.CreateResourceCredentials(credentialInfo)); }