dfe-analytical-services / dfeR

Common R tasks in the Department for Education (DfE)
https://dfe-analytical-services.github.io/dfeR/
GNU General Public License v3.0
8 stars 2 forks source link

Add a post proxy.R clean up function #56

Open cjrace opened 5 months ago

cjrace commented 5 months ago

We often see analysts struggle now who've ran proxy.R in the past (or new starts that have unwittingly ran it). The aim would be to have something is an equivalent function we can point to now that wipes the slate clean for them.

Not 100% on the way to do this, but it would be neat to have a semi-nuclear, wipe out any old settings that might be causing gremlins and errors now. Specifically making sure we unset anything that was previously set in proxy.R.

cjrace commented 5 months ago

Here is the last version of proxy.R before we removed it:

setup_proxy <- function(){

  # Ask the user for their password
  password <- rstudioapi::askForPassword("Please provide your Windows Password to authenticate.")

  # Construct proxy url using username and password
  proxy_encoded_url <- URLencode(
    paste0(
      "http://ad\\",
      Sys.getenv("USERNAME"),
      ":",
      password,
      "@mwg.proxy.ad.hq.dept:9090"
    ))

  # Construct commands to create environment variables
  http_proxy_cmd <-  paste0("setx http_proxy ", proxy_encoded_url)
  https_proxy_cmd <-  paste0("setx https_proxy ", proxy_encoded_url)

  # Create system environment variables
  system(http_proxy_cmd)
  system(https_proxy_cmd)

  # Set download file method for renv
  system("setx RENV_DOWNLOAD_FILE_METHOD wininet")

  # Pip folder variable
  pip_folder <- file.path(Sys.getenv("APPDATA"), "pip")

  # Create pip.ini file with trusted website for python
  if (!dir.exists(pip_folder)) dir.create(pip_folder)

  # SSL verify false (to make Azure Devops work internally). Analyst should only pull from trusted repos.
  system("git config --global http.sslVerify false")

  write("[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org",
        file = file.path(pip_folder, "pip.ini"))

}
rmbielby commented 3 months ago

Thinking this would be a network diagnostics tool, rather than setting any system variables itself. So gives a readout of what settings could be causing any issues.