feat(core): add jenkins artifact type
ADD
clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/jenkins/JenkinsArtifactAccount.java
+/*
+ * Copyright 2019 Pivotal, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.artifacts.jenkins;
+
+import com.netflix.spinnaker.clouddriver.artifacts.config.ArtifactAccount;
+import com.netflix.spinnaker.clouddriver.artifacts.config.BasicAuth;
+import lombok.Data;
+import lombok.RequiredArgsConstructor;
+
+@Data
+@RequiredArgsConstructor
+public class JenkinsArtifactAccount implements ArtifactAccount, BasicAuth {
+ private final String name;
+ private final String username;
+ private final String password;
+ private final String address;
+
+ public String getUsernamePasswordFile() {
+ return null;
+ }
+}

ADD
clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/jenkins/JenkinsArtifactConfiguration.java
+/*
+ * Copyright 2019 Pivotal, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.artifacts.jenkins;
+
+import com.squareup.okhttp.OkHttpClient;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@Configuration
+@ConditionalOnProperty("jenkins.enabled")
+@EnableConfigurationProperties(JenkinsProperties.class)
+@RequiredArgsConstructor
+@Slf4j
+public class JenkinsArtifactConfiguration {
+ private final JenkinsProperties jenkinsProperties;
+
+ @Bean
+ List<? extends JenkinsArtifactCredentials> jenkinsArtifactCredentials(OkHttpClient okHttpClient) {
+ return jenkinsProperties.getMasters()
+ .stream()
+ .map(m -> {
+ try {
+ return new JenkinsArtifactCredentials(new JenkinsArtifactAccount(m.getName(), m.getUsername(), m.getPassword(), m.getAddress()),
+ okHttpClient);
+ } catch (Exception e) {
+ log.warn("Failure instantiating jenkins artifact account {}: ", m, e);
+ return null;
+ }
+ })
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ }
+}

ADD
clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/jenkins/JenkinsArtifactCredentials.java
+/*
+ * Copyright 2019 Pivotal, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.artifacts.jenkins;
+
+
+import com.netflix.spinnaker.clouddriver.artifacts.config.ArtifactCredentials;
+import com.netflix.spinnaker.clouddriver.artifacts.config.SimpleHttpArtifactCredentials;
+import com.netflix.spinnaker.kork.artifacts.model.Artifact;
+import com.squareup.okhttp.HttpUrl;
+import com.squareup.okhttp.OkHttpClient;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Collections;
+import java.util.List;
+
+@Slf4j
+public class JenkinsArtifactCredentials extends SimpleHttpArtifactCredentials<JenkinsArtifactAccount> implements ArtifactCredentials {
+ public static final String TYPE = "jenkins/file";
+
+ @Getter
+ private final String name;
+
+ @Getter
+ private final List<String> types = Collections.singletonList(TYPE);
+
+ private final JenkinsArtifactAccount jenkinsArtifactAccount;
+
+ JenkinsArtifactCredentials(JenkinsArtifactAccount account, OkHttpClient okHttpClient) {
+ super(okHttpClient, account);
+ this.jenkinsArtifactAccount = account;
+ this.name = account.getName();
+ }
+
+ @Override
+ protected HttpUrl getDownloadUrl(Artifact artifact) {
+ String formattedJenkinsAddress = jenkinsArtifactAccount.getAddress().endsWith("/") ? jenkinsArtifactAccount.getAddress() : jenkinsArtifactAccount.getAddress() + "/";
+ String formattedReference = artifact.getReference().startsWith("/") ? artifact.getReference() : "/" + artifact.getReference();
+ String buildUrl = formattedJenkinsAddress + "job/" + artifact.getName() + "/" + artifact.getVersion() + "/artifact" + formattedReference;
+ HttpUrl url = HttpUrl.parse(buildUrl);
+ if (url == null) {
+ throw new IllegalArgumentException("Malformed content URL in reference: " + buildUrl + ". Read more here https://www.spinnaker.io/reference/artifacts/types/");
+ }
+ return url;
+ }
+
+}

ADD
clouddriver-artifacts/src/main/java/com/netflix/spinnaker/clouddriver/artifacts/jenkins/JenkinsProperties.java
+/*
+ * Copyright 2019 Pivotal, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.netflix.spinnaker.clouddriver.artifacts.jenkins;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+@ConfigurationProperties("jenkins")
+public class JenkinsProperties {
+ private boolean enabled;
+ private List<Master> masters = new ArrayList<>();
+
+ @Data
+ public static class Master {
+ private String name;
+ private String address;
+ private String username;
+ private String password;
+ }
+}

feat(core): add jenkins artifact type (#3469)

Co-Authored-By: Ria Stein <eleftheria.kousathana@gmail.com>