Exemplo n.º 1
0
    def activate(self, standard_webhook_url):
        config = self.config

        # Add a deploy key to the repository.
        public_key, private_key = generate_ssh_keypair()
        config["credentials"] = [
            {"name": "SSH Public Key", "value": public_key,},
        ]

        repository = self._get_repository_client()
        (result, created_deploykey, err_msg) = repository.deploykeys().create(
            app.config["REGISTRY_TITLE"] + " webhook key", public_key
        )

        if not result:
            msg = "Unable to add deploy key to repository: %s" % err_msg
            raise TriggerActivationException(msg)

        config["deploy_key_id"] = created_deploykey["pk"]

        # Add a webhook callback.
        description = "Webhook for invoking builds on %s" % app.config["REGISTRY_TITLE_SHORT"]
        webhook_events = ["repo:push"]
        (result, created_webhook, err_msg) = repository.webhooks().create(
            description, standard_webhook_url, webhook_events
        )

        if not result:
            msg = "Unable to add webhook to repository: %s" % err_msg
            raise TriggerActivationException(msg)

        config["webhook_id"] = created_webhook["uuid"]
        self.config = config
        return config, {"private_key": private_key}
Exemplo n.º 2
0
 def activate(self, standard_webhook_url):
     config = self.config
     public_key, private_key = generate_ssh_keypair()
     config["credentials"] = [
         {"name": "SSH Public Key", "value": public_key.decode("ascii"),},
         {"name": "Webhook Endpoint URL", "value": standard_webhook_url,},
     ]
     self.config = config
     return config, {"private_key": private_key.decode("ascii")}
Exemplo n.º 3
0
    def activate(self, standard_webhook_url):
        config = self.config
        new_build_source = config["build_source"]
        gl_client = self._get_authorized_client()

        # Find the GitLab repository.
        gl_project = gl_client.projects.get(new_build_source)
        if not gl_project:
            msg = "Unable to find GitLab repository for source: %s" % new_build_source
            raise TriggerActivationException(msg)

        # Add a deploy key to the repository.
        public_key, private_key = generate_ssh_keypair()
        config["credentials"] = [
            {
                "name": "SSH Public Key",
                "value": public_key.decode("ascii"),
            },
        ]

        key = gl_project.keys.create(
            {
                "title": "%s Builder" % app.config["REGISTRY_TITLE"],
                "key": public_key.decode("ascii"),
            }
        )

        if not key:
            msg = "Unable to add deploy key to repository: %s" % new_build_source
            raise TriggerActivationException(msg)

        config["key_id"] = key.get_id()

        # Add the webhook to the GitLab repository.
        hook = gl_project.hooks.create(
            {
                "url": standard_webhook_url,
                "push": True,
                "tag_push": True,
                "push_events": True,
                "tag_push_events": True,
            }
        )
        if not hook:
            msg = "Unable to create webhook on repository: %s" % new_build_source
            raise TriggerActivationException(msg)

        config["hook_id"] = hook.get_id()
        self.config = config
        return config, {"private_key": private_key.decode("ascii")}
Exemplo n.º 4
0
 def activate(self, standard_webhook_url):
   config = self.config
   public_key, private_key = generate_ssh_keypair()
   config['credentials'] = [
     {
       'name': 'SSH Public Key',
       'value': public_key,
     },
     {
       'name': 'Webhook Endpoint URL',
       'value': standard_webhook_url,
     },
   ]
   self.config = config
   return config, {'private_key': private_key}
Exemplo n.º 5
0
    def activate(self, standard_webhook_url):
        config = self.config
        new_build_source = config['build_source']
        gl_client = self._get_authorized_client()

        # Find the GitLab repository.
        gl_project = gl_client.projects.get(new_build_source)
        if not gl_project:
            msg = 'Unable to find GitLab repository for source: %s' % new_build_source
            raise TriggerActivationException(msg)

        # Add a deploy key to the repository.
        public_key, private_key = generate_ssh_keypair()
        config['credentials'] = [
            {
                'name': 'SSH Public Key',
                'value': public_key,
            },
        ]

        key = gl_project.keys.create({
            'title':
            '%s Builder' % app.config['REGISTRY_TITLE'],
            'key':
            public_key,
        })

        if not key:
            msg = 'Unable to add deploy key to repository: %s' % new_build_source
            raise TriggerActivationException(msg)

        config['key_id'] = key.get_id()

        # Add the webhook to the GitLab repository.
        hook = gl_project.hooks.create({
            'url': standard_webhook_url,
            'push': True,
            'tag_push': True,
            'push_events': True,
            'tag_push_events': True,
        })
        if not hook:
            msg = 'Unable to create webhook on repository: %s' % new_build_source
            raise TriggerActivationException(msg)

        config['hook_id'] = hook.get_id()
        self.config = config
        return config, {'private_key': private_key}
