github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/test/cli/test-fixtures/attestation/config/logid.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright 2021 The Sigstore Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  
    18  function get_log_id() {
    19  	curl -s --retry-connrefused --retry 10 http://trillian-log-server:8095/metrics |grep "^quota_acquired_tokens{spec=\"trees"|head -1|awk ' { print $1 } '|sed -e 's/[^0-9]*//g' > /tmp/logid
    20  }
    21  
    22  function get_ephemeral_ca() {
    23  	curl -s --retry-connrefused --retry 10 http://fulcio-server:5555/api/v1/rootCert > /etc/config/root.pem
    24  }
    25  
    26  function create_log () {
    27  	/go/bin/createtree -admin_server trillian-log-server:8096 > /tmp/logid
    28  	echo -n "Created log ID " && cat /tmp/logid
    29  }
    30  
    31  function update_config() {
    32  	cat /root/ctfe/ct_server.cfg | sed -e "s/%LOGID%/"`cat /tmp/logid`"/g" > /etc/config/ct_server.cfg
    33  	cp /root/ctfe/*.pem /etc/config/
    34  }
    35  
    36  # check to see if log id exists; if so, use that
    37  echo -n "Checking for existing configuration..."
    38  echo "Checking for preexisting logs..."
    39  get_log_id
    40  # else create one
    41  if ! [[ -s /tmp/logid ]]; then
    42  	echo "No log found; let's create one..."
    43  	create_log
    44  fi
    45  echo "Updating config with current log"
    46  update_config
    47  
    48  configid=`cat /etc/config/ct_server.cfg|grep log_id|awk ' { print $2 } '`
    49  echo "Exisiting configuration uses log ID $configid, exiting"
    50  
    51  echo "Grabing fulcio root pem file"
    52  get_ephemeral_ca
    53  
    54  echo "Finished ct_server configuration"