Skip to content

Commit

Permalink
(PE-39250) Remove project APIs and configuration
Browse files Browse the repository at this point in the history
Removes access to file_metadata and compile options which allowed
fetching data and compiling for bolt projects. This commit does not
remove all project based code, it is restricted to covering enough
ground to remove access to any functionality, but there may still be
some internal code left over.
  • Loading branch information
mcdonaldseanp committed Sep 25, 2024
1 parent bfd20a5 commit b29caf5
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 257 deletions.
4 changes: 2 additions & 2 deletions src/clj/puppetlabs/services/jruby/jruby_puppet_service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
(.compileCatalog jruby-instance request-options))

(compile-ast
[this jruby-instance compile-options boltlib-path]
(.compileAST jruby-instance compile-options boltlib-path))
[this jruby-instance compile-options]
(.compileAST jruby-instance compile-options))

(get-environment-module-info
[this jruby-instance env-name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
(i18n/trs "Versioned code not supported."))))
(constantly nil)
false
nil
nil
nil
(get-in config [:puppetserver :certname])))
master-route-handler (comidi/routes->handler master-routes)
master-mount (master-core/get-master-mount
Expand Down
71 changes: 15 additions & 56 deletions src/clj/puppetlabs/services/master/master_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -981,44 +981,29 @@

(schema/defn ^:always-validate compile-fn :- IFn
[jruby-service :- (schema/protocol jruby-protocol/JRubyPuppetService)
current-code-id-fn :- IFn
boltlib-path :- (schema/maybe [schema/Str])
bolt-projects-dir :- (schema/maybe schema/Str)]
current-code-id-fn :- IFn]
(fn [request]
(let [request-options (-> request
:body
slurp
(validated-body CompileRequest))
versioned-project (get request-options "versioned_project")
environment (get request-options "environment")]
;; Check to ensure environment/versioned_project are mutually exlusive and
;; at least one of them is set.
(cond
(and versioned-project environment)
{:status 400
:headers {"Content-Type" "text/plain"}
:body (i18n/tru "A compile request cannot specify both `environment` and `versioned_project` parameters.")}

(and (nil? versioned-project) (nil? environment))
;; Check to ensure environment is set.

(if (nil? environment)
{:status 400
:headers {"Content-Type" "text/plain"}
:body (i18n/tru "A compile request must include an `environment` or `versioned_project` parameter.")}

:else
(let [compile-options (if versioned-project
;; we need to parse some data from the project config for project compiles
(parse-project-compile-data request-options versioned-project bolt-projects-dir)
;; environment compiles only need to set the code ID
(assoc request-options
(let [compile-options (assoc request-options
"code_id"
(current-code-id-fn environment)))]
(current-code-id-fn environment))]
{:status 200
:headers {"Content-Type" "application/json"}
:body (json/encode
(jruby-protocol/compile-ast jruby-service
(:jruby-instance request)
compile-options
boltlib-path))})))))
compile-options))})))))

