Skip to content

Conversation

@varshavaradarajan
Copy link
Contributor

No description provided.

@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch from 0daa575 to 887aa8b Compare May 24, 2018 15:14
@varshavaradarajan varshavaradarajan changed the title [WIP] Support for external artifact config in pipeline config API. Support for external artifact config in pipeline config API. May 24, 2018
@varshavaradarajan
Copy link
Contributor Author

varshavaradarajan commented May 24, 2018

To test -

  • Fetch artifact - within the same pipeline and if the pipeline config being saved has a dependency on an upstream pipeline.

  • pipeline config update API: What happens if the pipeline already exists in the config? For a request like

{
                    "label_template": "${COUNT}",
                    "lock_behavior": "lockOnFailure",
                    "name": "new_pipeline",
                    "materials": [
                      {
                        "type": "git",
                        "attributes": {
                          "url": "git@github.com:sample_repo/example.git",
                          "destination": "dest"
                        }
                      }
                    ],
                    "stages": [
                      {
                        "name": "defaultStage",
                        "jobs": [
                          {
                            "name": "defaultJob",
                            "tasks": [
                              {
                                "type": "exec",
                                "attributes": {
                                  "run_if": [
                                    "passed"
                                  ],
                                  "command": "ls",
                                  "working_directory": null
                                }
                              }
                            ],
                            "artifacts": [
                              {
                                "type": "build",
                                "source": "foo",
                                "destination": "bar"
                              },
                              {
                                "type": "test",
                                "source": "fml",
                                "destination": "fml"
                              },
                              {
                                "type": "external",
                                "artifact_id": "gross",
                                "store_id": "hub",
                                "configuration": [
                                  {
                                    "key": "Image",
                                    "value": "we"
                                  }
                                ]
                              }
                            ]
                          }
                        ]
                      },
                      {
                        "name": "defaultStage2",
                        "jobs": [
                          {
                            "name": "defaultJob",
                            "tasks": [
                              {
                                "type": "exec",
                                "attributes": {
                                  "run_if": [
                                    "passed"
                                  ],
                                  "command": "ls",
                                  "working_directory": null
                                }
                              },
                              {
                                "type": "fetch",
                                "attributes": {
                                  "origin": "gocd",
                                  "stage": "defaultStage",
                                  "job": "defaultJob",
                                  "source": "dir"
                                }
                              },
                              {
                                "type": "fetch",
                                "attributes": {
                                  "origin": "external",
                                  "pipeline": "new_pipeline",
                                  "stage": "defaultStage",
                                  "job": "defaultJob",
                                  "artifact_id": "gross",
                                  "configuration": [
                                    {
                                      "key": "foo",
                                      "value": "plain"
                                    }
                                  ]
                                }
                              }
                            ]
                          }
                        ]
                      }
                    ]
                }
  • Publish artifact config - If the store id is a parameter.

  • Fetch artifact config - If either the pipeline, stage, job or artifact id is a parameter.

@akshaydewan - I guess the above applies to config repos as well. Although I don't think anything would have to change as the @PostConstruct is in place. Please verify.

@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch 4 times, most recently from 3273c16 to 5b753f2 Compare June 1, 2018 17:47
@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch 2 times, most recently from 5dfdc97 to 4eb2a6d Compare June 12, 2018 10:15
break;
default:
//TODO: change this when support for external artifacts is introduced
throw new UnprocessableEntityException(String.format("Invalid Artifact type: '%s'. It has to be one of %s.", type, String.join(",", "build", "test")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add external to exception message

this.getConfiguration().add(builder.create(property.getConfigKeyName(),
property.getConfigValue(),
property.getEncryptedValue(),
false));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always marking a configuration as unSecure can lead to ConfigurationPropertyBuilder adding errors if a encrypted value is provided.

public void encryptSecureProperties(CruiseConfig cruiseConfig, PipelineConfig pipelineConfig) {
if (artifactId != null) {
PipelineConfig dependencyMaterial = null;
if (pipelineName == null || CaseInsensitiveString.isBlank(pipelineName.getPath())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to handle a scenario where a given pipeline name corresponds to the current pipeline.
This could happen when a job fetches an artifact from a job corresponding to the previous stage in the pipeline.

// ignore
}
}
if (dependencyMaterial != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be refactored

return;
}
Configuration configurationProperties = new Cloner().deepClone(getConfiguration());
getConfiguration().clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the config is validated against the plugin and if there are errors it would be cleared as well.

}

public void addConfigurations(List<ConfigurationProperty> configurationProperties, CruiseConfig cruiseConfig) {
//TODO: based on https://github.com/gocd/gocd/pull/4763
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess this needs to be removed.

@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch 2 times, most recently from a920975 to 17dd3f0 Compare June 15, 2018 06:20
@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch 2 times, most recently from fc9a7f1 to 77d3e46 Compare June 20, 2018 08:37
@varshavaradarajan
Copy link
Contributor Author

varshavaradarajan commented Jun 21, 2018

What we have finally decided on encryption:

  • Do the encryption of secure plugin properties after preprocess and before validate. We need to handle this for all config save flows. This PR handles it for config save through entity.

@varshavaradarajan
Copy link
Contributor Author

varshavaradarajan commented Jun 21, 2018

Questions for @arvindsv:

Context: In this PR, we handle encryption of secure publish and fetch plugin properties for pipelines. We have various config save flows that we should take care of:

  • FullConfigSaveNormalFlow
  • FullConfigSaveMergeFlow
  • Old config save - normal flow (See GoFileConfigDataSource#writeWithLock)
  • Old config save - merged flow (See GoFileConfigDataSource#writeWithLock)
  • APIs

For the various config save flows that we have, should we even preprocess and attempt to encrypt plugin properties at the template level given that at the template level given that the store id or artifact id may be a param and so we might not be able to encrypt the properties? Asking this so that we don't perform expensive param preprocessing (which won't be able to replace param values for anything in a template) if we can't encrypt. We could also try to encrypt the plugin properties as is without preprocessing, but we might end up running into #4863.

For validation of a template publish or fetch external artifact config, the validation of plugin properties should happen in the context of the associated pipelines? So, for create template, we won't be requesting any plugin to perform validations, but for update of template, we have to check the associated pipelines and request the respective plugin to perform the validation, right?

@jyotisingh, @maheshp - Have I missed anything?

@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch 2 times, most recently from 9cf18eb to 7fda3d5 Compare June 21, 2018 18:07
@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch from 5f4d8f9 to d1a2cee Compare June 22, 2018 04:21
…s a param.

Encrypt fetch external artifact task properties when external config identifiers are params.
* This is so that PipelineConfigErrorCopier can copy plugin properties error to the pipeline config object.
…. Artifact id could be a param, using NameTypeValidator will result in errors when a parameter is provided at the template level.

* Currently for publish artifact, artifact id can't be a parameter. This needs to change at the xsd and validate level for templates.
@varshavaradarajan varshavaradarajan force-pushed the pipeline-config-api-external-artifacts branch from 9052bed to f1f858e Compare June 22, 2018 07:21
@varshavaradarajan varshavaradarajan merged commit 4b9e583 into gocd:master Jun 22, 2018
@GaneshSPatil GaneshSPatil added this to the Release 18.7 milestone Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants