Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a provider for scheduled pipelines #81

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
48 changes: 47 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
version: 2
version: 2.1

orbs:
snyk: snyk/[email protected]

jobs:
build:
docker:
Expand Down Expand Up @@ -54,6 +58,46 @@ jobs:
command: |
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete -draft ${CIRCLE_TAG} .

vulnerability-scan:
executor: go
steps:
- checkout
- run:
name: Setup Scanning
command: |
git config --global url."https://$GITHUB_USER:[email protected]/circleci/".insteadOf "https://github.com/circleci/"
- when:
condition:
or:
- equal: [ master, << pipeline.git.branch >> ]
steps:
- run:
name: Launching Snyk Orb Scanning
command: echo "Running snyk/scan on master; uploading the results"
- run:
name: Cleanup RemoteRepoURL
command: echo 'export REMOTE_REPO_URL="${CIRCLE_REPOSITORY_URL%".git"}"' >> "$BASH_ENV"
- snyk/scan:
organization: "circleci-public"
fail-on-issues: true
severity-threshold: high
monitor-on-build: true
additional-arguments: "--all-projects --remote-repo-url=${REMOTE_REPO_URL} -d"
- unless:
condition:
or:
- equal: [ master, << pipeline.git.branch >> ]
steps:
- run:
name: Launching Snyk Orb Scanning
command: echo "Running snyk/scan on branch; not uploading the results"
- snyk/scan:
organization: "circleci-public"
fail-on-issues: true
severity-threshold: high
monitor-on-build: false
additional-arguments: "--all-projects -d"

workflows:
version: 2
build:
Expand All @@ -62,6 +106,8 @@ workflows:
filters:
tags:
only: /^v\d+\.\d+\.\d+$/
- vulnerability-scan:
context: org-global-employees
- release:
requires:
- build
Expand Down
17 changes: 13 additions & 4 deletions circleci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// It uses upstream client functionality where possible and defines its own methods as needed
type Client struct {
contexts *api.ContextRestClient
schedules *api.ScheduleRestClient
rest *rest.Client
vcs string
organization string
Expand All @@ -39,19 +40,27 @@ func New(config Config) (*Client, error) {

rootURL := fmt.Sprintf("%s://%s", u.Scheme, u.Host)

contexts, err := api.NewContextRestClient(settings.Config{
cfg := settings.Config{
Host: rootURL,
RestEndpoint: u.Path,
Token: config.Token,
HTTPClient: http.DefaultClient,
})
}

contexts, err := api.NewContextRestClient(cfg)
if err != nil {
return nil, err
}

schedules, err := api.NewScheduleRestClient(cfg)
if err != nil {
return nil, err
}

return &Client{
rest: rest.New(rootURL, u.Path, config.Token),
contexts: contexts,
rest: rest.New(rootURL, u.Path, config.Token),
contexts: contexts,
schedules: schedules,

vcs: config.VCS,
organization: config.Organization,
Expand Down
21 changes: 21 additions & 0 deletions circleci/client/schedule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package client

import (
"github.com/CircleCI-Public/circleci-cli/api"
)

func (c *Client) GetSchedule(id string) (*api.Schedule, error) {
return c.schedules.ScheduleByID(id)
}

func (c *Client) CreateSchedule(organization, project, name, description string, timetable api.Timetable, useSchedulingSystem bool, parameters map[string]string) (*api.Schedule, error) {
return c.schedules.CreateSchedule(c.vcs, organization, project, name, description, useSchedulingSystem, timetable, parameters)
}

func (c *Client) DeleteSchedule(id string) error {
return c.schedules.DeleteSchedule(id)
}

func (c *Client) UpdateSchedule(id, name, description string, timetable api.Timetable, useSchedulingActor bool, parameters map[string]string) (*api.Schedule, error) {
return c.schedules.UpdateSchedule(id, name, description, useSchedulingActor, timetable, parameters)
}
1 change: 1 addition & 0 deletions circleci/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Provider() terraform.ResourceProvider {
"circleci_environment_variable": resourceCircleCIEnvironmentVariable(),
"circleci_context": resourceCircleCIContext(),
"circleci_context_environment_variable": resourceCircleCIContextEnvironmentVariable(),
"circleci_schedule": resourceCircleCISchedule(),
},
DataSourcesMap: map[string]*schema.Resource{
"circleci_context": dataSourceCircleCIContext(),
Expand Down
4 changes: 4 additions & 0 deletions circleci/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("TEST_CIRCLECI_ORGANIZATION"); v == "" {
t.Fatal("TEST_CIRCLECI_ORGANIZATION must be set for acceptance tests")
}

if v := os.Getenv("CIRCLECI_PROJECT"); v == "" {
t.Fatal("CIRCLECI_PROJECT must be set for acceptance tests")
}
}
Loading