@Override
    public int execute() throws Exception {
      int exitCode = 0;
      CredentialProvider.CredentialEntry credEntry = provider.getCredentialEntry(alias);

      if (credEntry != null) {
        /*
         * If credential already exists, overwrite if -f flag was specified.
         * overwrite is true if -f was specified.
         * overwrite is false if -n was specified.
         * if neither options were specified, prompt the user.
         */
        if (interactive) {
          // prompt the user to confirm or reject the overwrite
          overwrite = ToolRunner
                  .confirmPrompt("You are about to OVERWRITE the credential " +
                          alias + " from CredentialProvider " + provider +
                          ". Continue? ");
        }

        if (overwrite) {
          // delete the existing credential
          DeleteCommand deleteCommand = new DeleteCommand();
          exitCode = deleteCommand.execute();
        } else {
          // nothing to do
          return 0;
        }
      }

      // create new or overwrite existing credential if delete succeeded
      if (exitCode == 0) {
        exitCode = createCredential();
      }

      return exitCode;
    }
Creates or updates the specified credential.

@return - 0 on success; 1 on failure.
@throws Exception
ambari-server/src/main/java/org/apache/ambari/server/credentialapi/CredentialUtil.java