Exemplo n.º 6
0
    def activate(self, standard_webhook_url):
        config = self.config
        new_build_source = config["build_source"]
        gh_client = self._get_client()

        # Find the GitHub repository.
        try:
            gh_repo = gh_client.get_repo(new_build_source)
        except UnknownObjectException:
            msg = "Unable to find GitHub repository for source: %s" % new_build_source
            raise TriggerActivationException(msg)

        # Add a deploy key to the GitHub repository.
        public_key, private_key = generate_ssh_keypair()
        config["credentials"] = [
            {
                "name": "SSH Public Key",
                "value": public_key,
            },
        ]

        try:
            deploy_key = gh_repo.create_key(
                "%s Builder" % app.config["REGISTRY_TITLE"], public_key)
            config["deploy_key_id"] = deploy_key.id
        except GithubException as ghe:
            default_msg = "Unable to add deploy key to repository: %s" % new_build_source
            msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
            raise TriggerActivationException(msg)

        # Add the webhook to the GitHub repository.
        webhook_config = {
            "url": standard_webhook_url,
            "content_type": "json",
        }

        try:
            hook = gh_repo.create_hook("web", webhook_config)
            config["hook_id"] = hook.id
            config["master_branch"] = gh_repo.default_branch
        except GithubException as ghe:
            default_msg = "Unable to create webhook on repository: %s" % new_build_source
            msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
            raise TriggerActivationException(msg)

        return config, {"private_key": private_key}
Exemplo n.º 7
0
  def activate(self, standard_webhook_url):
    config = self.config
    new_build_source = config['build_source']
    gh_client = self._get_client()

    # Find the GitHub repository.
    try:
      gh_repo = gh_client.get_repo(new_build_source)
    except UnknownObjectException:
      msg = 'Unable to find GitHub repository for source: %s' % new_build_source
      raise TriggerActivationException(msg)

    # Add a deploy key to the GitHub repository.
    public_key, private_key = generate_ssh_keypair()
    config['credentials'] = [
      {
        'name': 'SSH Public Key',
        'value': public_key,
      },
    ]

    try:
      deploy_key = gh_repo.create_key('%s Builder' % app.config['REGISTRY_TITLE'],
                                      public_key)
      config['deploy_key_id'] = deploy_key.id
    except GithubException as ghe:
      default_msg = 'Unable to add deploy key to repository: %s' % new_build_source
      msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
      raise TriggerActivationException(msg)

    # Add the webhook to the GitHub repository.
    webhook_config = {
      'url': standard_webhook_url,
      'content_type': 'json',
    }

    try:
      hook = gh_repo.create_hook('web', webhook_config)
      config['hook_id'] = hook.id
      config['master_branch'] = gh_repo.default_branch
    except GithubException as ghe:
      default_msg = 'Unable to create webhook on repository: %s' % new_build_source
      msg = GithubBuildTrigger._get_error_message(ghe, default_msg)
      raise TriggerActivationException(msg)

    return config, {'private_key': private_key}
Exemplo n.º 8
0
    def activate(self, standard_webhook_url):
        config = self.config

        # Add a deploy key to the repository.
        public_key, private_key = generate_ssh_keypair()
        config['credentials'] = [
            {
                'name': 'SSH Public Key',
                'value': public_key,
            },
        ]

        repository = self._get_repository_client()
        (result, created_deploykey, err_msg) = repository.deploykeys().create(
            app.config['REGISTRY_TITLE'] + ' webhook key', public_key)

        if not result:
            msg = 'Unable to add deploy key to repository: %s' % err_msg
            raise TriggerActivationException(msg)

        config['deploy_key_id'] = created_deploykey['pk']

        # Add a webhook callback.
        description = 'Webhook for invoking builds on %s' % app.config[
            'REGISTRY_TITLE_SHORT']
        webhook_events = ['repo:push']
        (result, created_webhook,
         err_msg) = repository.webhooks().create(description,
                                                 standard_webhook_url,
                                                 webhook_events)

        if not result:
            msg = 'Unable to add webhook to repository: %s' % err_msg
            raise TriggerActivationException(msg)

        config['webhook_id'] = created_webhook['uuid']
        self.config = config
        return config, {'private_key': private_key}