code: def add_source(source, key=None):
      
      if source is None:
          log('Source is not present. Skipping')
          return
  
      if source.startswith('http'):
          directory = '/etc/yum.repos.d/'
          for filename in os.listdir(directory):
              with open(directory + filename, 'r') as rpm_file:
                  if source in rpm_file.read():
                      break
          else:
              log("Add source: {!r}".format(source))
              # write in the charms.repo
              with open(directory + 'Charms.repo', 'a') as rpm_file:
                  rpm_file.write('[%s]\n' % source[7:].replace('/', '_'))
                  rpm_file.write('name=%s\n' % source[7:])
                  rpm_file.write('baseurl=%s\n\n' % source)
      else:
          log("Unknown source: {!r}".format(source))
  
      if key:
          if '-----BEGIN PGP PUBLIC KEY BLOCK-----' in key:
              with NamedTemporaryFile('w+') as key_file:
                  key_file.write(key)
                  key_file.flush()
                  key_file.seek(0)
                  subprocess.check_call(['rpm', '--import', key_file.name])
          else:
              subprocess.check_call(['rpm', '--import', key])
docs: Add a package source to this system.
  
      @param source: a URL with a rpm package
  
      @param key: A key to be added to the system's keyring and used
      to verify the signatures on packages. Ideally, this should be an
      ASCII format GPG public key including the block headers. A GPG key
      id may also be used, but be aware that only insecure protocols are
      available to retrieve the actual public key from a public keyserver
      placing your Juju environment at risk.