(schema/defn ^:always-validate
v4-catalog-handler :- IFn
Expand All @@ -1034,10 +1019,8 @@
compile-handler :- IFn
[jruby-service :- (schema/protocol jruby-protocol/JRubyPuppetService)
wrap-with-jruby-queue-limit :- IFn
current-code-id-fn :- IFn
boltlib-path :- (schema/maybe [schema/Str])
bolt-projects-dir :- (schema/maybe schema/Str)]
(-> (compile-fn jruby-service current-code-id-fn boltlib-path bolt-projects-dir)
current-code-id-fn :- IFn]
(-> (compile-fn jruby-service current-code-id-fn)
(jruby-request/wrap-with-jruby-instance jruby-service)
wrap-with-jruby-queue-limit
jruby-request/wrap-with-error-handling))
Expand All @@ -1061,17 +1044,14 @@
v3-ruby-routes :- bidi-schema/RoutePair
"v3 route tree for the ruby side of the master service."
[request-handler :- IFn
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
bolt-projects-dir :- (schema/maybe schema/Str)
certname :- schema/Str]
(comidi/routes
(comidi/GET ["/node/" [#".*" :rest]] request
(request-handler request))
(comidi/GET ["/file_content/" [#".*" :rest]] request
;; Not strictly ruby routes anymore because of this
(file-serving/file-content-handler bolt-builtin-content-dir bolt-projects-dir request-handler (ring/params-request request)))
(request-handler request))
(comidi/GET ["/file_metadatas/" [#".*" :rest]] request
(file-serving/file-metadatas-handler bolt-builtin-content-dir bolt-projects-dir request-handler (ring/params-request request)))
(request-handler request))
(comidi/GET ["/file_metadata/" [#".*" :rest]] request
(request-handler request))
(comidi/GET ["/file_bucket_file/" [#".*" :rest]] request
Expand Down Expand Up @@ -1100,9 +1080,7 @@
get-code-content-fn :- IFn
current-code-id-fn :- IFn
cache-enabled :- schema/Bool
wrap-with-jruby-queue-limit :- IFn
boltlib-path :- (schema/maybe [schema/Str])
bolt-projects-dir :- (schema/maybe schema/Str)]
wrap-with-jruby-queue-limit :- IFn]
(let [class-handler (create-cacheable-info-handler-with-middleware
(fn [jruby env]
(some-> jruby-service
Expand Down Expand Up @@ -1136,9 +1114,7 @@
compile-handler' (compile-handler
jruby-service
wrap-with-jruby-queue-limit
current-code-id-fn
boltlib-path
bolt-projects-dir)]
current-code-id-fn)]
(comidi/routes
(comidi/POST "/compile" request
(compile-handler' request))
Expand Down Expand Up @@ -1189,20 +1165,15 @@
current-code-id-fn :- IFn
environment-class-cache-enabled :- schema/Bool
wrap-with-jruby-queue-limit :- IFn
boltlib-path :- (schema/maybe [schema/Str])
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
bolt-projects-dir :- (schema/maybe schema/Str)
certname :- schema/Str]
(comidi/context "/v3"
(v3-ruby-routes ruby-request-handler bolt-builtin-content-dir bolt-projects-dir certname)
(v3-ruby-routes ruby-request-handler certname)
(comidi/wrap-routes
(v3-clojure-routes jruby-service
get-code-content-fn
current-code-id-fn
environment-class-cache-enabled
wrap-with-jruby-queue-limit
boltlib-path
bolt-projects-dir)
wrap-with-jruby-queue-limit)
clojure-request-wrapper)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -1304,9 +1275,6 @@
get-code-content-fn :- IFn
current-code-id-fn :- IFn
environment-class-cache-enabled :- schema/Bool
boltlib-path :- (schema/maybe [schema/Str])
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
bolt-projects-dir :- (schema/maybe schema/Str)
certname :- schema/Str]
(comidi/routes
(v3-routes ruby-request-handler
Expand All @@ -1316,9 +1284,6 @@
current-code-id-fn
environment-class-cache-enabled
wrap-with-jruby-queue-limit
boltlib-path
bolt-builtin-content-dir
bolt-projects-dir
certname)
(v4-routes clojure-request-wrapper
jruby-service
Expand Down Expand Up @@ -1380,9 +1345,6 @@
wrap-with-authorization-check :- IFn
wrap-with-jruby-queue-limit :- IFn
environment-class-cache-enabled :- schema/Bool
boltlib-path :- (schema/maybe [schema/Str])
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
bolt-projects-dir :- (schema/maybe schema/Str)
certname :- schema/Str]
(let [ruby-request-handler (wrap-middleware handle-request
wrap-with-authorization-check
Expand All @@ -1399,9 +1361,6 @@
get-code-content
current-code-id
environment-class-cache-enabled
boltlib-path
bolt-builtin-content-dir
bolt-projects-dir
certname)))

(def MasterStatusV1
Expand Down
7 changes: 0 additions & 7 deletions src/clj/puppetlabs/services/master/master_service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@
certname (get-in config [:puppetserver :certname])
localcacert (get-in config [:puppetserver :localcacert])
puppet-version (get-in config [:puppetserver :puppet-version])
bolt-builtin-content-dir (get-in config [:bolt :builtin-content-dir] [])
bolt-projects-dir (get-in config [:bolt :projects-dir])
max-queued-requests (get-in config [:jruby-puppet :max-queued-requests] 0)
max-retry-delay (get-in config [:jruby-puppet :max-retry-delay] 1800)
settings (ca/config->master-settings config)
Expand All @@ -135,8 +133,6 @@
max-queued-requests
max-retry-delay))
identity)

boltlib-path (get-in config [:jruby-puppet :boltlib-path])
ring-app (comidi/routes
(master-core/construct-root-routes puppet-version
jruby-service
Expand All @@ -146,9 +142,6 @@
(get-auth-handler)
wrap-with-jruby-queue-limit
environment-class-cache-enabled
boltlib-path
bolt-builtin-content-dir
bolt-projects-dir
certname))
routes (comidi/context path ring-app)
route-metadata (comidi/route-metadata routes)
Expand Down
2 changes: 1 addition & 1 deletion src/clj/puppetlabs/services/protocols/jruby_puppet.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"Compile the catalog for a given certname")

(compile-ast
[this jruby-instance compile-options boltlib-path]
[this jruby-instance compile-options]
"Compiles arbitrary Puppet ASTs into mini catalogs")

(get-environment-module-info
Expand Down
2 changes: 1 addition & 1 deletion src/java/com/puppetlabs/puppetserver/JRubyPuppet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface JRubyPuppet {
List getTransportInfoForEnvironment(String environment);
List getModuleInfoForEnvironment(String environment);
Map compileCatalog(Map requestBody);
Map compileAST(Map compileOptions, List boltlibPath);
Map compileAST(Map compileOptions);
Map getModuleInfoForAllEnvironments();
JRubyPuppetResponse handleRequest(Map request);
Object getSetting(String setting);
Expand Down
7 changes: 3 additions & 4 deletions src/ruby/puppetserver-lib/puppet/server/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ def compileCatalog(request_data)
end
end

def compileAST(compile_options, boltlib_path)
def compileAST(compile_options)
ruby_compile_options = convert_java_args_to_ruby(compile_options)
ruby_boltlib_path = boltlib_path.kind_of?(Java::JavaUtil::List) ? boltlib_path.to_a : nil
Puppet::Server::ASTCompiler.compile(ruby_compile_options, ruby_boltlib_path)
Puppet::Server::ASTCompiler.compile(ruby_compile_options, nil)
end

def create_recorder
Expand Down Expand Up @@ -248,7 +247,7 @@ def check_cadir_for_deprecation_warning
# Each array element is examined, if it is expected to be a map
# we call back to the convert_java_args_to_ruby method, if it
# is expected to be an array, we recurse otherwise we do not modify
# the value.
# the value.
def resolve_java_objects_from_list(list)
list.map do |value|
if value.kind_of?(Java::ClojureLang::IPersistentMap)
Expand Down
Loading

0 comments on commit b29caf5

Please sign in to comment.